'NXJournaling
'October 16, 2013
'
'Report ID symbols with a leader that is unassociated. Unassociated leaders are added to the
'group: "UNASSOCIATED_ID_SYMBOLS". Parts list autoballoons are not checked.
'limitation: only checks the first leader of a symbol
'refer to eng-tips thread561-352627
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.Annotations
Imports NXOpen.UF
Module Module1
Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
Sub Main()
lw.Open()
Dim unassociatedSymbolCount As Integer = 0
Dim manualIdSymbols As New List(Of IdSymbol)
CollectManualIdSymbols(manualIdSymbols)
Dim nullGroup As Group = Nothing
Dim groupBuilder1 As GroupBuilder
groupBuilder1 = workPart.CreateGatewayGroupBuilder(nullGroup)
groupBuilder1.ActivegroupOption = True
groupBuilder1.ActionType = 0
groupBuilder1.GroupDisplayProperties = False
groupBuilder1.GroupName = "UNASSOCIATED_ID_SYMBOLS"
For Each tempID As IdSymbol In manualIdSymbols
If Not IsSymbolAssociated(tempID) Then
unassociatedSymbolCount += 1
Dim added1 As Boolean
added1 = groupBuilder1.ObjectsInGroup.Add(tempID)
Dim myIdSymbolBuilder As IdSymbolBuilder = workPart.Annotations.IdSymbols.CreateIdSymbolBuilder(tempID)
'lw.WriteLine("unassociated ID symbol")
'lw.WriteLine("text: " & myIdSymbolBuilder.UpperText)
'lw.WriteLine("location: " & tempID.AnnotationOrigin.ToString)
'lw.WriteLine("")
End If
Next
If unassociatedSymbolCount > 0 Then
Dim nXObject1 As NXObject
nXObject1 = groupBuilder1.Commit()
lw.WriteLine(unassociatedSymbolCount.ToString & " unassociated symbol(s) found, check the 'UNASSOCIATED_ID_SYMBOLS' group")
Else
lw.WriteLine("no unassociated ID Symbols found")
'add code to ungroup any UNASSOCIATED_ID_SYMBOLS groups?
End If
groupBuilder1.Destroy()
lw.Close()
End Sub
Sub CollectManualIdSymbols(ByRef theList As List(Of IdSymbol))
'put all ID symbols, excluding parts list auto balloons, into a list
For Each tempID As IdSymbol In workPart.Annotations.IdSymbols.ToArray()
Dim theCallout As Tag = Nothing
theUfSession.Drf.AskCalloutOfAnnotation(tempID.Tag, theCallout)
If theCallout = Tag.Null Then
'not an autoballoon
theList.Add(tempID)
End If
Next
End Sub
Function IsSymbolAssociated(ByVal theSymbol As IdSymbol) As Boolean
Dim myIdBuilder As IdSymbolBuilder
myIdBuilder = workPart.Annotations.IdSymbols.CreateIdSymbolBuilder(theSymbol)
'lw.WriteLine("num leaders: " & myIdBuilder.Leader.Leaders.Length.ToString)
'ignore IDSymbols with no leaders
If myIdBuilder.Leader.Leaders.Length > 0 Then
Dim tagObj1 As TaggedObject
tagObj1 = myIdBuilder.Leader.Leaders.FindItem(0)
Dim leaderData1 As LeaderData = CType(tagObj1, LeaderData)
Dim theObject As DisplayableObject
Dim theView As View
Dim thePoint As Point3d
leaderData1.Leader.GetValue(theObject, theView, thePoint)
If theObject Is Nothing Then
Return False
Else
Return True
End If
Else
'ID Symbol has no leaders
'assume this is intentional
Return True
End If
End Function
Public Function GetUnloadOption(ByVal dummy As String) As Integer
'Unloads the image when the NX session terminates
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination
'----Other unload options-------
'Unloads the image immediately after execution within NX
'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
'Unloads the image explicitly, via an unload dialog
'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Explicitly
'-------------------------------
End Function
End Module