vlax-invoke obj 'getattributes returns textstring of *TEXT

vlax-invoke obj 'getattributes returns textstring of *TEXT

DGRL
Advisor Advisor
4,329 Views
24 Replies
Message 1 of 25

vlax-invoke obj 'getattributes returns textstring of *TEXT

DGRL
Advisor
Advisor

Dear coders

 

Have some strange outcomes of my code

 

Want to get the textstring of the ATTRIB and the ATTDEF

If i run the code below i also get back the text string of *TEXT and i wonder why since i am filtering on attribute
If i compare the print out of the block reference with the print out of the attribute definition then i see in the first list also text strings of *TEXT
How do i make sure i only get the text strings of ATTRIB and ATTDEF??

 


(vlax-for blk (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)));get block collection (vlax-for obj blk (cond ( (= "AcDbBlockReference" (vla-get-objectname obj)) (if (= :vlax-true (vla-get-hasattributes obj)) (foreach att (vlax-invoke obj 'getattributes) (print (vla-get-textstring att)) ) ) ) ( (= "AcDbAttributeDefinition" (vla-get-objectname obj)) (print (vla-get-textstring obj)) ) ) ); end of vlax-for obj blk (princ) ); end of vlax-for blk

 

 

If this was of any help please kudo and/or Accept as Solution
Kind Regards
0 Likes
4,330 Views
24 Replies
Replies (24)
Message 21 of 25

DGRL
Advisor
Advisor

@ActivistInvestor

 

Just let me think of this and I will come up with a working code

I think my approach for this task is wrong and I will rethink of this

 

Since I have another job atm just give me some time

 

 

In the end I need to process dwg's which are not according company standard.

The only hard part I forgot when I took this job is the possibilities of multiple inserts

For all the attributes in the dwg that are inserted only one time I already have a working code

 

 

 

If this was of any help please kudo and/or Accept as Solution
Kind Regards
0 Likes
Message 22 of 25

_gile
Consultant
Consultant

@DGRL wrote:

This gives back the TAGG from the ATTDEF and the value from the ATTRIB



No, this returns the TAG and the value from the ATTRIB (att):

 

(cons (vla-get-tagstring att)(vla-get-textstring att))

 

Block references (INSERT) are only references of a block definition (BLOCK_RECORD).

They are graphical representation of all the entities contained in the definition with geometric transformations (position, rotation, scalings).

If the block definition is edited, all the references will reflect these changes.

 

It's slightly different with attributes.

The block definition may constain some attribute definitions (ATTDEF).

These are special entities which are not representated in block references as the other entities of the block definition (because, in this case, they could not be edited differently in different block references).

Attribute definitions are use as templates to create some other special entities: the attribute references. An attribute references is not a representation of the attribute definition, it is a separated entity associated / linked to a block reference.

They are transparently created when executing the INSERT command or the (vla-AddblockReference ... ) function, but if you (entmake ...) a block reference, you have to also explicitly (entmake ...) the attribute references using the attribute definition as template.

 

I hope I clearly explained why the 'attribute' behavior is different from the 'block' behavior.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 23 of 25

_gile
Consultant
Consultant

To process a drawing, you have to ask yourself precisely what you want to control / edit.

 

If this is related to the attribute definition (e.g., the text size, the justification, ...) you have to edit the attribute definition and synchronize the attribute references so that they are re-built using the new template (they should keep their 'values').

 

If this is related to the 'values' of the attribute references, you have to get all the references of the concerned block (with (ssget "_X" ...) or (gc:GetReferences ...) in this reply), then get the atrribute reference from the block reference attribute collection.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 24 of 25

DannyNL
Advisor
Advisor

In short, an INSERT is a reference to a BLOCK definition.

 

All lines, circles, etc. are only referenced. Change a line or circle in your definition, and all inserted blocks with the same name will show the same update.

 

But an ATTREF is a copy of an ATTDEF. This is to enable that you can enter different values for your attributes for each inserted block. Change an ATTDEF in your BLOCK definition and all inserted blocks with the same name are NOT automatically updated, since the INSERT still holds a copy of the original ATTDEF.

To push the changes in your ATTDEF's to your inserted blocks, you'll need to use ATTSYNC to update them.

Message 25 of 25

ActivistInvestor
Mentor
Mentor

I don't have to do a dump of anything.

 

There is no distinct ATTDEF for each ATTRIB within each insertion of the same block, and that's the part that you clearly misunderstand.

 


@DGRLwrote:

@ActivistInvestor

 

 

All I need is to access the  ; IAcadAttribute: AutoCAD Attribute Interface which contains the textstring I am after and I need to access the ; IAcadAttributeReference: AutoCAD Attribute Reference Interface

 

 

Do a dump of an attdef in a block and see for your self

 


 

 

0 Likes