javaxp
Automotive
- Jul 14, 2014
- 43
Hi,
I intend to make a journal that makes a new component containing all the bodies in Layer 1 from all components. (This is a simple aproximation of real thing)
Firstly I cycle all components in assembly, collecting for each component the bodies in layer 1 and creating a List (Of Body) with these objects (waveList).
Then I create a new component and set it as workPart.(test.prt)
Finally, I try to make the wave links with waveLinkBuilder using the list of bodies but this gives me an error: "Can't create the wavelink feature because the object selected is into the workPart"
The code:
Any hint to solve the situation?
Regards,
Javi
NX 12.0.2.9 MP14
I intend to make a journal that makes a new component containing all the bodies in Layer 1 from all components. (This is a simple aproximation of real thing)
Firstly I cycle all components in assembly, collecting for each component the bodies in layer 1 and creating a List (Of Body) with these objects (waveList).
Then I create a new component and set it as workPart.(test.prt)
Finally, I try to make the wave links with waveLinkBuilder using the list of bodies but this gives me an error: "Can't create the wavelink feature because the object selected is into the workPart"

The code:
Code:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies
Imports System.Collections.Generic
Module NXJournal
Public theSession As Session = Session.GetSession()
Public ufs As UFSession = UFSession.GetUFSession()
Public lw As ListingWindow = theSession.ListingWindow
Dim waveList As New List(Of Body)
Dim workPart As Part = theSession.Parts.Work
Dim dispPart As Part = theSession.Parts.Display
Sub Main()
lw.Open()
Try
Dim c As ComponentAssembly = dispPart.ComponentAssembly
'to process the work part rather than the display part,
' comment the previous line and uncomment the following line
'Dim c As ComponentAssembly = workPart.ComponentAssembly
If Not IsNothing(c.RootComponent) Then
'*** insert code to process 'root component' (assembly file)
'lw.WriteLine("Assembly: " & c.RootComponent.DisplayName)
'lw.WriteLine(" + Active Arrangement: " & c.ActiveArrangement.Name)
'*** end of code to process root component
reportComponentChildren(c.RootComponent, 0)
Else
'*** insert code to process piece part
lw.WriteLine("Part has no components")
End If
Catch e As Exception
theSession.ListingWindow.WriteLine("Failed: " & e.ToString)
End Try
createComponent()
addWave(waveList)
End Sub
'**********************************************************
Sub reportComponentChildren(ByVal comp As Component,
ByVal indent As Integer)
For Each child As Component In comp.GetChildren()
'*** insert code to process component or subassembly
'lw.WriteLine(New String(" ", indent * 2) & child.DisplayName())
'*** end of code to process component or subassembly
If child.GetChildren.Length <> 0 Then
'*** this is a subassembly, add code specific to subassemblies
'*** end of code to process subassembly
Else
'this component has no children (it is a leaf node)
'add any code specific to bottom level components
Dim myPart As Part
myPart = child.Prototype
For Each myObj As Body In myPart.Bodies
If myObj.Layer = 1 Then
waveList.Add(myObj)
Else
End If
Next
End If
reportComponentChildren(child, indent + 1)
Next
End Sub
Function createComponent()
Dim FileName As String = "c:\temp\test.prt"
Dim newName As String = FileName
Dim fileNew1 As NXOpen.FileNew = Nothing
fileNew1 = theSession.Parts.FileNew()
fileNew1.TemplateFileName = "Ekide_model-plain-1-mm-template.prt"
fileNew1.UseBlankTemplate = False
fileNew1.ApplicationName = "ModelTemplate"
fileNew1.Units = NXOpen.Part.Units.Millimeters
fileNew1.RelationType = ""
fileNew1.UsesMasterModel = "No"
fileNew1.TemplateType = NXOpen.FileNewTemplateType.Item
fileNew1.TemplatePresentationName = "Plantilla_model"
fileNew1.ItemType = ""
fileNew1.Specialization = ""
fileNew1.SetCanCreateAltrep(False)
fileNew1.NewFileName = FileName
fileNew1.MasterFileName = ""
fileNew1.MakeDisplayedPart = False
fileNew1.DisplayPartOption = NXOpen.DisplayPartOption.AllowAdditional
Dim createNewComponentBuilder1 As NXOpen.Assemblies.CreateNewComponentBuilder = Nothing
createNewComponentBuilder1 = workPart.AssemblyManager.CreateNewComponentBuilder()
createNewComponentBuilder1.ReferenceSetName = "MODEL"
createNewComponentBuilder1.LayerOption = NXOpen.Assemblies.CreateNewComponentBuilder.ComponentLayerOptionType.Original
createNewComponentBuilder1.ComponentOrigin = NXOpen.Assemblies.CreateNewComponentBuilder.ComponentOriginType.Absolute
createNewComponentBuilder1.OriginalObjectsDeleted = False
createNewComponentBuilder1.DefiningObjectsAdded = False
createNewComponentBuilder1.NewComponentName = "test"
createNewComponentBuilder1.NewFile = fileNew1
Dim nXObject1 As NXOpen.NXObject = Nothing
nXObject1 = createNewComponentBuilder1.Commit()
createNewComponentBuilder1.Destroy()
Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing
theSession.Parts.SetWorkComponent(nXObject1, NXOpen.PartCollection.RefsetOption.Entire, NXOpen.PartCollection.WorkComponentOption.Given, partLoadStatus1)
End Function
Function addWave(ByRef waveList As List(Of Body))
Dim nullFeatures_Feature As Features.Feature = Nothing
workPart = theSession.Parts.Work
Dim waveLinkBuilder1 As Features.WaveLinkBuilder
waveLinkBuilder1 = workPart.BaseFeatures.CreateWaveLinkBuilder(nullFeatures_Feature)
Dim extractFaceBuilder1 As Features.ExtractFaceBuilder
extractFaceBuilder1 = waveLinkBuilder1.ExtractFaceBuilder
extractFaceBuilder1.FaceOption = Features.ExtractFaceBuilder.FaceOptionType.FaceChain
waveLinkBuilder1.Type = Features.WaveLinkBuilder.Types.BodyLink
extractFaceBuilder1.FaceOption = Features.ExtractFaceBuilder.FaceOptionType.FaceChain
waveLinkBuilder1.CopyThreads = False
extractFaceBuilder1.ParentPart = Features.ExtractFaceBuilder.ParentPartType.OtherPart
extractFaceBuilder1.Associative = True
extractFaceBuilder1.FixAtCurrentTimestamp = False
extractFaceBuilder1.HideOriginal = False
extractFaceBuilder1.InheritDisplayProperties = False
Dim selectObjectList1 As SelectObjectList
selectObjectList1 = extractFaceBuilder1.BodyToExtract
extractFaceBuilder1.CopyThreads = False
Dim added1 As Boolean
added1 = selectObjectList1.Add(waveList.ToArray)
Dim nXObject1 As NXObject
nXObject1 = waveLinkBuilder1.Commit()
waveLinkBuilder1.Destroy()
End Function
'**********************************************************
Public Function GetUnloadOption(ByVal dummy As String) As Integer
Return Session.LibraryUnloadOption.Immediately
End Function
'**********************************************************
End Module
Any hint to solve the situation?
Regards,
Javi
NX 12.0.2.9 MP14