×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Journal to move assembly components beginning with a certain letter to a layer

Journal to move assembly components beginning with a certain letter to a layer

Journal to move assembly components beginning with a certain letter to a layer

(OP)
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.

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 

RE: Journal to move assembly components beginning with a certain letter to a layer

(OP)
Hello,

I managed to fix this myself - It's messy but it does the job! I hadn't passed the 'workpart' to the 'reportComponentChildren' sub.

If anyone has any general tips for cleaning up this code, I'd be happy to hear them.

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, workpart)

                '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, ByVal workpart As NXOpen.part)


        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, workpart)
        Next
    End Sub

    Public Function GetUnloadOption(ByVal dummy As String) As Integer
        Return Session.LibraryUnloadOption.Immediately
    End Function

End Module 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources