Dynamic block repositioning issue: Attributes stay, but Mtext moves

Dynamic block repositioning issue: Attributes stay, but Mtext moves

OrmArTHe
Enthusiast Enthusiast
2,559 Views
12 Replies
Message 1 of 13

Dynamic block repositioning issue: Attributes stay, but Mtext moves

OrmArTHe
Enthusiast
Enthusiast

Hi guys!

 

I'm trying to reposition the base point of a Dynamic block after it is added to the database.

 

The block consists of 5 Attributes and 1 Mtext.

 

The expected behaviour is that Attributes and Mtext stay at the current position, and only the base point and custom grips are repositioned.

 

What I get is: Attributes stay but Mtext moves along with the base point and custom grips.

Any ideas why this is happeneing and how to resolve it?

Screenshot 2024-12-11 125715.png

I've attached the dwg file.

0 Likes
Accepted solutions (1)
2,560 Views
12 Replies
Replies (12)
Message 2 of 13

_gile
Consultant
Consultant

Hi

You could "synchronize" the attributes, but it is simpler to use TransformBy method to displace a block reference (and its atributes will be displaced at the same time).



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 13

OrmArTHe
Enthusiast
Enthusiast

How do I "synchronize" the attributes? What came to my mind is a workaround: change that Mtext to Attribute - that should hopefully make it stay in place.

If TransformBy displaces attributes - that is not what I want. I want all the blocks' content to stay in place, and only reposition its base point (I don't care if custom grips are repositioned or not).

Edit: Forgot to attach the block. It's now attached to my first post.

0 Likes
Message 4 of 13

_gile
Consultant
Consultant

Sorry, I do not fully understand what you're trying to do when you say: "reposition its base point".
Are you talking about the block definition (BlockTableRecord) or an inserted reference (BlockReference)?



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 5 of 13

OrmArTHe
Enthusiast
Enthusiast

Sorry for not being explicit enough... I'm talking about inserted BlockReference.

0 Likes
Message 6 of 13

_gile
Consultant
Consultant

Please show the code that you have written and that "don't work" for you.

And perhaps explain how you'd "reposition its base point" without coding.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 7 of 13

OrmArTHe
Enthusiast
Enthusiast

> Please show the code that you have written and that "don't work" for you.

 

In my opinion, It is not that the code isn't working, but I just want to know why is Mtext moving and Attribute is not moving.

And perhaps explain how you'd "reposition its base point" without coding.

 

Actually, what I'm trying to do is to automate the process of manually repositioning the block reference as well as its attributes. Manual process involved repositioning the block using base point grip and a few custom grips. The manual steps were as follows:
1) Reposition the base point to location 1.

2) Reposition the attributes using custom grips to location 2.

Current automatic steps (with coding):

1) Reposition the base point to location 1 using `blkRef.Position = newPosition;`.
2) Reposition the attributes to location 2 by changing the values of dynamic block properties (e.g. `prop.Value = newValue;`).

The code works as expected albeit the Mtext is moved to location 1. This behaviour is explained by Mtext not being an attribute. So I was wandering if there is a way to keep Mtext from moving to location 1?

0 Likes
Message 8 of 13

_gile
Consultant
Consultant

@OrmArTHe  a écrit :

The code works as expected albeit the Mtext is moved to location 1. This behaviour is explained by Mtext not being an attribute. So I was wandering if there is a way to keep Mtext from moving to location 1?


No way. This is how AutoCAD blocks work. You cannot change an entity in a block reference (except attribute references), you have to change it in the block definition and doing so will affect all inserted references.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 9 of 13

OrmArTHe
Enthusiast
Enthusiast

 You cannot change an entity in a block reference (except attribute references), you have to change it in the block definition and doing so will affect all inserted references.

What changes should I make in block definition so that Mtext doesn't move  to location 1?

0 Likes
Message 10 of 13

_gile
Consultant
Consultant

@OrmArTHe  a écrit :

 You cannot change an entity in a block reference (except attribute references), you have to change it in the block definition and doing so will affect all inserted references.

What changes should I make to block definition so that Mtext doesn't move  to location 1?


Sorry if I was not clear. What you're asking is not possible, any tranformation to a block reference will affect all the displayed entities (with an exception for attributes)

.

You should learn how AutoCAD blocks work (read this topic).

A block definition (BlockTableRecord) is a collection of entities. A block reference (BlockReference) does not contains entities, it is only a reference to the block definition with linear transformations (displacement, rotation and scaling) which affect all the displayed entities.

Only the attributes work a little differently. The block definition may contain attribute definitions (AttributeDefinition) and, as shown in another of your posts, when creating a new BlockReference by code, we have to explicitly create an attribute reference in the block reference AttributeCollection for each AttributeDefinition in the block definition. This is why, unlike other entities, attribute references may be slightly different from their attribute definition (position, text string).

In your case, you should replace the MText (/) with a Constant attribute definition and add it to the selection set of the action of Position1 parameter so that it can be displaced with other attributes.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 11 of 13

OrmArTHe
Enthusiast
Enthusiast

Thank you for the detailed response.

In your case, you should replace the MText (/) with a Constant attribute definition and add it to the selection set of the action of Position1 parameter so that it can be displaced with other attributes.

I did this and still, the issue persists... Block attached.

0 Likes
Message 12 of 13

_gile
Consultant
Consultant
Accepted solution

My mistake, do not set the attribute definition Constant.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 13 of 13

OrmArTHe
Enthusiast
Enthusiast

Thanks!

0 Likes