.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

moving Z coordinate on MLeader objects

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
coralie.jacobi
1131 Views, 2 Replies

moving Z coordinate on MLeader objects

Hi, I'm hoping somebody can help me out here. I have some multileader objects that have a Z-coordinate that I need to put to 0. I have been successfull with Mtext and Dtext, but i'm struggling with the multileader. This is what I have so far. Don't get any errors, but it does not move to a Z value of 0.

 

If myPSR1.Status = PromptStatus.OK Then
                    acSSet = myPSR1.Value
                    Dim trans1 As Transaction = myDocument.TransactionManager.StartTransaction
                    Try
                        For Each selObj In acSSet
                            Select Case selObj.ObjectId.ObjectClass.Name
                                Case "AcDbText"
                                    Dim textObj As DBText = trans1.GetObject(selObj.ObjectId, OpenMode.ForWrite, False, True)
                                    OrigX = textObj.Position.X
                                    OrigY = textObj.Position.Y

                                    Newpt = New Point3d(OrigX, OrigY, 0)
                                    textObj.Position = Newpt

                                Case "AcDbMText"
                                    Dim mtextObj As MText = trans1.GetObject(selObj.ObjectId, OpenMode.ForWrite, False, True)
                                    OrigX = mtextObj.Location.X
                                    OrigY = mtextObj.Location.Y

                                    Newpt = New Point3d(OrigX, OrigY, 0)
                                    mtextObj.Location = Newpt

                                Case "AcDbMLeader"
                                    Dim mtextObj As MLeader = trans1.GetObject(selObj.ObjectId, OpenMode.ForWrite, False, True)
                                    Dim basePoint As Point3d
                                    Select Case mtextObj.ContentType
                                        Case ContentType.BlockContent
                                            basePoint = mtextObj.BlockPosition
                                            OrigX = mtextObj.BlockPosition.X
                                            OrigY = mtextObj.BlockPosition.Y
                                            Newpt = New Point3d(OrigX, OrigY, 0)
                                            mtextObj.BlockPosition = Newpt

                                        Case ContentType.MTextContent
                                            basePoint = mtextObj.TextLocation
                                            OrigX = mtextObj.TextLocation.X
                                            OrigY = mtextObj.TextLocation.Y
                                            Newpt = New Point3d(OrigX, OrigY, 0)
                                            mtextObj.TextLocation = Newpt
                                    End Select

                            End Select
                        Next selObj
                        ' all ok, commit it
                        trans1.Commit()
                    Catch ex As Autodesk.AutoCAD.Runtime.Exception
                        MsgBox("A problem occured because " + ex.Message)
                    Finally
                        ' whatever happens we must dispose the transaction
                        trans1.Dispose()
                    End Try
                End If

 Any help or guidance would be greatly appreciated.

 

thanks

 

cj

 

2 REPLIES 2
Message 2 of 3
_gile
in reply to: coralie.jacobi

Hi,

 

You can try this way:

 

        [CommandMethod("Test", CommandFlags.Modal)]
        public void Test()
        {
            Document doc = AcAp.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;

            TypedValue[] values = { new TypedValue(0, "TEXT,MTEXT,MULTILEADER") };
            PromptSelectionResult psr = ed.GetSelection(new SelectionFilter(values));
            if (psr.Status != PromptStatus.OK) return;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                foreach (ObjectId id  in psr.Value.GetObjectIds())
                {
                    switch (id.ObjectClass.Name)
                    {
                        case "AcDbText":
                            DBText text = (DBText)tr.GetObject(id, OpenMode.ForWrite);
                            Flatten(text, text.Position);
                            break;
                        case "AcDbMText":
                            MText mtext = (MText)tr.GetObject(id, OpenMode.ForWrite);
                            Flatten(mtext, mtext.Location);
                            break;
                        default: // MLeader
                            MLeader mleader = (MLeader)tr.GetObject(id, OpenMode.ForWrite);
                            Flatten(mleader, mleader.GetVertex(0, 0));
                            break;
                    }
                }
                tr.Commit();
            }
        }

        private void Flatten(Entity ent, Point3d basePt)
        {
            if (basePt.Z != 0.0)
                ent.TransformBy(Matrix3d.Displacement(new Vector3d(0.0, 0.0, -basePt.Z)));
        }

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 3
coralie.jacobi
in reply to: _gile

THANKS Gilles!!

 

I learned a ton from your quick response and got my code working the way I want it to.

 

cheers

 

cj

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost