ArcMcE
Electrical
- Dec 7, 2015
- 4
Hello,
I've been trying to create a journal to send all components in an assembly which begin with a certain letter (in this case 'F') to a layer. I've tried loads of bits of code from other similar threads online, but cant get any of them to work. I think the problem might be that I am using the wrong object type (if that's the right term? I mean such as 'as component' or 'as ComponentAssembly'). I was trying to add the components that begin with F to an array, which i would then process to move the layer.
The code below is one not-working version of what i have managed to do so far. I tried using parts of the code which is created when i recorded a journal of moving a component to a layer, but that didn't work either. The commented out section of the code is what i used to see if the code is at least finding any components beginning with the letter F, and it seems to be able to do that - Its just the moving to a layer part I'm stuck with.
I hope someone will be able to point me in the right direction.
Thanks in advance.
I've been trying to create a journal to send all components in an assembly which begin with a certain letter (in this case 'F') to a layer. I've tried loads of bits of code from other similar threads online, but cant get any of them to work. I think the problem might be that I am using the wrong object type (if that's the right term? I mean such as 'as component' or 'as ComponentAssembly'). I was trying to add the components that begin with F to an array, which i would then process to move the layer.
The code below is one not-working version of what i have managed to do so far. I tried using parts of the code which is created when i recorded a journal of moving a component to a layer, but that didn't work either. The commented out section of the code is what i used to see if the code is at least finding any components beginning with the letter F, and it seems to be able to do that - Its just the moving to a layer part I'm stuck with.
I hope someone will be able to point me in the right direction.
Thanks in advance.
Code:
Option Strict Off
Imports System
Imports System.Collections
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Utilities
Imports NXOpen.Assemblies
Imports NXOpenUI
Module NXJournal
Sub Main()
Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim workPart As NXOpen.Part = theSession.Parts.Work
Dim dispPart As NXOpen.Part = theSession.Parts.Display
Dim lw As ListingWindow = theSession.ListingWindow
lw.SelectDevice(ListingWindow.DeviceType.Window, "")
lw.Open()
Try
Dim c As ComponentAssembly = dispPart.ComponentAssembly
Dim Fixings As ArrayList = New ArrayList
Dim Part(0) As NXOpen.DisplayableObject
If Not IsNothing(c.RootComponent) Then
ReportComponentChildren(c.RootComponent, Fixings, Part)
'Dim fixing As String
'For Each fixing In fixings
' lw.writeline(fixing)
'Next
Else
lw.WriteLine("Part has no components")
End If
Catch e As Exception
theSession.ListingWindow.WriteLine("Failed: " & e.ToString)
End Try
End Sub
Sub reportComponentChildren(ByVal comp As Component, ByRef Fixings As arraylist, ByVal Part() As DisplayableObject)
For Each child As component In comp.GetChildren()
If child.DisplayName.ToUpper Like "F*" Then
part(0) = child
workPart.Layers.MoveDisplayableObjects(199, part)
'Fixings.Add(child.DisplayName.ToUpper)
End If
reportComponentChildren(child, Fixings, part)
Next
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
Return Session.LibraryUnloadOption.Immediately
End Function
End Module