×
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 cycle problem. CAM operation transform

Journal cycle problem. CAM operation transform

Journal cycle problem. CAM operation transform

(OP)
Journal creates cam operation mirror through a plane. It works when executed on operation, but when item is a group object I'm getting en error (see attached file).Please help me to get this journal working.



CODE

Option Strict Off
Imports System
Imports System.IO
Imports System.Windows.Forms
Imports NXOpen
Imports NXOpen.CAM
Imports NXOpen.UF
Imports NXOpen.Utilities

Module MirrorCAMops

    Dim theSession As Session
    Dim theUfSession As UFSession

    Sub Main()

        theSession = Session.GetSession()
        theUfSession = UFSession.GetUFSession()
        Dim WorkPart As Part = theSession.Parts.Work
        Dim setupTag As Tag
        Dim selectedTags() As NXOpen.Tag
        Dim selectedCount As Integer

        ' If there is a work part only then we can go further
        If WorkPart IsNot Nothing Then

            theUfSession.Cam.InitSession()
            theUfSession.Setup.AskSetup(setupTag)

            ' If there is a setup only then we go further
            If setupTag <> 0 Then
                ' Get the selected nodes from the Operation Navigator
                theUfSession.UiOnt.AskSelectedNodes(selectedCount, selectedTags)
                If selectedCount = 0 Then
                    MsgBox("No operations selected.", MsgBoxStyle.Exclamation)
                    Exit Sub
                End If
                Dim ptr As IntPtr = New System.IntPtr
                Dim cycle_cb_fn As UFNcgroup.CycleCbFT = New UFNcgroup.CycleCbFT(AddressOf cycle_cb)
                Dim datum As NXOpen.Tag
                Dim datumPlane1 = select_a_datum_plane(datum) = Selection.Response.Ok
                Dim i As Integer
                'Loop over the selected nodes to take action
                For i = 0 To selectedCount - 1
                    ' The selected item needs to be checked to take action
                    action(selectedTags(i))
                    ' Now if the selected item is a Group object then we need to cycle objects inside it
                    theUfSession.Ncgroup.CycleMembers(selectedTags(i), cycle_cb_fn, ptr)
                Next i
            End If
        End If
    End Sub

    Function cycle_cb(ByVal camObjectTag As Tag, ByVal ptr As IntPtr) As Boolean

        Dim answer As Boolean
        ' Every item needs to be checked to take action
        answer = action(camObjectTag)
        Return answer

    End Function

    Function action(ByVal camObjectTag As Tag) As Boolean

        Dim camObject As NXObject = NXObjectManager.Get(camObjectTag)
        Dim WorkPart As Part = theSession.Parts.Work
        'Check if the object is a Operation

        If TypeOf camObject Is CAM.Operation Then

            Dim objectsToTransform(0) As CAM.CAMObject

            Dim operationTransformBuilder1 As CAM.OperationTransformBuilder
            Dim origin1 As Point3d = New Point3d(0.0, 0.0, 0.0)
            Dim normal1 As Vector3d = New Vector3d(0.0, 0.0, 1.0)
            Dim plane1 As Plane

            objectsToTransform(0) = camObject
            operationTransformBuilder1 = WorkPart.CAMSetup.CreateOperationTransformBuilder(objectsToTransform)
            plane1 = WorkPart.Planes.CreatePlane(origin1, normal1, SmartObject.UpdateOption.WithinModeling)
            operationTransformBuilder1.Plane = plane1
            operationTransformBuilder1.TransformType = CAM.OperationTransformBuilder.Transform.MirrorThroughAPlane
            operationTransformBuilder1.MoveCopyInstance = CAM.OperationTransformBuilder.Result.Copy

            Dim nXObject1 As NXObject
            nXObject1 = operationTransformBuilder1.Commit()

            Dim objects1() As NXObject
            objects1 = operationTransformBuilder1.GetCommittedObjects()
            operationTransformBuilder1.Destroy()
        End If
        Return True
    End Function
    Function select_a_datum_plane(ByRef datum As NXOpen.Tag) As Selection.Response

        Dim message As String = "Datum Plane:"
        Dim title As String = "Select a Datum Plane"
        Dim scope As Integer = UFConstants.UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY
        Dim response As Integer
        Dim view As NXOpen.Tag
        Dim cursor(2) As Double
        Dim sel_mask As UFUi.SelInitFnT
        theUfSession.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
        Try
            theUfSession.Ui.SelectWithSingleDialog(message, title, scope, sel_mask, _
                         Nothing, response, datum, cursor, view)
        Finally
            theUfSession.Ui.UnlockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
        End Try
        If response <> UFConstants.UF_UI_OBJECT_SELECTED And _
           response <> UFConstants.UF_UI_OBJECT_SELECTED_BY_NAME Then
            Return Selection.Response.Cancel
        Else
            theUfSession.Disp.SetHighlight(datum, 0)
            Return Selection.Response.Ok
        End If

    End Function

End Module 

RE: Journal cycle problem. CAM operation transform

I think the problem is when it is a group you are cycling though the group and creating new operations changing the amount of items in the group so the next cycle it errors.
You need to cycle through the group just collecting the operations in an array then once done cycling through the group run through the array mirroring the operations.

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