SynchronizeAttributes

Hy alltogether,

i tried to sync the Routing attributes from the part to the assembly.
It works pretty good if i use properties inside NX.

I recordet a Journal to see what happend and have a look into net.ref.

What i tried out is the following Code but it didn´t work.


Sub Main(ByVal args() As String)

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")

Dim cw As ComponentAssembly = workPart.ComponentAssembly
If Not IsNothing(cw.RootComponent) Then
For Each child As Component In cw.RootComponent.GetChildren()

Dim objects1(0) As NXObject
objects1(0) = child
Dim assembliesGeneralPropertiesBuilder1 As Assemblies.AssembliesGeneralPropertiesBuilder
assembliesGeneralPropertiesBuilder1 = workPart.PropertiesManager.CreateAssembliesGeneralPropertiesBuilder(objects1)

assembliesGeneralPropertiesBuilder1.SynchronizeAttributes()

Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Komponente Eigenschaften")

theSession.DeleteUndoMark(markId2, Nothing)

Dim markId3 As Session.UndoMarkId
markId3 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Komponente Eigenschaften")

Dim nXObject1 As NXObject
nXObject1 = assembliesGeneralPropertiesBuilder1.Commit()

'workPart.PartPreviewMode = BasePart.PartPreview.None

Dim id1 As Session.UndoMarkId
id1 = theSession.GetNewestUndoMark(Session.MarkVisibility.Visible)

Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.DoUpdate(id1)

theSession.DeleteUndoMark(markId3, Nothing)

theSession.SetUndoMarkName(id1, "Komponente Eigenschaften")

assembliesGeneralPropertiesBuilder1.Destroy()

Next
End If

End Sub

Can somebody help please.

Thanks Hagen

I'm not familiar with the routing application. Do the routing attributes show up as part attributes or are they applied directly to the routing objects?

Yes, if you open item as display part or sync attributes you can see it under properties - attributes.
I work also with workpart.getuserattribute and everthing is fine.
If I reopen assembly and rightklick the part, choose property - attribute it is empty.
In this case I need to sync them to the assembly.
I hope I discribed it in the right way.

Thanks Hagen

NX 9 and Team Center 10

When you right click on a subassembly in the assembly navigator and choose: properties -> assembly -> synchronize subassembly properties, there are options for "layers", "display", and "attributes". Is this the same 'synchronize attributes' that you want to accomplish with the API?

Or did you have something else in mind?

Yes this is exactly what I want to do.

NX 9 and Team Center 10

From what I can see, the "synchronize attributes" command is only valid to use on subassemblies. The code below looks for subassmeblies in the currently displayed part and runs the "synchronize attributes" command on them.

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.Assemblies

Module Module1

Dim theSession As Session = Session.GetSession()
Dim lw As ListingWindow = theSession.ListingWindow
Dim workPart As Part = theSession.Parts.Work
Dim dispPart As Part = theSession.Parts.Display

Sub Main()

If IsNothing(theSession.Parts.BaseWork) Then
'active part required
Return
End If

lw.Open()

Const undoMarkName As String = "Synchronize Attributes"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)

Try
Dim c As ComponentAssembly = dispPart.ComponentAssembly
If Not IsNothing(c.RootComponent) Then
ProcessComponentChildren(c.RootComponent)
End If
Catch e As Exception
theSession.ListingWindow.WriteLine("Failed: " & e.ToString)
End Try
lw.Close()

End Sub

Sub ProcessComponentChildren(ByVal comp As Component)

For Each child As Component In comp.GetChildren()
If child.GetChildren.Length <> 0 Then
'*** this is a subassembly, add code specific to subassemblies

Dim objects1(0) As NXObject

objects1(0) = child
Dim assembliesGeneralPropertiesBuilder1 As Assemblies.AssembliesGeneralPropertiesBuilder
assembliesGeneralPropertiesBuilder1 = dispPart.PropertiesManager.CreateAssembliesGeneralPropertiesBuilder(objects1)

assembliesGeneralPropertiesBuilder1.SynchronizeAttributes()

Dim nXObject1 As NXObject
nXObject1 = assembliesGeneralPropertiesBuilder1.Commit()

Dim id1 As Session.UndoMarkId
id1 = theSession.GetNewestUndoMark(Session.MarkVisibility.Visible)

Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.DoUpdate(id1)

assembliesGeneralPropertiesBuilder1.Destroy()

End If
ProcessComponentChildren(child)
Next
End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

End Function

End Module

Thank you so much.

The code works great. The only thing is that you raise an exception if a subassembly is unload.
This is not important for me and i can solve my self if nessesary.
Is only an information if somebody else will use it.

Thanks Hagen

NX 9 and Team Center 10

Yes, I noticed that during my testing, but forgot to mention it in the description above. Thanks for the reminder.