Author Topic: How to find the AttributeDefinition corresponding to an Attribute?  (Read 2357 times)

0 Members and 1 Guest are viewing this topic.

FengK

  • Guest
Hello,

The reason I'm asking this is I want to write my own attsync function since it is so slow in some cases. Maybe the attsync command is doing much more than what I need: moving the attributes to the right spots. The attributes are all over the places sometimes after running some commands, especially for dynamic blocks.

This is how I plan to approach the problem: for each Attribute in a block, find the corresponding AttributeDefinition in the block definition, get the coordinate of the AttributeDefinition insertionpoint, do a coordinate translation to get the correct insertionpoint of the Attribute, then move the Attribute. But I haven't found a way to find the AttributeDefinition corresponding to an Attribute. Any hint? Or is there any other way?

Thank you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: How to find the AttributeDefinition corresponding to an Attribute?
« Reply #1 on: May 07, 2008, 05:14:11 PM »
The best way, I can think of, is by the Tag value, but even that isn't a good way, so I guess there is no good way that I see.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

FengK

  • Guest
Re: How to find the AttributeDefinition corresponding to an Attribute?
« Reply #2 on: May 07, 2008, 05:20:53 PM »
Thanks for the reply Tim. I thought about that, but it is not solid because you can have multiple attributes with the same TagString in one block. I don't think we have any blocks like that, I'm just looking for a more bullet proof method.

VovKa

  • Water Moccasin
  • Posts: 1631
  • Ukraine
Re: How to find the AttributeDefinition corresponding to an Attribute?
« Reply #3 on: May 07, 2008, 05:25:24 PM »
Code: [Select]
(defun test (BlockName / EntName OutList)
  (setq EntName (tblobjname "BLOCK" BlockName))
  (while (setq EntName (entnext EntName))
    (if (= (cdr (assoc 0 (entget EntName))) "ATTDEF")
      (setq OutList (cons EntName OutList))
    )
  )
  (reverse OutList)
)
;(mapcar 'entget (test "SomeBlockName"))
as for 'multiple attributes with the same TagString in one block' - i suspect that attributes are created in the same order as attribute definitions are stored in block definition.
« Last Edit: May 07, 2008, 06:07:29 PM by VovKa »

FengK

  • Guest
Re: How to find the AttributeDefinition corresponding to an Attribute?
« Reply #4 on: May 07, 2008, 06:00:42 PM »
Thanks for your reply Vovka. But I don't think your code does what I was after. Maybe I didn't explain my question well. Say you have a block with multiple attributes (and the block definition would have multiple AttributeDefinitions), and you use (nentsel) to pick one of them, would you be able to know which AttributeDefinition is for the attribute you picked?


gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: How to find the AttributeDefinition corresponding to an Attribute?
« Reply #5 on: May 07, 2008, 06:05:00 PM »
Hi,

I can't be 100% sure, but according to the tests I did, the list returned by:
 (vlax-invoke reference 'getAttributes)
and the one returned by:
(reverse
  (vlax-for o def
    (if   (= (vla-get-objectname o) "AcDbAttributeDefinition")
      (setq lst (cons o lst))
    )
  )
)
are sorted the same way, and change the same way after using battman
Speaking English as a French Frog

VovKa

  • Water Moccasin
  • Posts: 1631
  • Ukraine
Re: How to find the AttributeDefinition corresponding to an Attribute?
« Reply #6 on: May 07, 2008, 06:10:54 PM »
+1 gile
i'was 2 minutes late to edit my post :)

FengK

  • Guest
Re: How to find the AttributeDefinition corresponding to an Attribute?
« Reply #7 on: May 07, 2008, 06:20:36 PM »
gile, thanks for your suggestion. I'd also like to assume the getAttributes method on a block reference and gathering AttributeDefinition from a block definition would return attributes in the same order, probably is by the order that they were added into the block definition? I'll do some testing.