Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies
Module BlankRouting
Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim RoutObjAttribute As String = "RoutObjVis"
Sub Main()
If IsNothing(theSession.Parts.Work) Then
'active part required
Return
End If
[highlight #8AE234] 'Is Routing Objekt Attribute set or not?
Dim RoutObjVisible As Boolean = True
Try
RoutObjVisible = workPart.GetBooleanUserAttribute(RoutObjAttribute, 0)
Catch ex As NXException
If ex.ErrorCode = 512008 Then
'attribute not found
workPart.SetBooleanUserAttribute(RoutObjAttribute, 0, False, Update.Option.Later)
Else
'unexpected error
MsgBox(ex.ErrorCode & " : " & ex.Message)
Return
End If
End Try [/highlight]
'Find Routing Objects
Const undoMarkName As String = "hide routing objects"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)
Dim routeTags As New List(Of Tag)
Dim routeObjs As New List(Of DisplayableObject)
FindObjects(routeTags, UFConstants.UF_route_control_point_type)
FindObjects(routeTags, UFConstants.UF_route_port_type)
FindObjects(routeTags, UFConstants.UF_route_part_anchor_type)
[highlight #8AE234]FindObjects(routeTags, UFConstants.UF_route_path_subtype)[/highlight]
For Each tempTag As Tag In routeTags
Dim tmpDisplay As DisplayableObject = Utilities.NXObjectManager.Get(tempTag)
routeObjs.Add(tmpDisplay)
Next
[highlight #8AE234] 'Blank or Unblank Routing Objects
If RoutObjVisible Then
HideRoutObj(routeObjs)
Else
ShowRoutObj(routeObjs)
End If[/highlight]
End Sub
Sub FindObjects(ByRef tagList As List(Of Tag), ByVal objType As Integer)
Dim tmpObj As NXOpen.Tag = NXOpen.Tag.Null
Do
theUfSession.Obj.CycleObjsInPart(theSession.Parts.Display.Tag, objType, tmpObj)
If tmpObj = NXOpen.Tag.Null Then
Continue Do
End If
If tmpObj <> NXOpen.Tag.Null Then
tagList.Add(tmpObj)
End If
Loop Until tmpObj = NXOpen.Tag.Null
End Sub
[highlight #8AE234] Sub ShowRoutObj(ByRef routeObjs As List(Of DisplayableObject))
'Show routing objects (control points, ports, and anchors)
theSession.DisplayManager.ShowObjects(routeObjs.ToArray, DisplayManager.LayerSetting.ChangeLayerToSelectable)
workPart.SetBooleanUserAttribute(RoutObjAttribute, 0, True, Update.Option.Later)
End Sub
Sub HideRoutObj(ByRef routeObjs As List(Of DisplayableObject))
'Hide routing objects (control points, ports, and anchors)
theSession.DisplayManager.BlankObjects(routeObjs.ToArray)
workPart.SetBooleanUserAttribute(RoutObjAttribute, 0, False, Update.Option.Later)
End Sub[/highlight]
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