Create a annotative mleader in vb.net

Create a annotative mleader in vb.net

gosbee30
Contributor Contributor
572 Views
1 Reply
Message 1 of 2

Create a annotative mleader in vb.net

gosbee30
Contributor
Contributor

I am trying to create a multileader vb.net. I am mostly successful except for two issues.

One, the text for the multileader is white instead of by layer. the color does change if I double click on the mtext to edit it.

Two the text does not add annotation scales. The arrow itself scales but not the text.

 

This is the code I am using:

 

Public Sub DrawLeader(ldrText As String, ldrRoatateRaw As Double, invLayer As String)
        Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
        Dim db As Database = doc.Database
        Dim edt As Editor = doc.Editor
 
        Dim mlIns As Point3d = edt.GetPoint(vbCrLf + "Select the Mleader insertion point: ").Value
        Dim mlTIns As Point3d = edt.GetPoint(vbCrLf + "Select text insertion location: ").Value
 
        Using trans As Transaction = db.TransactionManager.StartTransaction()
            doc.LockDocument()
            Try
                Dim bt As BlockTable = trans.GetObject(db.BlockTableId, OpenMode.ForRead)
                Dim btr As BlockTableRecord = trans.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
                Dim dict As DBDictionary = db.MLeaderStyleDictionaryId.GetObject(OpenMode.ForRead)
                Dim mlstyle As ObjectId = dict.GetAt("BA_EX_L90_Arrow")
                Application.SetSystemVariable("TEXTSTYLE", "BA_EX_L90")
                Dim mlText As New MText With
                    {.Contents = ldrText,
                    .Rotation = ldrRoatateRaw,
                    .TextStyleId = db.Textstyle
                    }
                Using mldr As New MLeader
                    mldr.MLeaderStyle = mlstyle
                    Dim index As Integer = mldr.AddLeaderLine(New Point3d(0, 0, 0))
                    mldr.AddFirstVertex(index, mlIns)
                    mldr.Layer = invLayer
                    mldr.ContentType = ContentType.MTextContent
                    mldr.MText = mlText
                    mldr.TextLocation = mlTIns
                    mldr.Annotative = AnnotativeStates.True
                    btr.AppendEntity(mldr)
                    trans.AddNewlyCreatedDBObject(mldr, True)
                End Using
                trans.Commit()
                doc.SendStringToExecute("regen", True, False, False)
            Catch ex As Exception
                edt.WriteMessage(vbCrLf + "Error encountered: " + ex.Message)
                trans.Abort()
            End Try
        End Using
    End Sub

 

 

The leader style is

gosbee30_0-1626311316212.png

 

gosbee30_1-1626311316175.png

 

gosbee30_2-1626311316253.png

 

And my Text Style is:

gosbee30_3-1626311316220.png

 

0 Likes
573 Views
1 Reply
Reply (1)
Message 2 of 2

Jeff_M
Consultant
Consultant

See THIS response to a similar question.

Jeff_M, also a frequent Swamper
EESignature
0 Likes