Jump to content

Welcome to eMastercam

Register now to participate in the forums, access the download area, buy Mastercam training materials, post processors and more. This message will be removed once you have signed in.

Use your display name or email address to sign in:

Retrieving chains by operation


Recommended Posts

Is there a way of getting an array of chains from a given operation? I'm writing my first nethook

and am wanting to process all chains that belong to the operations that were pre-selected by the user.

I've seen:

 

ChainManagerMode.GetOperationChains

 

in the API Reference Guide, but don't know how to apply this. Any help would be appreciated. Thanks.

Link to comment
Share on other sites

In the NET-Hook API Reference

I drilled down to Mastercam.Operations

Selected the Operation type I’m interested in (e.g. ContourOperation)

and in its Methods section I see GetChainArray – “This method retrieves the Chains in this operation.”

 

What are you trying to do with the Chains?

What type(s) of Operations are you "processing"?

Link to comment
Share on other sites

I am trying to reverse the chains, and before reversing the chains, store in a variable if the operation is using

left or right cutter comp. Then after reversing the chain set the cutter comp back to what it was previously.

This is what I have so far:

Public Overrides Function Run(ByVal param As Integer) As MCamReturn

            'Make sure there are operations to modify
            Dim ops As Array = Mastercam.Support.SearchManager.GetOperations().ToArray

            If ops.Length = 0 Then
                Debug.WriteLine("There Are No Operations To Modify")
                Return MCamReturn.FunctionExit
            End If

            Dim bSelect As Boolean = False

            'Loop through all operations to see if there are any selected
            For i As Integer = 0 To UBound(ops)
                Dim op As Mastercam.Database.Operation = CType(ops(i), Mastercam.Database.Operation)
                If Not op Is Nothing Then
                    If op.Selected = True Then
                        bSelect = True
                        Exit For
                    End If
                End If
            Next i

            'If there are no selected operations then let's exit
            If bSelect = False Then
                Debug.WriteLine("There Are No Selected Operations To Modify")
                Return MCamReturn.FunctionExit
            End If

            'Process all selected operations
            Dim bSuccess As Boolean = LoopThroughSelectedOps(ops)

            If bSuccess = True Then
                MsgBox("Chains Reversed And Flipped")
            Else
                MsgBox("Error Reversing Chains")
            End If

            Return MCamReturn.NoErrors

        End Function

Here is the code from my module:

Public Sub ReverseChains(ByVal OpToRegen As Mastercam.Database.Operation, ByVal chains As Array)

        If chains.Length = 0 Then Exit Sub

        For i As Integer = 0 To UBound(chains)

            Dim chain = CType(chains(i), Mastercam.Database.Chain)

            If chain.Direction = Mastercam.Database.Types.ChainDirectionType.Clockwise Then
                chain.Direction = Mastercam.Database.Types.ChainDirectionType.CounterClockwise
            ElseIf chain.Direction = Mastercam.Database.Types.ChainDirectionType.CounterClockwise Then
                chain.Direction = Mastercam.Database.Types.ChainDirectionType.Clockwise
            End If

            OpToRegen.Commit()
            OpToRegen.Regenerate()

        Next i

    End Sub

    Public Function LoopThroughSelectedOps(ByVal OpsToProcess As Array) As Boolean

        Dim TheAnswer As Boolean = False

        If OpsToProcess.Length = 0 Then
            TheAnswer = False
            Return TheAnswer
            Exit Function
        End If

        For i As Integer = 0 To UBound(OpsToProcess)

            Dim TheOp As Mastercam.Database.Operation = CType(OpsToProcess(i), Mastercam.Database.Operation)

            If TheOp IsNot Nothing Then

                If TheOp.Selected = True Then

                    If TheOp.Type = Mastercam.Database.Types.OperationType.Contour Then

                        Dim ContourOp As Mastercam.Operations.ContourOperation = CType(TheOp, Mastercam.Operations.ContourOperation)

                        ReverseChains(TheOp, ContourOp.GetChainArray)

                        'Dim ChainArray = ContourOp.GetChainArray

                    End If 'End of Contour Operation type if

                    If TheOp.Type = Mastercam.Database.Types.OperationType.Pocket Then

                        Dim PocketOp As Mastercam.Operations.PocketOperation = CType(TheOp, Mastercam.Operations.PocketOperation)

                        ReverseChains(TheOp, PocketOp.GetChainArray)

                    End If 'End of Pocket Operation type if

                    If TheOp.Type = Mastercam.Database.Types.OperationType.SlotMill Then

                        Dim SlotMillOp As Mastercam.Operations.SlotMillOperation = CType(TheOp, Mastercam.Operations.SlotMillOperation)

                        ReverseChains(TheOp, SlotMillOp.GetChainArray)

                    End If 'End of SlotMill Operation type if

                End If 'End of TheOp being selected if

            End If 'End of TheOp being nothing if

        Next i

        Return TheAnswer

    End Function

So far I am just trying to do the reverse chain part and when I debug the current code I have

it seems to delete the chain rather than reversing it.

Link to comment
Share on other sites

Thanks Mick! I was missing the "SetChainArray". Only problem I'm having is this works for when I chain

off of wire geometry that I draw myself in Mastercam or curves that I extract from the edges of the solid

model, but it doesn't work if I chain directly from the solid itself. Is there a way of checking what kind of

entity is used for the chain? Because right now it is deleting the chain if a solid edge is used.

Link to comment
Share on other sites
  • 9 months later...

Here is a screenshot of the code I use in ATP to reverse a chain, let me know of this helps.

Mick,

 

I'm trying to use this snippet to reverse toolpaths after mirroring geometry. I'm missing some basic stuff though:

 

  • How is the boolean(?) <conventional> assigned? (line 801 in the screenshot)
  • How are the classes(?) <definition> and <overrides> initiated? (lines 814, 817)

 

I will be happy to do some homework on this, but a little nudge in the right direction could sure help.

Thanks.

Link to comment
Share on other sites

Eric,

 

The bool conventional maps to a checkbox on the UI. The overrides are values set from the UI and whether the imported operations have depth or we are using the depth of the current drawing. You can set these to hard coded values while testing your code.

 

Mick

 

 

Mick,

 

I'm trying to use this snippet to reverse toolpaths after mirroring geometry. I'm missing some basic stuff though:

 

  • How is the boolean(?) <conventional> assigned? (line 801 in the screenshot)
  • How are the classes(?) <definition> and <overrides> initiated? (lines 814, 817)

 

I will be happy to do some homework on this, but a little nudge in the right direction could sure help.

Thanks.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.

Join us!

eMastercam - your online source for all things Mastercam.

Together, we are the strongest Mastercam community on the web with over 56,000 members, and our online store offers a wide selection of training materials for all applications and skill levels.

Follow us

×
×
  • Create New...