Ehaviv
Computer
- Jul 2, 2003
- 1,012
Hi and thank you in advanced.
I get nullreferenceexception and I don't know what wrong ?
I get nullreferenceexception and I don't know what wrong ?
Code:
Imports System
Imports NXOpen
Imports NXOpen.UF
Module AskAllBodies
Sub Main (ByVal args() As String)
Dim s As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim theUI As UI = UI.GetUI()
Dim dp As Part = s.Parts.Display
Dim allBodies() As Body
Dim markId1 As Session.UndoMarkId
markId1 = s.SetUndoMark(Session.MarkVisibility.Visible, "AskAllBodies")
Dim theComponent As Assemblies.Component
If SelectComponent("Select a component", theComponent) = Selection.Response.Cancel Then
Exit Sub
End If
Dim a_part As Part = theComponent.Prototype
'Dim part_occur As Tag ' Input Tag of part occurrence
'Dim object_prototype As Tag ' Input Tag of object prototype
Dim a_tag As Tag ' Returns tag of object occurrence or NULL_TAG if object is not found
Dim obj_occ As Body = Nothing
allBodies = AskAllBodies(a_part)
For Each aBody As Body In allBodies
a_tag = ufs.Assem.FindOccurrence(theComponent.Tag, aBody.Tag)
obj_occ = NXOpen.Utilities.NXObjectManager.Get(a_tag)
obj_occ.Highlight
'obj_occ.Color = 5
'obj_occ.RedisplayObject()
Next
'msgbox("OK to UnHighlight")
For Each aBody As Body In allBodies
'aBody.UnHighlight
Next
End Sub
Function AskAllBodies(ByVal thePart As Part) As Body()
Dim s As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim theBodies As New System.Collections.ArrayList()
Dim aBodyTag As Tag = Tag.Null
Do
ufs.Obj.CycleObjsInPart(thePart.Tag, UFConstants.UF_solid_type, aBodyTag)
If aBodyTag = Tag.Null Then Exit Do
Dim theType As Integer, theSubtype As Integer
ufs.Obj.AskTypeAndSubtype(aBodyTag, theType, theSubtype)
If theSubtype = UFConstants.UF_solid_body_subtype Then
theBodies.Add(s.GetObjectManager.GetTaggedObject(aBodyTag))
End If
Loop While True
Return DirectCast(theBodies.ToArray(GetType(Body)), Body())
End Function
Function SelectComponent(ByVal prompt As String, ByRef myComp As Assemblies.Component) As Selection.Response
Dim selObj As TaggedObject
Dim theUI As UI = UI.GetUI
Dim title As String = "Select a component"
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim cursor As Point3d
Dim scope As Selection.SelectionScope = Selection.SelectionScope.AnyInAssembly
Dim selectionMask_array(0) As Selection.MaskTriple
With selectionMask_array(0)
.Type = UFConstants.UF_component_type
.Subtype = UFConstants.UF_all_subtype
End With
Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(prompt, _
title, scope, selAction, _
includeFeatures, keepHighlighted, selectionMask_array, _
selobj, cursor)
If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
myComp = selObj
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
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
End Function
End Module