Author Topic: Problem retrieving Attribute Tags  (Read 5391 times)

0 Members and 1 Guest are viewing this topic.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Problem retrieving Attribute Tags
« on: May 28, 2012, 03:47:54 PM »
Using ACAD2006, I have a block that I cannot retrieve the attribute tags from.
See the DWG attached and the code below.
It appears that the attrdef are after another block within the main block and that the
vlax-for stops when it encounters the sub block.
Any testers here today?

Code: [Select]
(defun c:test (/ DOC blocks x plist)
  (and
    (setq DOC (vla-get-activedocument (vlax-get-acad-object)))
    (setq blocks (vla-get-blocks DOC))  ;  <--<<
    (not (vla-getentity (vla-get-utility DOC) 'blkobj 'point "Select Block:")) ; entsel
    (equal "AcDbBlockReference" (vlax-get blkobj 'ObjectName))
    (vlax-for x (vla-item blocks (vlax-get blkobj 'Name))
      (if (equal "AcDbAttributeDefinition" (vlax-get x 'ObjectName))
        (setq plist (cons (vla-get-promptstring x) plist))
      )
    )
  )
  (reverse plist)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Problem retrieving Attribute Tags
« Reply #1 on: May 28, 2012, 04:11:49 PM »
Do not know much about LISP but looking quickly did not see any nested blocks that contained AttributeReferences.
 
Are you searching for AcDbAttributeDefinition or AcDbAttributeReferences?

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Problem retrieving Attribute Tags
« Reply #2 on: May 28, 2012, 04:27:03 PM »
Atts are in the main block & I'm looking for TAGS.
There is a block within the main block and the code stops when it gets to that sub block.
The atts are in the main block but fall after the sub block.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Problem retrieving Attribute Tags
« Reply #3 on: May 28, 2012, 04:31:46 PM »
Not sure about 2006, Alan, as I don't have that to test with any longer. But I get a list of the Promptstrings (this is what your code gets, even though you mentioned the Attribute Tag) just fine in 2012:

Command: TESt Select Block:
Command: ("Sheet Number" "Plan Date" "Sheet Title - 1st line:" "Sheet Title -
2nd line:" "Owners Name" "Address" "City-State" "Plans Status" "Revision
number:" "Revision date:" "Revision By" "Revision number:" "Revision date:"
"Revision By" "Revision number:" "Revision date:" "Revision By" "Revision
number:" "Revision date:" "Revision By" "Revision number:" "Revision date:"
"Revision By" "Revision number:" "Revision date:" "Revision By" "Draftsperson:")

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Problem retrieving Attribute Tags
« Reply #4 on: May 28, 2012, 04:47:17 PM »
It returns nil for me.
See attached text file. Note that the attrdef are after the sub block.
The routine stops when it gets to the sub block.

I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Problem retrieving Attribute Tags
« Reply #5 on: May 28, 2012, 04:52:13 PM »
This is the output from test when I add a (print (vlax-get x 'ObjectName))
Command: test
Select Block:
Command:
"AcDbLine"
"AcDbLine"
"AcDbArc"
"AcDbArc"
"AcDbLine"
"AcDbLine"
"AcDbText"
"AcDbLine"
"AcDbLine"
"AcDbLine"
"AcDbArc"
"AcDbLine"
"AcDbText"
"AcDbArc"
"AcDbArc"
"AcDbLine"
"AcDbArc"
"AcDbLine"
"AcDbLine"
"AcDbLine"
"AcDbLine"
"AcDbLine"
"AcDbLine"
"AcDbLine"
"AcDbArc"
"AcDbLine"
"AcDbArc"
"AcDbArc"
"AcDbArc"
"AcDbArc"
"AcDbLine"
"AcDbArc"
"AcDbArc"
"AcDbArc"
"AcDbLine"
"AcDbArc"
"AcDbArc"
"AcDbBlockReference" nil
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Problem retrieving Attribute Tags
« Reply #6 on: May 28, 2012, 04:56:27 PM »
This is from a similar block, but the object order is not the same as the block in question.
Looking at that block there is one "AcDbAttributeDefinition" missing and it is the last object in the
block definition.

Command: test
Select Block:
Command:
"AcDbAttributeDefinition"
"AcDbAttributeDefinition"
"AcDbAttributeDefinition"
"AcDbAttributeDefinition"
"AcDbAttributeDefinition"
"AcDbAttributeDefinition"
"AcDbAttributeDefinition"
"AcDbAttributeDefinition"
"AcDbAttributeDefinition"
"AcDbAttributeDefinition"
"AcDbAttributeDefinition"
"AcDbAttributeDefinition"
"AcDbAttributeDefinition"
"AcDbAttributeDefinition"
"AcDbAttributeDefinition"
"AcDbAttributeDefinition"
"AcDbAttributeDefinition"
"AcDbAttributeDefinition"
"AcDbAttributeDefinition"
"AcDbAttributeDefinition"
"AcDbAttributeDefinition"
"AcDbAttributeDefinition"
"AcDbAttributeDefinition"
"AcDbAttributeDefinition"
"AcDbAttributeDefinition"
"AcDbAttributeDefinition"
"AcDbAttributeDefinition"
"AcDbAttributeDefinition"
"AcDbLine"
"AcDbLine"
"AcDbLine"
"AcDbArc"
"AcDbArc"
"AcDbLine"
"AcDbLine"
"AcDbLine" ("Owners Name" "Address" "City-State" "Plans Status" "Sheet Title -
1st line:" "Sheet Title - 2nd line:" "Draftsperson:" "Plan Date" "Model Name"
"Sheet Number" "Revision number 1:" "Revision date 1:" "Revision By 1"
"Revision number 2:" "Revision date 2:" "Revision By 2" "Revision number 3:"
"Revision date 3:" "Revision By 3" "Revision number 4:" "Revision date 4:"
"Revision By 4" "Revision number 5:" "Revision date 5:" "Revision By 5"
"Revision number 6:" "Revision date 6:" "Revision By 6")
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Problem retrieving Attribute Tags
« Reply #7 on: May 28, 2012, 04:57:39 PM »
I see an RTEXT object in the entity list. It happens to be the first object after the nested block. Older versions of Autocad choke when attempting to access the properties of RTEXT objects with ActiveX, it appears 2006 falls in the category of 'older versions'....i.o.w., I don't recall when they finally fixed this. I think you can throw in a (vl-catch-all-apply) to trap the error and continue on, but this might be one of those things that the error trap fails to catch (it's been too long since I've had to work with these I just can't recall exactly...sorry) so you would need to resort to checking the object type via the DXF & Entity Type.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Problem retrieving Attribute Tags
« Reply #8 on: May 28, 2012, 05:02:50 PM »
Oh - Thanks Jeff for the heads up.  8-)
That must be it, I'll try the catch-all and report back.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Problem retrieving Attribute Tags
« Reply #9 on: May 28, 2012, 05:08:28 PM »
No error!
I just tried this and it will return all before the Rtext.
When it hits that the loop ends without an error.
 :pissed:

Off to DXF land.....
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Problem retrieving Attribute Tags
« Reply #10 on: May 28, 2012, 05:11:39 PM »
Yeah, that's what the voice in the back of my mind was telling me you were going to find. I quit using RTEXT long ago for this very reason.

kruuger

  • Swamp Rat
  • Posts: 637
Re: Problem retrieving Attribute Tags
« Reply #11 on: May 28, 2012, 05:30:52 PM »
Code - Auto/Visual Lisp: [Select]
  1. (defun c:TEST (/ ob res)
  2.   (foreach % (cd:BLK_GetEntity "Title Block 11x17 Attributes" "ATTDEF")
  3.     (setq res (cons (vla-get-promptstring (vlax-ename->vla-object %)) res))
  4.   )
  5.   (princ (reverse res))
  6.   (princ)
  7. )
  8. ; =========================================================================================== ;
  9. ; Lista obiektow w definicji bloku / List of objects in block definition                      ;
  10. ;  Name   [STR] - nazwa bloku / block name                                                    ;
  11. ;  Entity [STR] - nazwa entycji / entity name                                                 ;
  12. ; ------------------------------------------------------------------------------------------- ;
  13. ; (cd:BLK_GetEntity "*Model_space" nil), (cd:BLK_GetEntity "NAZWA" "*LINE")                   ;
  14. ; =========================================================================================== ;
  15. (defun cd:BLK_GetEntity (Name Entity / en dt res)
  16.   (setq en (tblobjname "BLOCK" Name))
  17.   (while
  18.     (and
  19.       en
  20.       (setq en (entnext en))
  21.       (setq dt (entget en))
  22.       (/= "ENDBLK" (cdr (assoc 0 dt)))
  23.     )
  24.     (if
  25.       (if Entity
  26.         (wcmatch (cdr (assoc 0 dt)) (strcase Entity))
  27.         (cdr (assoc 0 dt))
  28.       )
  29.       (setq res
  30.         (cons
  31.           (cdr (assoc -1 dt))
  32.           res
  33.         )
  34.       )
  35.     )
  36.   )
  37.   (reverse res)
  38. )
kruuger


pBe

  • Bull Frog
  • Posts: 402
Re: Problem retrieving Attribute Tags
« Reply #12 on: May 29, 2012, 01:36:17 AM »
Command: test
Select Block:
Command:
"AcDb3dPolyline"
"AcDb3dPolyline"
"AcDb3dPolyline"
"AcDb3dPolyline"
"AcDbBlockReference" nil

BUT the "block" is XREF
« Last Edit: May 29, 2012, 01:41:30 AM by pBe »

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Problem retrieving Attribute Tags
« Reply #13 on: May 29, 2012, 02:58:42 AM »
A xref "is" a block, it's just a block with a path parameter. It "shouldn't" cause any problems.

Would have done it slightly differently, but effect is pretty much the same:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:GetBlockInternals (/ en eo blk lst)
  2.   (if (and (setq en (entsel "Select Block: "))
  3.            (setq eo (vlax-ename->vla-object (car en)))
  4.            (eq (vla-get-ObjectName eo) "AcDbBlockReference")
  5.            (setq blk (vla-Item (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object))) (vla-get-EffectiveName eo))))
  6.     (vlax-for item blk
  7.       (princ "\t")
  8.       (prin1 (vla-get-ObjectName item))
  9.       (if (eq (vla-get-ObjectName item) "AcDbAttributeDefinition")
  10.         (setq lst (cons (vla-get-PromptString item) lst)))))
  11.   (reverse lst))
And it seems to work fine in Vanilla 2012:
Quote
Command: GETBLOCKINTERNALS
Select Block:  "AcDbLine"     "AcDbLine"      "AcDbArc"       "AcDbArc" 
"AcDbLine"       "AcDbLine"   "AcDbText"  "AcDbLine"       "AcDbLine"   
"AcDbLine"  "AcDbArc"      "AcDbLine" "AcDbText"     "AcDbArc"     "AcDbArc"   
 "AcDbLine"      "AcDbArc"       "AcDbLine"   "AcDbLine"  "AcDbLine"       
"AcDbLine"   "AcDbLine"  "AcDbLine"       "AcDbLine"   "AcDbArc" "AcDbLine"     
"AcDbArc"     "AcDbArc"     "AcDbArc"     "AcDbArc"     "AcDbLine"     
"AcDbArc"       "AcDbArc"  "AcDbArc"      "AcDbLine" "AcDbArc"    "AcDbArc"   
"AcDbBlockReference"     "RText"   "AcDbMText"   "AcDbLine"  "AcDbLine"       
"AcDbLine"   "AcDbLine"  "AcDbLine"       "AcDbPolyline"       "AcDbPolyline"   
    "AcDbPolyline"       "AcDbPolyline"       "AcDbLine"   "AcDbLine" 
"AcDbText"       "AcDbText"   "AcDbLine"  "AcDbPolyline"    "AcDbPolyline"
"AcDbLine"     "AcDbLine"      "AcDbLine" "AcDbLine"     "AcDbLine"     
"AcDbAttributeDefinition"  "AcDbAttributeDefinition" "AcDbAttributeDefinition" 
    "AcDbAttributeDefinition"  "AcDbAttributeDefinition"
"AcDbAttributeDefinition"      "AcDbAttributeDefinition" 
"AcDbAttributeDefinition" "AcDbAttributeDefinition"     
"AcDbAttributeDefinition"  "AcDbAttributeDefinition" "AcDbAttributeDefinition" 
    "AcDbAttributeDefinition"  "AcDbAttributeDefinition"
"AcDbAttributeDefinition"      "AcDbAttributeDefinition" 
"AcDbAttributeDefinition" "AcDbAttributeDefinition"     
"AcDbAttributeDefinition"  "AcDbAttributeDefinition" "AcDbAttributeDefinition" 
    "AcDbAttributeDefinition"  "AcDbAttributeDefinition"
"AcDbAttributeDefinition"      "AcDbAttributeDefinition" 
"AcDbAttributeDefinition" "AcDbAttributeDefinition"("Sheet Number" "Plan Date"
"Sheet Title - 1st line:" "Sheet Title - 2nd line:" "Owners Name" "Address"
"City-State" "Plans Status" "Revision number:" "Revision date:" "Revision By"
"Revision number:" "Revision date:" "Revision By" "Revision number:" "Revision
date:" "Revision By" "Revision number:" "Revision date:" "Revision By"
"Revision number:" "Revision date:" "Revision By" "Revision number:" "Revision
date:" "Revision By" "Draftsperson:")
The nested Block Reference doesn't seem to cause any hassles here. Not even your original c:test fails:
Quote
Command: test
Select Block:
Command: ("Sheet Number" "Plan Date" "Sheet Title - 1st line:" "Sheet Title -
2nd line:" "Owners Name" "Address" "City-State" "Plans Status" "Revision
number:" "Revision date:" "Revision By" "Revision number:" "Revision date:"
"Revision By" "Revision number:" "Revision date:" "Revision By" "Revision
number:" "Revision date:" "Revision By" "Revision number:" "Revision date:"
"Revision By" "Revision number:" "Revision date:" "Revision By" "Draftsperson:")
Must be something to do with 2006.

Perhaps do this through the DXF codes as Kruuger shows. Maybe there's some sort of issue in 2006 with the vlax-for when it encounters a nested block reference.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

pBe

  • Bull Frog
  • Posts: 402
Re: Problem retrieving Attribute Tags
« Reply #14 on: May 29, 2012, 04:18:55 AM »
A xref "is" a block, it's just a block with a path parameter. It "shouldn't" cause any problems.

You maybe right Irné , But thats the only time i can duplicate the CABs result.

Maybe there's some sort of issue in 2006 with the vlax-for when it encounters a nested block reference.

I guess its a version thingy then. CAB did say there are missing items when he tried the test routine on a similar block.