Mtext Attribute Location / Alignmentpoint / Position

Mtext Attribute Location / Alignmentpoint / Position

js75CAD
Enthusiast Enthusiast
1,709 Views
4 Replies
Message 1 of 5

Mtext Attribute Location / Alignmentpoint / Position

js75CAD
Enthusiast
Enthusiast

Hi All,

 

I am trying to swap one block for another and I have a multiline attribute, so I am trying to mimic the justification and alignment to be as per the original. I know that as a single line attribute, if the justification is Bottom left, I use position and if otherwise I use the alignment point. This works perfect!

 

Why does this not work with the Multiline Attribute but only when the justification is Left?

The IsMTextAttribute object gives me a new position that is Location, but this doesn't work either. I have tried the alignment point, the position even the attachment point, but for the life of me I cannot get the Right justified MtextAttributes to match that of the original block.

 

There is no subject matter on this that I can find anywhere. Does anyone have a hint that might get me where I need to be to move this attribute?

 

 

 

Accepted solutions (1)
1,710 Views
4 Replies
Replies (4)
Message 2 of 5

_gile
Consultant
Consultant

Hi,

Have a look at MText properties in the documentation specifically Location and Attachment.

After having edited the MText, to update the attribute, you have to reset the modified MText as MTextAttribute:

attributeReference.MtextAttribute = mtext;


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 5

js75CAD
Enthusiast
Enthusiast

_gile,

 

Thanks, but this doesn't work either. I am not sure why Autodesk go out of their way to make things so bloody difficult! How many points do you need? Location, attachmentpoint, alignmentPoint, Position... come on!

 

attNew.TextString = att.MTextAttribute.Contents

Select Case att.Justify.ToString
Case "MiddleRight"
attNew.MTextAttribute.Attachment = att.MTextAttribute.Attachment
attNew.AlignmentPoint = att.AlignmentPoint

Case Else
attNew.Justify = att.Justify
attNew.AlignmentPoint = att.AlignmentPoint
End Select

attNew.UpdateMTextAttribute()

 

 

This is what I have so far. If the MTextAttribute is Left justified, no problem. But the minute it becomes right justified, it keeps throwing the text. Now I have managed to make it just move slightly, but the grip point is moving and I am not sure what that point is? Below you can see what I am trying to achieve.

js75CAD_0-1633127735380.png

 

0 Likes
Message 4 of 5

_gile
Consultant
Consultant
Accepted solution

You have to first check if the attribute reference is a MTextAttribute and make things differently if it is or if it is not.

Something like this:

 

if(att.IsMTextAttribute)
{
    attNew.IsMTextAttribute = true;
    MText mtext = att.MTextAttribute;
    MText mtextNew = attNew.MTextAttribute;
    mtextNew.Location = mtext.Location;
    mtextNew.Attachment = mtext.Attachment;
    mtextNew.Contents = mtext.Contents;
    attNew.MTextAttribute = mtextNew;
}
else
{
    attNew.Position = att.Position;
    attNew.TextString = att.TextString;
    if (att.Justify == AttachmentPoint.BaseLeft)
    {
        attNew.Justify = AttachmentPoint.BaseLeft;
    }
    else
    {
        attNew.Justify = att.Justify;
        attNew.AlignmentPoint = att.AlignmentPoint;
    }
}

 

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 5 of 5

js75CAD
Enthusiast
Enthusiast
Thank you _gile!

I had already checked if it was (sorry i should have included that part of the code), but I misunderstood what you meant by the Mtext. I now know what I did wrong.

Admittedly, I still am struggling to understand the difference between all the points, but now I have this, I will start testing different scenarios to see how they change. I just wish they has some documentation on this.

Much appreciated and whereever you are in the world, have an awesome weekend!
0 Likes