Change Multileaders Text masking on or off

Change Multileaders Text masking on or off

Anonymous
Not applicable
1,435 Views
2 Replies
Message 1 of 3

Change Multileaders Text masking on or off

Anonymous
Not applicable

I am trying to write a routine in vb.net that will find all of the Multileader objects in a drawing and then set the background mask of them to true.  The code I have so far captures all of the multileaders, but when I try to update the BackgroundFill to True, it doesn't do anything.  Here is the code I have so far:

 

<CommandMethod("SelectAllMLeaders")>
Public Sub SelectAllMLeaders()
Dim myDWG As Document = DocumentManager.MdiActiveDocument
Dim myEd As Editor = DocumentManager.MdiActiveDocument.Editor
Dim myTVs(0) As TypedValue
myTVs(0) = New TypedValue(DxfCode.Start, "MULTILEADER")
Dim myFilter As New SelectionFilter(myTVs)
Dim myPSR As PromptSelectionResult = myEd.SelectAll(myFilter)
If myPSR.Status = PromptStatus.OK Then

Using myTrans As Transaction = myDWG.TransactionManager.StartTransaction
For Each myObjectID As ObjectId In myPSR.Value.GetObjectIds
Dim myEntity As Entity = myObjectID.GetObject(OpenMode.ForWrite)

Dim myLeader As New MLeader '= myEntity
myLeader = myEntity
myLeader.MText.BackgroundFill = True

Next
myTrans.Commit()
End Using

Dim mySS As SelectionSet = myPSR.Value
MsgBox(mySS.Count)
End If

End Sub

0 Likes
Accepted solutions (1)
1,436 Views
2 Replies
Replies (2)
Message 2 of 3

norman.yuan
Mentor
Mentor
Accepted solution

Firstly, this forum is for AutoCAD VBA/COM API discussion, in spite of its name, for historical reason. Your question is about AutoCAD .NET API (regardless of you using VB.NET or C#), which should be posted in .NET forum for better chances of responding.

 

Secondly, when you post code, copied from your IED (Visual Studio, likely), use "</>" button above the text message window, so that the code format could be preserved for better readability.

 

Anyway, come to you question. Here is the code that works  (my comments in blue, new code in red):

 

          Using myTrans As Transaction = myDWG.TransactionManager.StartTransaction
                For Each myObjectID As ObjectId In myPSR.Value.GetObjectIds
                    Dim myEntity As Entity = myObjectID.GetObject(OpenMode.ForWrite)

'' I have to comment your code of this line ''Dim myLeader As New MLeader '= myEntity

'' The trick is declare a variable to hold the nested object (MText, in this case)
'' then make change to it. When all done, assign it back to the owner (MLeader)
'' It sounds a bit odd, but we have come across similar things in AutoCAD
'' programming. It is just how Autodesk wrap the underline mechanism with .NET API Dim myLeader As MLeader = myEntity Dim mt As MText = myLeader.MText mt.BackgroundFill = True myLeader.MText = mt Next myTrans.Commit() End Using

HTH

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 3

Anonymous
Not applicable
Thank you. That worked. I really appreciate it. It's good to know the background behind it as well - the fact that Autodesk does this on a regular basis.




0 Likes