Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Journal cycle problem. CAM operation transform

Status
Not open for further replies.

rafl

Mechanical
May 30, 2011
41
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

 
Replies continue below

Recommended for you

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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor