Showing results for 
Search instead for 
Did you mean: 

Journal to move a group


I've attempted to record a journal VB that selects a grouped set of lines and moves them a prescribed distance.  Simple enough, right?

The routine works perfectly in playback.  However if I subsequently delete or add any lines to the group, but VB code fails.  

Examining the code, despite the fact that I selected Groups during the recording of the code, the VB code records the selection of each individual component.


Here's the scenario:

I have multiple Named groupings of lines, arcs, text, etc. all located at the correct x,y,z coordinates

Each group is assigned to a reference set so that I can pull one p/n over into a master assy and choose the correct reference set to indicate which geometry set I need.  I know this may sound odd, but it is perfect for my purpose since I use the attibutes of each reference set to drive information table in my master assy.

The negative to this approach is that in my component file, all the lines, arcs, text, etc. is all a jumbled mess.  It's simple enough to select things because they are grouped, but a simple routine that selects each group individually and spaces them out in the x-dir (and a similar routine that does the reverse, restacking all the groups) is terribly convenient for editing.

So, back to the original question, is there VB code that will select the grouped objects by name and not the individual lines, arcs, text, etc?


Re: Journal to move a group

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

The code below will find a group with a given name. The group object can be passed to the move object command and the group and its members will be moved accordingly.


        Dim tmpGrp As NXOpen.Tag = NXOpen.Tag.Null
        Dim myGroup As Group
        Dim groupFound As Boolean = False

        Const targetGroupName As String = "TEST"

            theUfSession.Obj.CycleObjsInPart(workPart.Tag, UFConstants.UF_group_type, tmpGrp)
            'skip the initial null tag
            If tmpGrp = NXOpen.Tag.Null Then
                groupFound = True
                Continue Do
            End If

            myGroup = Utilities.NXObjectManager.Get(tmpGrp)
            If myGroup.Name = targetGroupName Then
                groupFound = True
                Exit Do
            End If

        Loop Until tmpGrp = NXOpen.Tag.Null

Re: Journal to move a group


Thank you.  

I attempted to paste this code into a simple routine but I got several Journal compile errors.  A few:

"item is not declared" errors and one "overload resolution failed because no accessible 'add' can be found.


I'm sorry, but I have little to no VB coding experience so I've probably pasted this in incorrectly.  


So, could you possibly help just a bit more and provide a complete code that does the following:


1) Selects a group called "bob" and moves it 100 inches in the x direction and then

2) Selects a group called "larry" and moves it 200 inces in the x direction


I think I could figure out the all of the other bits.


I appreciate your help.



Re: Journal to move a group

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

I had a chance to get back to this today. The code below will move a group named BOB 5 units in the absolute +X direction and LARRY 10 units in the absolute +X direction. The distances are easy to change, just plug in the numbers you want when you call the MoveStuff routine.


The code doesn't do much in the way of error checking and if you have multiple groups with the same name, it will only move the last one it finds.


Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module2

    Dim theSession As Session = Session.GetSession()
    Dim theUfSession As UFSession = UFSession.GetUFSession

    Sub Main()

        Dim workPart As Part = theSession.Parts.Work

        Dim lw As ListingWindow = theSession.ListingWindow

        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "move bob and larry")

        Dim tmpGrpTag As NXOpen.Tag = NXOpen.Tag.Null
        Dim tmpGrp As Group = Nothing
        Dim grpBob As Group = Nothing
        Dim grpLarry As Group = Nothing

            theUfSession.Obj.CycleObjsInPart(workPart.Tag, UFConstants.UF_group_type, tmpGrpTag)
            'skip the initial null tag
            If tmpGrpTag = NXOpen.Tag.Null Then
                Continue Do
            End If

            tmpGrp = Utilities.NXObjectManager.Get(tmpGrpTag)
            If tmpGrp.Name = "BOB" Then
                grpBob = tmpGrp
            End If

            If tmpGrp.Name = "LARRY" Then
                grpLarry = tmpGrp
            End If
        Loop Until tmpGrpTag = NXOpen.Tag.Null

        Dim xVec As New Vector3d(1, 0, 0)

        If Not IsNothing(grpBob) Then
            MoveStuff(grpBob, xVec, 5)
        End If

        If Not IsNothing(grpLarry) Then
            MoveStuff(grpLarry, xVec, 10)
        End If

    End Sub

    Sub MoveStuff(ByVal theObj As NXObject, ByVal vector1 As Vector3d, ByVal distance As Double)

        Dim nullFeatures_MoveObject As Features.MoveObject = Nothing

        Dim moveObjectBuilder1 As Features.MoveObjectBuilder
        moveObjectBuilder1 = theSession.Parts.Work.BaseFeatures.CreateMoveObjectBuilder(nullFeatures_MoveObject)

        moveObjectBuilder1.TransformMotion.Option = GeometricUtilities.ModlMotion.Options.Distance

        moveObjectBuilder1.TransformMotion.DistanceValue.RightHandSide = distance.ToString

        moveObjectBuilder1.MoveParents = False

        Dim origin1 As Point3d = New Point3d(0.0, 0.0, 0.0)
        Dim direction1 As Direction
        direction1 = theSession.Parts.Work.Directions.CreateDirection(origin1, vector1, SmartObject.UpdateOption.WithinModeling)

        moveObjectBuilder1.TransformMotion.DistanceVector = direction1

        Dim added1 As Boolean
        added1 = moveObjectBuilder1.ObjectToMoveObject.Add(theObj)

        Dim nXObject1 As NXObject
        nXObject1 = moveObjectBuilder1.Commit()

        Dim objects2() As NXObject
        objects2 = moveObjectBuilder1.GetCommittedObjects()


    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


Re: Journal to move a group


Works like a charm.  


So from one "pirate who doesn't do anything" to another.  Thanks alot!