- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello everyone
So I wrote some code to insert a TAG into a drawing for each MEP Wire that is found in model space. The code works fine except for one problem: The tag is inserted as a Multi View Block Reference instead of a Tag. Tags are created from multi-view block definitions but I can't seem to figure out where I'm going wrong.
I've provided pictures of the native Tag (Created using the native AutoCAD Tag creation tool) and my custom tag created from the vb.net code.
Both have the same information in the properties palette, but AutoCAD reads my custom tag as a "multi view block" rather than as a tag like the native tag. You can see this in the top of the ribbon with the additional options available for a native Tag. Additionally, my custom tag has no grips nor the option to edit the attributes.
My code uses the native tag's definition to create a new multiview block reference which attaches to all the Wires in blue. I'll include my code below. Thanks for anyone that can help.
[
Dim doc As Document = application.DocumentManager.MdiActiveDocument
Dim docdb As Database = doc.Database
Dim ED As Editor = doc.Editor
<CommandMethod("AddTag2Wire")>
Public Sub AddTag2Wire()
Dim PEO As New PromptEntityOptions(vbNewLine + "Select The Tag To Replicate")
Dim Prompt = ED.GetEntity(PEO)
Dim TagObjectId = Prompt.ObjectId
If Prompt.Status = PromptStatus.Cancel Then
Return
End If
Dim PEO2 As New PromptIntegerOptions(vbNewLine + "Input Text Height (4, 6 or 8)")
Dim PromptintegerResult = ED.GetInteger(PEO2)
If PromptIntegerResult.Status = PromptStatus.Cancel Then
Return
End If
Dim PIR = PromptintegerResult.Value
Using trans As Transaction = docdb.TransactionManager.StartTransaction
Dim BLOCKTABLE As BlockTable = trans.GetObject(docdb.BlockTableId, OpenMode.ForRead)
Dim MODELSPACE As BlockTableRecord = trans.GetObject(BLOCKTABLE(BlockTableRecord.ModelSpace), OpenMode.ForWrite) 'OPENS MODEL SPACE
Dim OpenTag As MultiViewBlockReference = trans.GetObject(TagObjectId, OpenMode.ForRead)
Dim OpenTagDefinitionId = OpenTag.BlockDefId
For Each ObjectId As objectid In MODELSPACE
If ObjectId.ObjectClass.Name = "AecbDbWire" Then
Dim OpenWire As Wire = trans.GetObject(ObjectId, OpenMode.ForRead)
Dim Location = OpenWire.Location
Dim InsertLocation As New Point3d(Location.X, Location.Y, 0)
Dim NewTag As New MultiViewBlockReference
NewTag.BlockDefId = OpenTagDefinitionId
If PIR = 4 Then
Dim TagScale As New Scale3d(4, 4, 1)
NewTag.Scale = TagScale
ElseIf PIR = 6 Then
Dim TagScale As New Scale3d(6, 6, 1)
NewTag.Scale = TagScale
ElseIf PIR = 8 Then
Dim TagScale As New Scale3d(8, 8, 1)
NewTag.Scale = TagScale
Else
ED.WriteMessage(vbNewLine + "Only 4, 6 or 8 Are Acceptable Arguments")
Return
End If
MODELSPACE.AppendEntity(NewTag)
trans.AddNewlyCreatedDBObject(NewTag, True)
Dim TagAnchor As New AnchorExtendedTagToEntity
TagAnchor.SubSetDatabaseDefaults(docdb)
TagAnchor.SetToStandard(docdb)
TagAnchor.ForceHorizontal = True
TagAnchor.ReferencedEntityId = ObjectId
NewTag.SetAnchor(TagAnchor)
NewTag.Location = New Point3d(0, 0, 0)
Else Continue For
End If
Next
trans.Commit()
End Using
]
Solved! Go to Solution.