×
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

Component Group in NXOpen

Component Group in NXOpen

Component Group in NXOpen

(OP)
Hi all,

I've done quite a bit of searching on this, and read through the help files, but can't seem to get this to work. I am trying to make a (simple for now) program to select components and add them to a component group. (I know this can be easily done without a journal, but this will eventually be merged into a journal that will be doing several other things.)

I started of by using an example code for selecting objects and tried adding the component group in. Here's what I have so far:

CODE --> vb

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
        Dim lw As ListingWindow = theSession.ListingWindow
        Dim mySelectedObject As Assemblies.Component
        Dim Group1 As Assemblies.ComponentGroup

        lw.Open()
        
        'Continue prompting for a selection until the user
        '  presses Cancel or Back.
        Do Until SelectAnObject("Hey, select something", _
                               mySelectedObject) = Selection.Response.Cancel
            lw.WriteLine("Object Tag: " & mySelectedObject.Tag)
            lw.WriteLine("object Name: " & mySelectedObject.Name)
            lw.WriteLine("Object Type: " & mySelectedObject.GetType.ToString)
            lw.WriteLine("")
            Group1.AddComponent(mySelectedObject, 0)

        Loop


        ' The close method closes the text stream to the window,
        '   it does not close the window itself
        '   (use the .CloseWindow() method for that).
        ' Also, if you are using the listing window to write
        '   to a file, the close method will clean up and close the file.
        lw.Close()

    End Sub

    Function SelectAnObject(ByVal prompt As String, _
               ByRef selObj As NXObject) As Selection.Response

        Dim theUI As UI = UI.GetUI
        Dim cursor As Point3d
        Dim typeArray() As Selection.SelectionType = _
            {Selection.SelectionType.All, _
                Selection.SelectionType.Faces, _
                Selection.SelectionType.Edges, _
                Selection.SelectionType.Features}

        Dim resp As Selection.Response = theUI.SelectionManager.SelectObject( _
                prompt, "Selection", _
                Selection.SelectionScope.AnyInAssembly, _
                False, typeArray, selobj, cursor)

        If resp = Selection.Response.ObjectSelected Or _
                resp = Selection.Response.ObjectSelectedByName Then
            Return Selection.Response.Ok
        Else
            Return Selection.Response.Cancel
        End If

    End Function

End Module 

There issue I'm having is I'm not sure how to initialize the ComponentGroup (group1), so the line "Group1.AddComponent(myselectedobject,0)" is just giving an error.

Any help would be appreciated.

Thanks!

RE: Component Group in NXOpen

Do you want to create a new component group in the current work part, or do you want to create a new component group?

If you want to use an existing group, iterate through the workpart.ComponentGroups collection to find the one you want.

If you want to create a new group, use Group1 = workpart.ComponentGroups.CreateComponentGroup(...).

www.nxjournaling.com

RE: Component Group in NXOpen

(OP)
Thanks cowski! That's exactly what I needed. Is there any way to control turning on/off the component groups through a Journal?

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