NX二次开发源码分享: 加载所有的装配组件----全部加载
Imports SystemImports NXOpen
Imports NXOpen.UF
Imports NXOpen.Utilities
'
' The OpenComponents() parameter
' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly
' only opens unloaded components fully (see also PR-8406345)
' Workaround: collect and open all components individually
'
Module NXJournal
Dim theSession As Session = Session.GetSession()
Dim theUFSession As UFSession = UFSession.GetUFSession()
Dim dispPart As Part = theSession.Parts.Display
Sub DoIt()
Dim allComps() As Assemblies.Component = getAllChildren(dispPart)
Echo("Number of Components: " & allComps.Length.ToString)
For ii As Integer = 0 To allComps.Length - 1
Echo(allComps(ii).DisplayName)
Next
Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading
theSession.Parts.LoadOptions.UsePartialLoading = False
Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus
Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing
partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(
NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)
reportPartLoadStatus(partLoadStatus1)
partLoadStatus1.Dispose()
theSession.Parts.LoadOptions.UsePartialLoading = option1
End Sub
Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()
Dim theChildren As Collections.ArrayList = New Collections.ArrayList
Dim aChildTag As Tag = Tag.Null
Do
theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)
If (aChildTag = Tag.Null) Then Exit Do
Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)
theChildren.Add(aChild)
Loop
Return theChildren.ToArray(GetType(Assemblies.Component))
End Function
Public Sub Main(ByVal args As String())
If dispPart IsNot Nothing Then
DoIt()
Return
End If
End Sub
Sub Echo(ByVal output As String)
theSession.ListingWindow.Open()
theSession.ListingWindow.WriteLine(output)
theSession.LogFile.WriteLine(output)
End Sub
Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)
If load_status.NumberUnloadedParts = 0 Then
Return
End If
Echo("Load notes:")
For ii As Integer = 0 To load_status.NumberUnloadedParts - 1
Echo("" & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))
Next
End Sub
Public Function GetUnloadOption(ByVal arg As String) As Integer
Return Session.LibraryUnloadOption.Immediately
End Function
End Module
页:
[1]