How to move all Assembly Components to particular layer(1) using journal
How to move all Assembly Components to particular layer(1) using journal
(OP)
Hi,
This is shanmuk, new to NX7.5
I need your help in creating journal for assembly components.
Tool: UG/NX 7.5
Need:
I want to move all assembly components to layer 1 using journal.
Can you please help me in creating journal for the above need.
This is shanmuk, new to NX7.5
I need your help in creating journal for assembly components.
Tool: UG/NX 7.5
Need:
I want to move all assembly components to layer 1 using journal.
Can you please help me in creating journal for the above need.





RE: How to move all Assembly Components to particular layer(1) using journal
CODE -->
Option Strict Off Imports System Imports System.Collections Imports NXOpen Imports NXOpen.Utilities Imports NXOpen.Assemblies Module MoveComponents Dim s As Session = Session.GetSession() Dim lw As ListingWindow = s.ListingWindow Sub Main() Dim allComp1 As ArrayList = New ArrayList Dim displaypart As Part = s.Parts.Display Dim root As Component = s.Parts.Display.ComponentAssembly.RootComponent getAllComponents2(root, allComp1) Dim cnt1 As Integer = allComp1.Count Dim objectArray1(cnt1 - 1) As DisplayableObject For i As Integer = 0 To cnt1 - 1 objectArray1(i) = allComp1(i) Next displaypart.Layers.MoveDisplayableObjects(1, objectArray1) End Sub Sub getAllComponents2(ByVal comp As Component, ByRef allComp As ArrayList) Dim child As Component = Nothing Dim space As String = Nothing For Each child In comp.GetChildren() allComp.Add(child) getAllComponents2(child, allComp) 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 ModuleRegards
Frank Swinkels
RE: How to move all Assembly Components to particular layer(1) using journal
thanks for your valuable reply and i tried your journal, it is working fine and thanks for that. I have some more queries i hope you will advise me in regarding.
1. From the above journal it was moving all assembly components to layer 1. (that's really helpful to me) But, I have a range that all assembly components should be in between layer (1 to 10), some components which are already in layer below 10 those components are also moving to layer 1. Please suggest me, (in leaving those components which are in layer <10 same as previous but changing the component layer >10 to layer 1).
2. I am trying the below journal to find out the (referenceset_entire part or referenceset_empty) only. But, this journal showing all reference set which are in assembly, I need only specific reference set.
Example: An assembly containing 10 sub assembly components (out of 10 sub assemblies, 4 sub assembly components having reference set name as "S" and another 4 sub assembly components having reference set name as "S-T/L" and remaining two having reference set as Entire Part (which is none)). I need the journal to list only those two components which having reference set as Entire part. "Please have a look on below journal"
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.Assemblies
Imports NXOpen.UF
Module report_components
Dim s As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim lw As ListingWindow = s.ListingWindow
Sub Main()
lw.Open()
Dim root As Component = _
s.Parts.Display.ComponentAssembly.RootComponent
reportComponentChildren(root, 0)
End Sub
Sub reportComponentChildren(ByVal comp As Component, _
ByVal indent As Integer)
Dim child As Component = Nothing
Dim space As String = Nothing
Dim c_part As Part = Nothing
Dim c_obj As NXObject = Nothing
For ii As Integer = 1 To indent
space = space & " "
Next
For Each child In comp.GetChildren()
'c_obj = child.Prototype
'lw.WriteLine(space & child.Name)
'c_part = DirectCast(child.Prototype, Part)
'lw.WriteLine(space & child.Name & " " & c_part.FullPath)
Dim cpTag As NXOpen.Tag = child.Tag()
Dim partName As String = ""
Dim refsetName As String = ""
Dim instName As String = ""
Dim origin(2) As Double
Dim csysMatrix(8) As Double
Dim xform(3, 3) As Double
ufs.Assem.AskComponentData(cpTag, partName, refsetName, instName, origin, csysMatrix, Xform)
lw.WriteLine(child.Name & " " & refsetName)
reportComponentChildren(child, indent + 1)
Next
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
Return Session.LibraryUnloadOption.Immediately
End Function
End Module
RE: How to move all Assembly Components to particular layer(1) using journal
CODE -->
Option Strict Off Imports System Imports System.Collections Imports NXOpen Imports NXOpen.Utilities Imports NXOpen.Assemblies Module MoveComponents Dim s As Session = Session.GetSession() Dim lw As ListingWindow = s.ListingWindow Sub Main() Dim allComp1 As ArrayList = New ArrayList Dim displaypart As Part = s.Parts.Display Dim root As Component = s.Parts.Display.ComponentAssembly.RootComponent getAllComponents2(root, allComp1) Dim dispobj As DisplayableObject = Nothing Dim objectArray1(-1) As DisplayableObject Dim objlayer As Integer = Nothing Dim cnt2 As Integer = 0 For i As Integer = 0 To cnt1 - 1 dispobj = DirectCast(allComp1(i), DisplayableObject) objlayer = dispobj.Layer If objlayer > 10 Then ReDim Preserve objectArray1(cnt2) objectArray1(cnt2) = allComp1(i) cnt2 += 1 End If Next If cnt2 > 0 Then displaypart.Layers.MoveDisplayableObjects(1, objectArray1) End If End Sub Sub getAllComponents2(ByVal comp As Component, ByRef allComp As ArrayList) Dim child As Component = Nothing Dim space As String = Nothing For Each child In comp.GetChildren() allComp.Add(child) getAllComponents2(child, allComp) 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 ModuleI have changed your second journal just to make it similar to the first layer in that I use the array list of components. This makes it much easier to combine/change any journal. Since in this journal we are only looking for reference sets I have used an alternative method.
CODE -->
Option Strict Off Imports System Imports System.Collections Imports NXOpen Imports NXOpen.Assemblies Imports NXOpen.UF Module ReportReferenceSet Dim s As Session = Session.GetSession() Dim ufs As UFSession = UFSession.GetUFSession() Dim lw As ListingWindow = s.ListingWindow Sub Main() Dim allComp1 As ArrayList = New ArrayList Dim displaypart As Part = s.Parts.Display lw.Open() Dim root As Component = s.Parts.Display.ComponentAssembly.RootComponent getAllComponents2(root, allComp1) Dim referenceSet1 As String = "Entire Part" reportComponentReferenceSet(allComp1, referenceSet1) End Sub Sub reportComponentReferenceSet(ByVal allComp1 As ArrayList, ByVal referenceSet1 As String) For Each comp As Component In allComp1 If comp.ReferenceSet = referenceSet1 Then lw.WriteLine(comp.Name & " " & comp.ReferenceSet) End If Next End Sub Sub getAllComponents2(ByVal comp As Component, ByRef allComp As ArrayList) Dim child As Component = Nothing Dim space As String = Nothing For Each child In comp.GetChildren() allComp.Add(child) getAllComponents2(child, allComp) Next End Sub Public Function GetUnloadOption(ByVal dummy As String) As Integer Return Session.LibraryUnloadOption.Immediately End Function End ModuleRegards
Frank Swinkels
RE: How to move all Assembly Components to particular layer(1) using journal
I will try these journals and come back to you with results
RE: How to move all Assembly Components to particular layer(1) using journal
For second journal for reference sets it was working perfectly, thank you very much.
for first journal it was showing an error like [ cnt1 is not defined ] please see the attached snap shot.
some what i tried to define (cnt1) but i didnt get any result. Please suggest.
RE: How to move all Assembly Components to particular layer(1) using journal
After the line
getAllComponents2(root, allComp1)
in main sub insert a line
Dim cnt1 As Integer = allComp1.Count
Regards
Frank Swinkels
RE: How to move all Assembly Components to particular layer(1) using journal
Now it is working for me..
thank you..
RE: How to move all Assembly Components to particular layer(1) using journal
I need your help and suggestion in regarding.
Is there any program in journal or grip to the below activity ?
ex:
I use 5 .prt files in my daily use of work which was saved in some location. Can we call that .prt file through icon in NX 7.5, If it is possible please guide me. How i need is if i click on icon in toolbar. it should show the list of 5 .prt files. So, that i can use the need one in single click.
Thanks in Advance.
RE: How to move all Assembly Components to particular layer(1) using journal
I have attached two images. Image1.jpg shows the selection dialog for 5 parts which whould run from the added file open icon on image2.jpg. The five blank icons would be separate programs to open parts.
Frank Swinkels
RE: How to move all Assembly Components to particular layer(1) using journal
I need like image 1. What is the program for that ?
RE: How to move all Assembly Components to particular layer(1) using journal
You have given the below journal to Find out the Reference Set "Entire Part". What changes to be done to the following journal for replacing the "Entire Part" to Reference Set "S". Please advice.
Option Strict Off
Imports System
Imports System.Collections
Imports NXOpen
Imports NXOpen.Assemblies
Imports NXOpen.UF
Module ReportReferenceSet
Dim s As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim lw As ListingWindow = s.ListingWindow
Sub Main()
Dim allComp1 As ArrayList = New ArrayList
Dim displaypart As Part = s.Parts.Display
lw.Open()
Dim root As Component = s.Parts.Display.ComponentAssembly.RootComponent
getAllComponents2(root, allComp1)
Dim referenceSet1 As String = "Entire Part"
reportComponentReferenceSet(allComp1, referenceSet1)
End Sub
Sub reportComponentReferenceSet(ByVal allComp1 As ArrayList, ByVal referenceSet1 As String)
For Each comp As Component In allComp1
If comp.ReferenceSet = referenceSet1 Then
lw.WriteLine(comp.Name & " " & comp.ReferenceSet)
End If
Next
End Sub
Sub getAllComponents2(ByVal comp As Component, ByRef allComp As ArrayList)
Dim child As Component = Nothing
Dim space As String = Nothing
For Each child In comp.GetChildren()
allComp.Add(child)
getAllComponents2(child, allComp)
Next
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
Return Session.LibraryUnloadOption.Immediately
End Function
End Module
RE: How to move all Assembly Components to particular layer(1) using journal
CODE -->
Option Strict Off Imports System Imports System.Collections Imports NXOpen Imports NXOpen.Assemblies Imports NXOpen.UF Module ReportReferenceSet Dim s As Session = Session.GetSession() Dim ufs As UFSession = UFSession.GetUFSession() Dim lw As ListingWindow = s.ListingWindow Dim displaypart As Part = s.Parts.Display Sub Main() Dim allComp1 As ArrayList = New ArrayList ' lw.Open() Dim root As Component = s.Parts.Display.ComponentAssembly.RootComponent getAllComponents2(root, allComp1) Dim referenceSet1 As String = "Entire Part" Dim referenceSet2 As String = "S" ' reportComponentReferenceSet(allComp1, referenceSet1) ChangeComponentReferenceSet(allComp1, referenceSet1, referenceSet2) End Sub Sub reportComponentReferenceSet(ByVal allComp1 As ArrayList, ByVal referenceSet1 As String) For Each comp As Component In allComp1 If comp.ReferenceSet = referenceSet1 Then lw.WriteLine(comp.Name & " " & comp.ReferenceSet) End If Next End Sub Sub ChangeComponentReferenceSet(ByVal allComp1 As ArrayList, ByVal referenceSet1 As String, _ ByVal referenceSet2 As String) Dim errorList1 As ErrorList Dim comp1(0) As Component For Each comp As Component In allComp1 If comp.ReferenceSet = referenceSet1 Then comp1(0) = comp errorList1 = displaypart.ComponentAssembly.ReplaceReferenceSetInOwners(referenceSet2, comp1) End If Next End Sub Sub getAllComponents2(ByVal comp As Component, ByRef allComp As ArrayList) Dim child As Component = Nothing Dim space As String = Nothing For Each child In comp.GetChildren() allComp.Add(child) getAllComponents2(child, allComp) Next End Sub Public Function GetUnloadOption(ByVal dummy As String) As Integer Return Session.LibraryUnloadOption.Immediately End Function End ModuleRegards
Frank Swinkels
RE: How to move all Assembly Components to particular layer(1) using journal
It is possible to do what you want. You could have an icon for each of the 5 part files that you use daily. What it would need is a simple program for the toolbar such that the part is opened. Alternatively you can have a single icon which start a program from which you would select a part file to open.
I have attached two images. Image1.jpg shows the selection dialog for 5 parts which whould run from the added file open icon on image2.jpg. The five blank icons would be separate programs to open parts.
Frank Swinkels
I need program for image 1, please advice and thanks.
RE: How to move all Assembly Components to particular layer(1) using journal
I want to run a journal, Which will create one reference set and will move all the components to the same reference set.
Example:
If I modeled an assembly which contains 20 sub assemblies. After completing my model I need the following with a single click. (If it is possible please guide me)
My Need:
I need a journal to create Reference Set name as "Assembly", after creating reference set it should move all the assembly components to the same "Assembly" reference set.
Thanks in Advance.
RE: How to move all Assembly Components to particular layer(1) using journal
Set up a directory such as
C:\myprograms Instead of myprograms you can have whatever you want.
Create next level directories as
C:\myprograms\application
C:\myprograms\startup
In your UGII_BASE_DIR\ugii\menus directory you have a file custom_dirs.dat Edit this file and add a line
C:\myprograms\
Finally create an environment variable
UGII_CUSTOM_DIRECTORY_FILE
which points to your UGII_BASE_DIR\ugii\menus\custom_dirs.dat file
If all is setup correctly then when you run the journal it will display the dialog. If it is not set up correctly you will get a message that the dialog cannot be found.
Remember that at this point the program does not do anything yet. First you need to have it set up correctly then we need to add the toolbar and finally you will need to supply the file names and full file paths.
On the other issue regarding assembly reference sets I suggest you look at the thread. I have nothing to add.
Frank Swinkels
RE: How to move all Assembly Components to particular layer(1) using journal
I will come back to you with result
RE: How to move all Assembly Components to particular layer(1) using journal
Option Strict Off
Imports System
Imports System.Collections
Imports NXOpen
Imports NXOpen.Assemblies
Imports NXOpen.UF
Module ReportReferenceSet
Dim s As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim lw As ListingWindow = s.ListingWindow
Dim displaypart As Part = s.Parts.Display
Sub Main()
Dim allComp1 As ArrayList = New ArrayList
' lw.Open()
Dim root As Component = s.Parts.Display.ComponentAssembly.RootComponent
getAllComponents2(root, allComp1)
Dim referenceSet1 As String = "Entire Part"
Dim referenceSet2 As String = "S"
' reportComponentReferenceSet(allComp1, referenceSet1)
ChangeComponentReferenceSet(allComp1, referenceSet1, referenceSet2)
End Sub
Sub reportComponentReferenceSet(ByVal allComp1 As ArrayList, ByVal referenceSet1 As String)
For Each comp As Component In allComp1
If comp.ReferenceSet = referenceSet1 Then
lw.WriteLine(comp.Name & " " & comp.ReferenceSet)
End If
Next
End Sub
Sub ChangeComponentReferenceSet(ByVal allComp1 As ArrayList, ByVal referenceSet1 As String, _
ByVal referenceSet2 As String)
Dim errorList1 As ErrorList
Dim comp1(0) As Component
For Each comp As Component In allComp1
If comp.ReferenceSet = referenceSet1 Then
comp1(0) = comp
errorList1 = displaypart.ComponentAssembly.ReplaceReferenceSetInOwners(referenceSet2, comp1)
End If
Next
End Sub
Sub getAllComponents2(ByVal comp As Component, ByRef allComp As ArrayList)
Dim child As Component = Nothing
Dim space As String = Nothing
For Each child In comp.GetChildren()
allComp.Add(child)
getAllComponents2(child, allComp)
Next
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
Return Session.LibraryUnloadOption.Immediately
End Function
End Module
Regards,
Sam
RE: How to move all Assembly Components to particular layer(1) using journal
Now I will try to explain you better about my reference set requirements (Please see the attachments)
I have attached one model images for example:
A model contains 5 sub level assemblies and each sub assembly contain there individual reference sets say model ( Please See image 1). Now I will create a new reference set say T/L (Top Level) and i will move all sub assembly components to that "T/L" reference set. (Please See Image 2 & 3)
Now my requirement is Can we do the above procedure automatically. That i am using below journal which was recorded through NX, This journal is working for current model only. But, I need this journal to use for any model or any assembly part. (which creates new reference set and should move all components to that reference set). Please guide me. I hope so, you understood my requirement. Thanks for your patience.
Option Strict Off
Imports System
Imports NXOpen
Module NXJournal
Sub Main
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
' ----------------------------------------------
' Menu: Format->Reference Sets...
' ----------------------------------------------
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")
theSession.SetUndoMarkName(markId1, "Reference Sets Dialog")
Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Create New Reference Set")
Dim referenceSet1 As ReferenceSet
referenceSet1 = workPart.CreateReferenceSet()
Dim markId3 As Session.UndoMarkId
markId3 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Add Components to Reference Set")
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.DoUpdate(markId2)
Dim markId4 As Session.UndoMarkId
markId4 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Edit Name of Reference Set")
referenceSet1.SetName("T/L")
Dim nErrs2 As Integer
nErrs2 = theSession.UpdateManager.DoUpdate(markId4)
Dim markId5 As Session.UndoMarkId
markId5 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Edit Objects of Reference Set")
Dim components1(0) As NXObject
Dim component1 As Assemblies.Component = CType(workPart.ComponentAssembly.RootComponent.FindObject("COMPONENT sub level 1 1"), Assemblies.Component)
components1(0) = component1
referenceSet1.AddObjectsToReferenceSet(components1)
Dim nErrs3 As Integer
nErrs3 = theSession.UpdateManager.DoUpdate(markId5)
Dim markId6 As Session.UndoMarkId
markId6 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Edit Objects of Reference Set")
Dim components2(0) As NXObject
Dim component2 As Assemblies.Component = CType(workPart.ComponentAssembly.RootComponent.FindObject("COMPONENT sub level 2 1"), Assemblies.Component)
components2(0) = component2
referenceSet1.AddObjectsToReferenceSet(components2)
Dim nErrs4 As Integer
nErrs4 = theSession.UpdateManager.DoUpdate(markId6)
Dim markId7 As Session.UndoMarkId
markId7 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Edit Objects of Reference Set")
Dim components3(0) As NXObject
Dim component3 As Assemblies.Component = CType(workPart.ComponentAssembly.RootComponent.FindObject("COMPONENT sub level 3 1"), Assemblies.Component)
components3(0) = component3
referenceSet1.AddObjectsToReferenceSet(components3)
Dim nErrs5 As Integer
nErrs5 = theSession.UpdateManager.DoUpdate(markId7)
Dim markId8 As Session.UndoMarkId
markId8 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Edit Objects of Reference Set")
Dim components4(0) As NXObject
Dim component4 As Assemblies.Component = CType(workPart.ComponentAssembly.RootComponent.FindObject("COMPONENT sub level 4 1"), Assemblies.Component)
components4(0) = component4
referenceSet1.AddObjectsToReferenceSet(components4)
Dim nErrs6 As Integer
nErrs6 = theSession.UpdateManager.DoUpdate(markId8)
Dim markId9 As Session.UndoMarkId
markId9 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Edit Objects of Reference Set")
Dim components5(0) As NXObject
Dim component5 As Assemblies.Component = CType(workPart.ComponentAssembly.RootComponent.FindObject("COMPONENT sub level 5 1"), Assemblies.Component)
components5(0) = component5
referenceSet1.AddObjectsToReferenceSet(components5)
Dim nErrs7 As Integer
nErrs7 = theSession.UpdateManager.DoUpdate(markId9)
theSession.DeleteUndoMarksUpToMark(markId3, Nothing, False)
theSession.SetUndoMarkName(markId1, "Reference Sets")
theSession.DeleteUndoMark(markId1, Nothing)
' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------
End Sub
End Module
RE: How to move all Assembly Components to particular layer(1) using journal
Please look at my above issue.
Thanks & Regards,
Sam
RE: How to move all Assembly Components to particular layer(1) using journal
please look at my issue. I need your help in creating journal.
Thanks & Regards,
Sam