Issue with attributs after inserting blocks

Issue with attributs after inserting blocks

KZambaux
Enthusiast Enthusiast
649 Views
5 Replies
Message 1 of 6

Issue with attributs after inserting blocks

KZambaux
Enthusiast
Enthusiast

Hi,

I am able to add blocks from files (see post https://forums.autodesk.com/t5/net/insert-dynamics-block-with-parameters-and-attributs/td-p/8571442).

However, when I move the block, attributs are not updated.

I change the "Position" property of the BlockReference.

Same issue occurs if I move the block from Autocad itself. I run Regen command, but nothing happen.

The block I am using is in the linked post as the code (see above).


I try to import the block via the insert command, attributs are showing up

Then when I move the block, I need to perform Regen command. Attributs are updated.


So, is there something to perform by code to have the same feature ?


Thanks for your help

Ahmed

0 Likes
Accepted solutions (1)
650 Views
5 Replies
Replies (5)
Message 2 of 6

norman.yuan
Mentor
Mentor

Your question, or your description of the issue is not very clear:

 

When you say "attribute is not updated", what exactly "updated" mean? In your referred previous post, you said "attribute values are not updated". 

 

So, when MOVE the block reference, do the attributes also move with the block reference or not? If yes, that is what one should expect. If not, something seriously wrong (unless the block reference is moved by your code in a strange/specific way).

 

Or, you mean the attribute value should be changed when block reference is moved? This is not how regular attribute should behave. It could only happen if the attribute is a Field, which tied to data related to geometric position of linked entity, or if you have code runs automatically whenever a block reference is moved.

 

Please explain what kind of attribute your code adds to the block reference, what kind of update you are expecting when block reference is moved (attribute also being moved, or attribute's value being somehow updated).

 

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 6

norman.yuan
Mentor
Mentor

OK, upon opening/reviewing the drawing file (block file) you attached in previous post, I think you r block reference inserting code needs to be modified for the order of doing thing.

 

I am not sure whether the dynamic property of the block actually controls attributes in the block or not. In your block reference inserting code, you need add attribute reference to the block reference first (before setting the block reference's dynamic property). Because setting dynamic property may trigger AutoCAD to generate a new anonymous block definition for the block reference, which has not had its attribute references added.

 

So, do it in these orders:

 

1. Create new BlockReference instance, and add to model/paperspace and transaction;

2. Add AttributeReference, according to block definition, to the block reference and transaction;

3. Commit the transaction

4. Open the block reference in a new transaction and set its dynamic property/properties.

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 4 of 6

KZambaux
Enthusiast
Enthusiast

Hi,

Sorry, I will try to be more clear.

 

In my dynamic block, I have several attributs for which values are coordinates of point. In fact, my goal is to get coordinates of particulars points of my block. So, I use attributs.
Attributs are created by selecting Object in Field Name. Then I select my Object type (circle of example). And I choose Center as property.

 

Within Autocad itself, I can insert the block (Insert command). Then I can move it (changing X/Y position in the graphical block property). I can also modify the dynamic parameter (changing value in graphical block property). Here there is a rotation parameter.
With the Regen command, I can see that attributs values are updated with new coordinates. So, I will be able to get those coordinates and perform some maths work with them afterwards.
Attributs are also moving along the block.

 

What I am trying to do is to perform this "graphical" behaviour by code.

 

In my previous post (see first message of this post), I was able to insert block with parameters and attributs. Thanks for your help on this matter.
I have to say that when I insert the block with the posted code, coordinates values (for my attributs) are the default values (values seen in the block editor).
My code doesn't add attributs. It just uses the existing ones. That is why I am confuse. What I want to perform works perfectly in graphical mode. But I need this to work by code.

 

Once the block is inserted by code, I can change X or Y position in the graphical block property.
The block moves (attributs coming along) but attributs value are not updated. Coordinates are still the same value (default values). Even with the Regen command.

 

When I change the X or Y position by code (here I used the BlockReference), block moves as well, but this time, attributs are not coming along. They stay where there are when I insert the block the first time.

 

I hope it is mode clear.

 

In the code I am using to insert Block, I do not use dynamic properties yet. For the moment, I only insert it, then try to move it in a graphical way. But inserted block by code doesn't behave like inserted block via Insert code.

 

Thanks for you help.

Ahmed

0 Likes
Message 5 of 6

KZambaux
Enthusiast
Enthusiast

Hi

 

I try to use Field with the following code:

Field field = (Field)tr.GetObject(acAtt.GetField(), OpenMode.ForWrite);
field.Evaluate();
acAttRef.SetField(field);

 With it, attribut values are updated as I want.

However, when I save the drawing in a file, it says "Object in multiple property".

 

So I guess, this code corrupts my drawing.

0 Likes
Message 6 of 6

KZambaux
Enthusiast
Enthusiast
Accepted solution

Hi,

 

I did found my problem !!!

When creating AttributeReference, I don't have to write TextString property.

In my code, I had

acAttRef.TextString = acAtt.TextString;

Without it, my attributs value are updated as I want!

 

Thanks for your help

Ahmed

0 Likes