Set MText Attachment Point

For @dsotelo

Continuing the discussion from 3 MText to 1 MText:

import clr

clr.AddReference('AcCoreMgd')
clr.AddReference('AcDbMgd')
clr.AddReference('AeccDbMgd')

from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.DatabaseServices import *

OUT = eval('AttachmentPoint.' + IN[0])

4 Likes

Thanks that worked

The AttachmentPoint enumeration members are here:

https://help.autodesk.com/view/OARX/2020/ENU/?guid=OARX-ManagedRefGuide-Autodesk_AutoCAD_DatabaseServices_AttachmentPoint

Do you know how to make a new line in the mtext using the API? Similar to typing text and hitting enter for a new line of text.

Thank you for your help

You can use the \n escape character.

I tried that and i didnt work.

It’s not clear what isn’t working in the screenshot.

Hello @mzjensen,

Thanks for this code. However, it appears in Python3 this only returns the enum numerical value and not the AttachmentPoint object. I would prefer to update the code for Python3. Do you have any thoughts or knowledge of this? I tried using the migration feature but it says there is an error for “eval(‘AttachmentPoint.’ + IN[0])”.

Python.NET is funky when handling enums, so that code posted earlier probably won’t work. You’ll have to just do all the work within the Python node itself instead of outputting the enum and then using the ObjectExtensions.SetParameterValueByName node. Start a transaction, open the MText object for write, set the attachment point property, commit the transaction, etc.