Reference Leader's GeometryIntent
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am working on a script that attaches a custom sketch symbol to welding symbols that have been placed on sheets already. Turns out that to attach it confidently to the DrawingWeldingSymbol, I must reference a GeometryIntent of the object. Unfortunately, it seems as though there is no built in way to reference the DrawingWeldingSymbol's GeometryIntent, despite being able to do so manually as a user. Specifically, it would be great to be able to create/have GeometryIntent from an arbitrary node from a Leader.
For some reason I am able to get the sketch symbols to attach, though I cannot consistently recognize what is allowing this. It seems like if I have the sketch symbol placed exactly on the point of a node of a Leader, it attaches to that node in a satisfactory way. As this is inconsistent, which supposedly nothing I can do to guarantee it, I am unable to use the as a solution with my current information.
Does anyone have any idea's on how to either utilize GeomtryIntent in this situation, or have details on how to attach sketch symbols to weld symbols without this integrated feature with consistency and reliability?
Code for reference, and to help future forum travelers:
Sub Main()
If Not ActiveDocIsDwg() Then Exit Sub
If Not RefreshSymbolFromLibrary("Weld No. (WIP)") Then Exit Sub
Dim weldSymbols As ObjectCollection = FindAllWeldSymbols()
If weldSymbols Is Nothing Then Exit Sub
For Each weldSym As DrawingWeldingSymbol In weldSymbols
Logger.Trace("Processing weld symbol on sheet '" & weldSym.Parent.Name & "'.")
If Not AttachWeldNumbering(weldSym) Then
Logger.Error("Failed to attach weld numbering to weld symbol on sheet '" & weldSym.Parent.Name & "'.")
End If
Next
'TestCreateSymbol()
End Sub
Function AttachWeldNumbering(weldSym As DrawingWeldingSymbol) As Boolean
Dim leaderPoints As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
Dim weldSymLeader As Leader = weldSym.Leader
'Dim rootNode As LeaderNode = weldSymLeader.RootNode
'Dim geomIntent As GeometryIntent = rootNode.AttachedEntity()
Dim attachPoint As Point2d
'Logger.Debug("Node Count: " & weldSymLeader.AllNodes.Count)
'For Each node As LeaderNode In weldSymLeader.AllNodes
' 'Logger.Debug()
' 'Logger.Debug("Node: " & node.)
' geomIntent = node.AttachedEntity()
'Next
attachPoint = weldSymLeader.AllNodes.Item(1).Position
Dim geomIntent As GeometryIntent
'geomIntent = Sheet.CreateGeometryIntent(weldSymLeader.AllNodes.Item(1), attachPoint)
'leaderPoints.Add(ThisApplication.TransientGeometry.CreatePoint2d(10, 8))
'leaderPoints.Add(geomIntent)
'leaderPoints.Add(weldSym.Position)
leaderPoints.Add(ThisApplication.TransientGeometry.CreatePoint2d(attachPoint.x-4, attachPoint.y-2))
leaderPoints.Add(attachPoint)
Dim weldNumberSymbol As SketchedSymbol = CreateWeldNumberSymbol(leaderPoints, "A")
Logger.Trace("Attached weld number symbol to weld symbol on sheet '" & weldSym.Parent.Name & "'.")
End Function
Function FindAllWeldSymbols() As ObjectCollection
Dim foundSymbols As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
For Each sheet As Sheet In ThisApplication.ActiveDocument.Sheets
For Each weldSymbol As DrawingWeldingSymbol In sheet.WeldingSymbols
foundSymbols.Add(weldSymbol)
Logger.Trace("Found weld symbol on sheet '" & sheet.Name & "'.")
Next
Next
Return foundSymbols
End Function
Sub TestCreateSymbol()
Dim testLeaderPoints As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
testLeaderPoints.Add(ThisApplication.TransientGeometry.CreatePoint2d(5, 4))
testLeaderPoints.Add(ThisApplication.TransientGeometry.CreatePoint2d(10, 8))
CreateWeldNumberSymbol(testLeaderPoints, "A")
End Sub
Function CreateWeldNumberSymbol(leaderPoints As ObjectCollection, prompt As String) As SketchedSymbol
Dim sheet As Sheet = ThisApplication.ActiveDocument.ActiveSheet
Dim insertPoint As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(5, 4)
weldNumberSymbol = ThisApplication.ActiveDocument.SketchedSymbolDefinitions.Item("Weld No. (WIP)")
Dim newWeldSym As SketchedSymbol
newWeldSym = sheet.SketchedSymbols.AddWithLeader(weldNumberSymbol, leaderPoints, 0, 1, {prompt})
newWeldSym.LeaderVisible = True
Return newWeldSym
End Function
Function RefreshSymbolFromLibrary(symbolName As String) As Boolean
Dim allSketchDefs As SketchedSymbolDefinitions = ThisApplication.ActiveDocument _
.SketchedSymbolDefinitions
Dim allSketchLibraries As SketchedSymbolDefinitionLibraries = allSketchDefs.SketchedSymbolDefinitionLibraries
Dim foundSymDefLib As SketchedSymbolDefinitionLibrary = Nothing
For Each sketchLib As SketchedSymbolDefinitionLibrary In allSketchLibraries
If sketchLib.Name <> "Sketch Symbols.idw" Then
'Logger.Trace("Skipping library: " & sketchLib.Name)
Continue For
End If
Logger.Trace("Checking library: " & sketchLib.Name)
Dim libSketchDefs As LibrarySketchedSymbolDefinitions = sketchLib.SketchedSymbolDefinitions
For Each libDef As LibrarySketchedSymbolDefinition In libSketchDefs
'Logger.Trace(" - Found symbol: " & libDef.Name)
If libDef.Name = symbolName Then
Logger.Trace("Found symbol: " & symbolName)
foundSymDefLib = sketchLib
Exit For
End If
Next
Next
Dim resultingSymDef As SketchedSymbolDefinition = allSketchDefs.AddFromLibrary(foundSymDefLib, symbolName, True)'True: replace Existing
If foundSymDefLib IsNot Nothing Then Return True
MsgBox("Symbol '" & symbolName & "' not found in library.", vbExclamation, "Symbol Not Found")
Logger.Trace("Symbol '" & symbolName & "' not found in library.")
Return False
End Function
Function ActiveDocIsDwg() As Boolean
If ThisApplication.ActiveDocumentType = kDrawingDocumentObject Then
activeDocIsDwg = True
Logger.Trace("Active document is a drawing.")
Else
MsgBox("This rule only works with drawing documents.", vbExclamation, "Wrong Document Type")
activeDocIsDwg = False
Logger.Trace("Active document is not a drawing.")
End If
End Function