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:

NetHooks get selection operation parameter question


Recommended Posts

Below has NetHooks  get selection operation parameter shown MainView, but only get one operation, if selection other operation show error and the parameter not update, I don't know where is error

 

 

'Option Infer On

' -----------------------------------------------------------------------
' <copyright file="NETHookMain.vb" company="CNC Software, Inc.">
' Copyright 2014 CNC Software, Inc..
' </copyright>
' -----------------------------------------------------------------------

Imports Mastercam.Database.Types
Imports Mastercam.IO
Imports Mastercam.IO.Types
Imports Mastercam.Math
Imports Mastercam.Support
Imports System.Globalization
Imports Mastercam.App
Imports Mastercam.App.Types
Imports Mastercam.BasicGeometry
Imports Mastercam.Database

Imports System.Collections.Generic
Imports System.Diagnostics.CodeAnalysis
Imports System.IO
Imports System.Windows.Forms
Imports Mastercam.Operations
Imports Mastercam.Support.Group
Imports Mastercam.Tools
Imports Mastercam.GeometryUtility.Types
Imports System.Math


Namespace QuickParameters

    Public Class NETHookMain
        Inherits NetHook3App

#Region "System Public Methods"

        Public Overrides Function Init(ByVal param As Integer) As MCamReturn
            Return MCamReturn.NoErrors
        End Function


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

            Using f As New MainView()
                'f.ShowDialog()
            End Using
            GetParameter()
            Return MCamReturn.NoErrors

        End Function

        Public Overrides Function Close(ByVal param As Integer) As MCamReturn
            Return MCamReturn.NoErrors
        End Function

        Public Overrides Function Notify(ByVal event_code As MCamEvent) As MCamReturn
            Select Case event_code
                Case MCamEvent.OperationSelectionsChanged
                    Dim selectedOperations = SearchManager.GetOperations()
                    Dim ss = SearchManager.GetOperation(True)
                    Dim xx As Boolean = ss.Selected

                    If xx = True Then
                        GetParameter(xx)

                    End If

                    'End If
                    Return MCamReturn.NoErrors
                Case Else
                    Return MCamReturn.NoErrors
            End Select
        End Function

#End Region
        Public Function GetParameter(Optional onlySelectedOps As Boolean = True) As Integer
            Dim Main As New MainView
            Dim sTool_typ As String = String.Empty
            Dim sOp_typ As String = String.Empty
            Dim sTool_clc As Double
            'Dim ops = SearchManager.GetOperations(onlySelectedOps)
            Dim ops = SearchManager.GetOperations(onlySelectedOps)
            Main.Update()
            Try
                For Each op As Operation In ops
                    Select Case op.OperationTool.ToolTypeID
                        Case 1
                            sTool_typ = "CenterDrillTool"
                        Case 2
                            sTool_typ = "SpotDrillTool"
                        Case 3
                            sTool_typ = "DrillTool"
                        Case 4
                            sTool_typ = "TapRHTool"
                        Case 5
                            sTool_typ = "TapLHTool"
                        Case 6
                            sTool_typ = "ReamerTool"
                        Case 7
                            sTool_typ = "BoreTool"
                        Case 8
                            sTool_typ = "CounterBoreTool"
                        Case 9
                            sTool_typ = "CounterSinkTool"
                        Case 10
                            sTool_typ = "EndMillFlatTool"
                        Case 11
                            sTool_typ = "EndMillSphericalTool"
                        Case 12
                            sTool_typ = "ChamferMillTool"
                        Case 13
                            sTool_typ = "FaceMillTool"
                        Case 14
                            sTool_typ = "SlotMillTool"
                        Case 15
                            sTool_typ = "RadiusMillTool"
                        Case 16
                            sTool_typ = "DoveMillTool"
                        Case 17
                            sTool_typ = "TaperedMillTool"
                        Case 18
                            sTool_typ = "LollipopMillTool"
                        Case 19
                            sTool_typ = "EndMillBullnoseTool"
                        Case 20
                            sTool_typ = "EngraveTool"
                        Case 21
                            sTool_typ = "BradPointDrillTool"
                        Case Else
                            sTool_typ = "UndefinedTool"
                    End Select

                    Select Case op.Type
                        Case 0
                            sOp_typ = "Unknown"
                        Case 1
                            sOp_typ = "Contour"
                        Case 2
                            sOp_typ = "Drilling 3-Axis Output Format"
                        Case 3
                            sOp_typ = "Pocket"
                        Case 4
                            sOp_typ = "Transform"
                        Case 5
                            sOp_typ = "Multisurface rough parallel"
                        Case 6
                            sOp_typ = "Multisurface rough radial"
                        Case 7
                            sOp_typ = "Multisurface rough project"
                        Case 8
                            sOp_typ = "Multisurface rough flowline"
                        Case 9
                            sOp_typ = "Multisurface rough contour"
                        Case 10
                            sOp_typ = "Multisurface rough pocket"
                        Case 11
                            sOp_typ = "Multisurface finish parallel"
                        Case 12
                            sOp_typ = "Multisurface finish radial"
                        Case 13
                            sOp_typ = "Multisurface finish project"
                        Case 14
                            sOp_typ = "Multisurface finish flowline"
                        Case 15
                            sOp_typ = "Multisurface finish contour"
                        Case 16
                            sOp_typ = "C-Hook Toolpath"
                        Case 17
                            sOp_typ = "Manual entry"
                        Case 18
                            sOp_typ = "Circle mill 3 Axis Output Format"
                        Case 19
                            sOp_typ = "Point"
                        Case 20
                            sOp_typ = "Trimmed"
                        Case 21
                            sOp_typ = "Ruled"
                        Case 22
                            sOp_typ = "Revolved"
                        Case 23
                            sOp_typ = "Letters"
                        Case 24
                            sOp_typ = "Swept 2D"
                        Case 25
                            sOp_typ = "Swept 3D"
                        Case 26
                            sOp_typ = "Coons"
                        Case 27
                            sOp_typ = "Lofted"
                        Case 28
                            sOp_typ = "Drilling 4 Axis or 5 Axis Output Format"
                        Case 29
                            sOp_typ = "-axis curve"
                        Case 30
                            sOp_typ = "Project toolpath onto a plane"
                        Case 31
                            sOp_typ = "Project toolpath onto a cylinder"
                        Case 32
                            sOp_typ = "Project toolpath onto a sphere"
                        Case 33
                            sOp_typ = "Project toolpath onto a cone"
                        Case 34
                            sOp_typ = "Project toolpath onto a cross section"
                        Case 35
                            sOp_typ = "Project toolpath onto a surface"
                        Case 36
                            sOp_typ = "Non-associative contour"
                        Case 37
                            sOp_typ = "Non-associative drilling"
                        Case 38
                            sOp_typ = "Non-associative pocketing"
                        Case 39
                            sOp_typ = "Multisurface finish pencil trace"
                        Case 40
                            sOp_typ = "Multisurface finish leftover stock"
                        Case 41
                            sOp_typ = "Multisurface finish steep"
                        Case 42
                            sOp_typ = "Multisurface finish shallow"
                        Case 43
                            sOp_typ = "Multisurface finish constant scallop"
                        Case 44
                            sOp_typ = "Multisurface rough plunge"
                        Case 45
                            sOp_typ = "Multisurface finish -axis flowline"
                        Case 46
                            sOp_typ = "Multisurface finish -axis"
                        Case 47
                            sOp_typ = "Merged in ASCII NCI"
                        Case 48
                            sOp_typ = "5-axis swarf"
                        Case 49
                            sOp_typ = "5-axis roll die"
                        Case 50
                            sOp_typ = "Unknown"
                        Case 99
                            sOp_typ = "Unknown"
                        Case 100
                            sOp_typ = "Thread mill"
                        Case 101
                            sOp_typ = "Edit common operation parameters"
                        Case 102
                            sOp_typ = "Facing"
                        Case 103
                            sOp_typ = "Associative trimmed"
                        Case 104
                            sOp_typ = "Solid drill control"
                        Case 105
                            sOp_typ = "Slot mill"
                        Case 106
                            sOp_typ = "Helix bore"
                        Case 107
                            sOp_typ = "Multi-surface rough restmill"
                        Case 108
                            sOp_typ = "Associative nesting container"
                        Case 109
                            sOp_typ = "Multi-surface finish blend"
                        Case 110
                            sOp_typ = "Multi-surface -axis, rough"
                        Case 111
                            sOp_typ = "Slice 5-axis"
                        Case 112
                            sOp_typ = "Port 5-axis"
                        Case 113
                            sOp_typ = "Circle mill 4-Axis or 5-Axis Output Format"
                        Case 114
                            sOp_typ = "Advanced drill"
                        Case 115
                            sOp_typ = "Chamfer drill"
                        Case 116
                            sOp_typ = "Unknown"
                        Case 129
                            sOp_typ = "Unknown"
                        Case 130
                            sOp_typ = "Tab cutoff"
                        Case 131
                            sOp_typ = "Multi-surface rough pocket, light"
                        Case 132
                            sOp_typ = "High-speed surface toolpaths"
                        Case 133
                            sOp_typ = "Nesting onionskin"
                        Case 134
                            sOp_typ = "2D hardmill machining/peel mill"
                        Case 135
                            sOp_typ = "Saw"
                        Case 136
                            sOp_typ = "FBM drill control"
                        Case 137
                            sOp_typ = "FBM mill pocket"
                        Case 138
                            sOp_typ = "FBM mill contour"
                        Case 139
                            sOp_typ = "Solid model"
                        Case 140
                            sOp_typ = "2D model chamfer"
                        Case 141
                            sOp_typ = "Unknown"
                        Case 149
                            sOp_typ = "Unknown"
                        Case 150
                            sOp_typ = "Probe cycle: probe motion"
                        Case 151
                            sOp_typ = "Probe cycle command block"
                        Case 152
                            sOp_typ = "Probe cycle header"
                        Case 153
                            sOp_typ = "Probe cycle trailer"
                        Case 154
                            sOp_typ = "SafetyZone linking or multiaxis linking"
                        Case 155
                            sOp_typ = "SafetyZone for multiaxis drill - only used for link_op"
                        Case 156
                            sOp_typ = "Unknown"
                        Case 300
                            sOp_typ = "Unknown"
                        Case 301
                            sOp_typ = "Router contour - obsolete"
                        Case 302
                            sOp_typ = "Router pocket - obsolete"
                        Case 303
                            sOp_typ = "Router circmill - obsolete"
                        Case 304
                            sOp_typ = "Router cutoff - obsolete"
                        Case 305
                            sOp_typ = "Router surface rough pocket - obsolete"
                        Case 306
                            sOp_typ = "Block drill"
                        Case 307
                            sOp_typ = "Unknown"
                        Case 415
                            sOp_typ = "Unknown"
                        Case 416
                            sOp_typ = "Engraving"
                        Case 417
                            sOp_typ = "Unknown"
                        Case 438
                            sOp_typ = "Unknown"
                        Case 439
                            sOp_typ = "Art"
                        Case 440
                            sOp_typ = "Advanced multiaxis X9 and older"
                        Case 441
                            sOp_typ = "Advanced multiaxis-Swarf"
                        Case 442
                            sOp_typ = "Advanced multiaxis-Morph"
                        Case 443
                            sOp_typ = "Advanced multiaxis-Parallel"
                        Case 444
                            sOp_typ = "Advanced multiaxis-Along curve"
                        Case 445
                            sOp_typ = "Advanced multiaxis-Triangular mesh"
                        Case 446
                            sOp_typ = "Advanced multiaxis-Roughing"
                        Case 447
                            sOp_typ = "Advanced multiaxis-Project"
                        Case 448
                            sOp_typ = "Convert to 5-axis"
                        Case 449
                            sOp_typ = "Port Expert"
                        Case 450
                            sOp_typ = "Blade Expert"
                        Case 451
                            sOp_typ = "Rotary advanced"
                        Case 452
                            sOp_typ = "Unknown"
                        Case 458
                            sOp_typ = "Unknown"
                        Case 459
                            sOp_typ = "Deburr"
                        Case 460
                            sOp_typ = "3+2 Automatic roughing"
                        Case 461
                            sOp_typ = "Unknown"
                    End Select

                    sTool_clc = Round(op.CalcCycleTime, 3)
                    Dim x As Long = Int(sTool_clc / 3600) 'hour
                    Dim y As Long = Int(((sTool_clc - x * 3600) / 60)) 'min
                    Dim z As Long = Round((sTool_clc - x * 3600 - y * 60), 2)
                    Dim sTime As String = x.ToString("00") & ":" & y.ToString("00") & ":" & z.ToString("00")
                    'MsgBox(sTool_clc)
                    sTool_min = op.GetMinimumZ.ToString

                    Main.Label1.Text = op.OperationTool.Number
                    Main.Label2.Text = sOp_typ
                    Main.Label3.Text = op.OperationTool.Diameter
                    Main.Label4.Text = op.OperationTool.LengthOffset
                    Main.Label5.Text = op.FeedRate
                    Main.Label6.Text = op.SpindleSpeed
                    Main.Label7.Text = op.ToolPlane.ViewName
                    Main.Label8.Text = op.ToolPlane.WorkOffsetNumber
                    Main.Label9.Text = op.PlungeRate
                    Main.Label10.Text = op.GetMinimumZ
                    Main.Label11.Text = op.GetMaximumZ
                    Main.Label12.Text = sTime
                    Main.Label13.Text = op.OperationTool.CornerRadius
                    Main.Label14.Text = sTool_typ
                    Main.Show()
                    Main.TopMost = True

                Next
                'Main.Hide()
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try

            Return True
        End Function
    End Class
End Namespace

 

Link to comment
Share on other sites
3 hours ago, Lee1 said:

Below has NetHooks  get selection operation parameter shown MainView, but only get one operation, if selection other operation show error and the parameter not update, I don't know where is error

Hi, 

I created an example to help you -> https://github.com/xx4g/VbDisplayOperationDataAddIn

Here we are programatically creating a gui, and changing the data in the labels for each selected operation found and notifying the user so the information is visible until the user presses okay and proceeds to the operation. Note the use of ToString() to do conversion before adding the information to a textbox.

    ''' <summary> This method is designed to be the main entry point for your NetHook app. This is where your app should do
    '''           all of the things it's supposed to do and then return an MCamReturn value representing the outcome of
    '''           your
    '''            NetHook application. </summary>
    '''
    ''' <param name="param"> Parameter is not used. </param>
    '''
    ''' <returns> A <c>MCamReturn</c> return type. </returns>
    Public Overrides Function Run(param As Integer) As MCamReturn

#Region "Initialize Form Object"
        '' Init a new instance of windows.forms
        Dim VbForm = New System.Windows.Forms.Form()
#End Region

#Region "Set Form Paramaters"
        ''Set the window to start at the center of the screen
        VbForm.StartPosition = FormStartPosition.CenterScreen
        ''Make the window Always on Top
        VbForm.TopMost = True
        ''Set The Text of the window
        VbForm.Text = "Operation Params Display"
        '' Set the window height
        VbForm.Height = 750

        VbForm.Width = 750

        VbForm.BackColor = System.Drawing.Color.Black

        VbForm.ForeColor = System.Drawing.Color.Green
#End Region

#Region "Initialize Label Object(s)"
        Dim Label1 = New System.Windows.Forms.Label()
        Dim Label2 = New System.Windows.Forms.Label()
        Dim Label3 = New System.Windows.Forms.Label()
        Dim Label4 = New System.Windows.Forms.Label()
        Dim Label5 = New System.Windows.Forms.Label()
        Dim Label6 = New System.Windows.Forms.Label()
        Dim Label7 = New System.Windows.Forms.Label()
        Dim Label8 = New System.Windows.Forms.Label()
        Dim Label9 = New System.Windows.Forms.Label()
        Dim Label10 = New System.Windows.Forms.Label()
        Dim Label11 = New System.Windows.Forms.Label()
        Dim Label12 = New System.Windows.Forms.Label()
        Dim Label13 = New System.Windows.Forms.Label()
        Dim Label14 = New System.Windows.Forms.Label()
#End Region

#Region "Set Label1 Paramaters"
        ''Set the window to start 10 units the left form
        Label1.Left = 110
        ''Set the window to start 10 units the left form
        Label1.Top = 0
        ''Set The Text of the Label as empty
        Label1.Text = ""
        ''set the size
        Label1.Size = New System.Drawing.Size(200, 25)
#End Region

#Region "Set Label2 Paramaters"
        ''Set the window to start 10 units the left form
        Label2.Left = 110
        ''Set the window to start 10 units the left form
        Label2.Top = 25
        ''Set The Text of the Label as empty
        Label2.Text = ""
        ''set the size
        Label2.Size = New System.Drawing.Size(200, 25)
#End Region

#Region "Set Label3 Paramaters"
        ''Set the window to start 10 units the left form
        Label3.Left = 110
        ''Set the window to start 10 units the left form
        Label3.Top = 50
        ''Set The Text of the Label as empty
        Label3.Text = ""
        ''set the size
        Label3.Size = New System.Drawing.Size(200, 25)
#End Region

#Region "Set Label4 Paramaters"
        ''Set the window to start 10 units the left form
        Label4.Left = 110
        ''Set the window to start 10 units the left form
        Label4.Top = 75
        ''Set The Text of the Label as empty
        Label4.Text = ""
        ''set the size
        Label4.Size = New System.Drawing.Size(200, 25)
#End Region

#Region "Set Label5 Paramaters"
        ''Set the window to start 10 units the left form
        Label5.Left = 110
        ''Set the window to start 10 units the left form
        Label5.Top = 100
        ''Set The Text of the Label as empty
        Label5.Text = ""
        ''set the size
        Label5.Size = New System.Drawing.Size(200, 25)
#End Region

#Region "Set Label6 Paramaters"
        ''Set the window to start 10 units the left form
        Label6.Left = 110
        ''Set the window to start 10 units the left form
        Label6.Top = 125
        ''Set The Text of the Label as empty
        Label6.Text = ""
        ''set the size
        Label6.Size = New System.Drawing.Size(200, 25)
#End Region

#Region "Set Label7 Paramaters"
        ''Set the window to start 10 units the left form
        Label7.Left = 110
        ''Set the window to start 10 units the left form
        Label7.Top = 150
        ''Set The Text of the Label as empty
        Label7.Text = ""
        ''set the size
        Label7.Size = New System.Drawing.Size(200, 25)
#End Region

#Region "Set Label8 Paramaters"
        ''Set the window to start 10 units the left form
        Label8.Left = 110
        ''Set the window to start 10 units the left form
        Label8.Top = 175
        ''Set The Text of the Label as empty
        Label8.Text = ""
        ''set the size
        Label8.Size = New System.Drawing.Size(200, 25)
#End Region

#Region "Set Label9 Paramaters"
        ''Set the window to start 10 units the left form
        Label9.Left = 110
        ''Set the window to start 10 units the left form
        Label9.Top = 200
        ''Set The Text of the Label as empty
        Label9.Text = ""
        ''set the size
        Label9.Size = New System.Drawing.Size(200, 25)
#End Region

#Region "Set Label10 Paramaters"
        ''Set the window to start 10 units the left form
        Label10.Left = 110
        ''Set the window to start 10 units the left form
        Label10.Top = 225
        ''Set The Text of the Label as empty
        Label10.Text = ""
        ''set the size
        Label10.Size = New System.Drawing.Size(200, 25)
#End Region

#Region "Set Label11 Paramaters"
        ''Set the window to start 10 units the left form
        Label11.Left = 110
        ''Set the window to start 10 units the left form
        Label11.Top = 250
        ''Set The Text of the Label as empty
        Label11.Text = ""
        ''set the size
        Label11.Size = New System.Drawing.Size(200, 25)
#End Region

#Region "Set Label12 Paramaters"
        ''Set the window to start 10 units the left form
        Label12.Left = 110
        ''Set the window to start 10 units the left form
        Label12.Top = 275
        ''Set The Text of the Label as empty
        Label12.Text = ""
        ''set the size
        Label12.Size = New System.Drawing.Size(200, 25)
#End Region

#Region "Set Label13 Paramaters"
        ''Set the window to start 10 units the left form
        Label13.Left = 110
        ''Set the window to start 10 units the left form
        Label13.Top = 300
        ''Set The Text of the Label as empty
        Label13.Text = ""
        ''set the size
        Label13.Size = New System.Drawing.Size(200, 25)
#End Region

#Region "Set Label14 Paramaters"
        ''Set the window to start 10 units the left form
        Label14.Left = 110
        ''Set the window to start 10 units the left form
        Label14.Top = 325
        ''Set The Text of the Label as empty
        Label14.Text = ""
        ''set the size
        Label14.Size = New System.Drawing.Size(200, 25)
#End Region

#Region "Add Objects To Form"
        VbForm.Controls.Add(Label1)
        VbForm.Controls.Add(Label2)
        VbForm.Controls.Add(Label3)
        VbForm.Controls.Add(Label4)
        VbForm.Controls.Add(Label5)
        VbForm.Controls.Add(Label6)
        VbForm.Controls.Add(Label7)
        VbForm.Controls.Add(Label8)
        VbForm.Controls.Add(Label9)
        VbForm.Controls.Add(Label9)
        VbForm.Controls.Add(Label10)
        VbForm.Controls.Add(Label11)
        VbForm.Controls.Add(Label12)
        VbForm.Controls.Add(Label13)
        VbForm.Controls.Add(Label14)
#End Region

#Region "Show Form"
        ''Draw the window
        VbForm.Show()
#End Region

#Region "Loop through operations and write the information to the form"
        ''Get the Selected Operations only
        Dim ops = Mastercam.Support.SearchManager.GetOperations(True)
        Dim i As Int32
        i = 1
        Try
            For Each op As Mastercam.Database.Operation In ops
                Label1.Text = "TlNum -> " + op.OperationTool.Number.ToString()
                Label2.Text = "Op Type -> " + op.GetType().ToString()
                Label3.Text = "Dia -> " + op.OperationTool.Diameter.ToString()
                Label4.Text = "Length -> " + op.OperationTool.LengthOffset.ToString()
                Label5.Text = "Feed -> " + op.FeedRate.ToString()
                Label6.Text = "RPM -> " + op.SpindleSpeed.ToString()
                Label7.Text = "Too.Plane -> " + op.ToolPlane.ViewName
                Label8.Text = "WoffNum -> " + op.ToolPlane.WorkOffsetNumber.ToString()
                Label9.Text = "Plunge -> " + op.PlungeRate.ToString()
                Label10.Text = "Minz -> " + op.GetMinimumZ.ToString()
                Label11.Text = "Maxz -> " + op.GetMaximumZ.ToString()
                Label12.Text = "Time -> " + op.CalcCycleTime().ToString()
                Label13.Text = "Corner Rad -> " + op.OperationTool.CornerRadius.ToString()
                Label14.Text = "Tl Type -> " + op.OperationTool.GetType().ToString()
                MessageBox.Show("Operation Number" + i.ToString())
                i = i + 1
            Next
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
#End Region



        Return MCamReturn.NoErrors
    End Function

 

Vb Operations Display App.png

Link to comment
Share on other sites
  • 2 weeks later...

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...