eInvalidInput While Setting Attachment of MText

eInvalidInput While Setting Attachment of MText

Abby_Baratta
Enthusiast Enthusiast
411 Views
3 Replies
Message 1 of 4

eInvalidInput While Setting Attachment of MText

Abby_Baratta
Enthusiast
Enthusiast

Hi!

 

I've been working on a function that will insert text into the active document and I wanted to edit the attachment point. I've tried it two different ways, but I am still seeing the eInvalidInput error. The function that I have written is as follows:

        internal static void AddSomeText(string txt, double txtHeight ,Point3d txtLoc, string layerName)
        {
            //call func to create layer name, in case it's not in there yet
            AssignLayer(layerName);

            //document and database
            acAppServ.Document acDoc = acAppServ.Application.DocumentManager.MdiActiveDocument;
            Database acCurDB = acDoc.Database;

            //transaction
            using (Transaction acTr = acCurDB.TransactionManager.StartTransaction())
            {
                using (DocumentLock docLock = acDoc.LockDocument())
                {
                    //block table and block table record
                    BlockTable acBlkTbl = acTr.GetObject(acCurDB.BlockTableId, OpenMode.ForRead) as BlockTable;
                    BlockTableRecord acBlkTblRec = acTr.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                    //create multiline text object
                    using (MText acMText = new MText())
                    {
                        acMText.Location = txtLoc;
                        acMText.TextHeight = txtHeight;
                        acMText.Layer = layerName;
                        //acMText.Attachment = AttachmentPoint.MiddleAlign;
                        acMText.SetAttachmentMovingLocation(AttachmentPoint.MiddleAlign);
                        acMText.Contents = txt;

                        acBlkTblRec.AppendEntity(acMText);
                        acTr.AddNewlyCreatedDBObject(acMText, true);
                    }
                }
                acTr.Commit();
            }

            acAppServ.Application.DocumentManager.MdiActiveDocument.Editor.Regen();
        }

Where acAppServ is Autodesk.AutoCAD.ApplicationServices

 

I would really appreciate any help on how to properly set this this property!

0 Likes
Accepted solutions (1)
412 Views
3 Replies
Replies (3)
Message 2 of 4

daniel_cadext
Advisor
Advisor
Accepted solution

 

MiddleAlign is not one of the allowed options

 

https://forums.autodesk.com/t5/net-forum/einvalidinput-while-setting-attachment-of-mtext/td-p/136561...

Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx
0 Likes
Message 3 of 4

_gile
Consultant
Consultant

@daniel_cadext Isn't that the link you wanted to give?

https://help.autodesk.com/view/OARX/2025/ENU/?guid=OARX-ManagedRefGuide-Autodesk_AutoCAD_DatabaseSer...



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 4 of 4

Abby_Baratta
Enthusiast
Enthusiast

Ah, yeah changing it to one of those in that list worked. Thanks!