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:

MASTERCAM API'S (net-hooks using vb.net)


Recommended Posts

Hi, I am  a student

Sorry if its a silly thing to ask!I am very new to mastercam API'S. I have learnt fundamentals of vb.net and want to work with mastercam API'S  for my project. I followed the PDF instructions(Mastercam.net API's Developing vb.net add-ins for mastercam) which links mastecam interface to vb.

I viewed through (mastercam vb.net examples files ) for example codes but unable to understand much.

 

I am trying to create "points and lines" but unable to do so.

I tried to mimic the code from example files but it didn't show anything on mastercam when I debugged the program.

The attachments which I included with this post are the ones which I mimicked from the examples files

Can anyone help me with  the problem

Thanks in advance

Screenshot (74).png

Screenshot (75).png

Link to comment
Share on other sites

On our website are sample NET-Hook projects:

https://www.mastercam.com/en-us/Communities/3rd-Party-Developers/NET-Hook-Downloads

You appear to be missing the main "Run" function that Mastercam calls when you run your Add-In. From within the "Run", you call your methods.

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

    Me.Point1()

    Return Mastercam.App.Types.MCamReturn.NoErrors

End Function

 

Link to comment
Share on other sites

Rogin Martin and Mick George, thanks a lot for replying to my query.

I added that "run function" which calls the "point1() and point2()" subs. When I ran the program it opened mastercam but nothing appeared in it

I added break points  to understand the code but it popped up a message.

5abd250f75e02_Screenshot(85).thumb.png.fdb2683219d576dcdb9eeaefc504f07a.png

I am attaching the  screenshots(which I took while the program was running) . I have also attached my vb.net project(masternethook.rar).

Can you guys tell me where I went wrong this time?

 

 

 

Screenshot (83).png

Screenshot (84).png

Screenshot (86).png

masternethook.rar

Link to comment
Share on other sites

Your NET-Hook works for me. It created the two points.

Be sure the you are running the proper DLL (masternethook.dll) that this project created?

In your “The breakpoint will not currently be hit” screen shot, Visual Studio is referring to -> OPERATIONSMANAGEREXMAPLE.DLL

That’s not the name of the DLL that the “masternethook“ project you sent creates.

I loaded your “masternethook“ project in Visual Studio.

Start Debugging (F5) and Mastercam 2018 starts up.

Selected the “Run Add-In” command and navigated to the bin\Debug folder of the “masternethook“ project and selected the just built masternethook.dll.

The result is two points added to the Mastercam database and shown on-screen.

 

 

 

Link to comment
Share on other sites

That SplineGeometry constructor wants an array of Point3D objects.

See the online NET-Hook API docs here ->

https://nethookdocs.mastercam.com

Dim pt1 As New Point3D(10, 0, 0)
Dim pt2 As New Point3D(10, 10, 10)
Dim pt3 As New Point3D(25, 30, 35)

' Need an Array of Point3D objects             
Dim points() As Point3D
points = New Point3D() {pt1, pt2, pt3}
           
Dim spline As New SplineGeometry(points)            
spline.Commit()            

 

Edited by Roger Martin from CNC Software
Link to comment
Share on other sites

"Declaration expected" ?
What is the exact pop-up message?

The code below works for me. It creates the Spline and displays a message box -> "spline has 3 points"
(Visual Studio 2015 or 2017 and .NET Framework 4 or higher.)

Public Class MyHook : Inherits NetHook3App

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

        Dim spline = CreateSpline()
        MessageBox.Show(String.Format("spline has {0} points", spline.NodePoints.Length))
        Return MCamReturn.NoErrors

    End Function

    Private Function CreateSpline As SplineGeometry

    Dim pt1 As New Point3D(10, 0, 0)
        Dim pt2 As New Point3D(10, 10, 10)
        Dim pt3 As New Point3D(25, 30, 35)
        Dim points() As Point3D = {pt1, pt2, pt3}   

        ' The "New Spline" in the parameter here is not needed.
        ' You can do it this way, it's just an unnecessary additional construction.
        'Dim spline As New SplineGeometry(New Spline(points))

        ' You can pass the points directly to the SplineGeometry constructor.
        Dim spline As New SplineGeometry(points)
        Dim result = spline.Commit()
        Return spline

        End Function

End Class


 

Link to comment
Share on other sites

Thanks sir, The  spline geometry worked

Sir, Iam unable to  understand that MC view on "mirror method  using MC views and line 3D" . I have written

(1): Line to be mirrored

(2): Axis on which the line is mirrored

(3): New mirrored line which is  the first line coordinates and return the new  mirrored line 

(4): Call the function to the main run program

 

The code shows no error but, its not displaying the mirrored line5acdb14b02854_Screenshot(178).thumb.png.fe8154f8d8c95161a900bf2752016315.png

 

 

Screenshot (177).png

Link to comment
Share on other sites

Please post your code, not "pictures" of your code.

Also, which version of Mastercam are you using?

This creates a mirrored line with endpoints of -10,0,0 and -10,10,0

  Public Overrides Function Run(ByVal param As Integer) As MCamReturn            
      Dim result = MirrorLine()
      MessageBox.Show(String.Format("Line has been mirrored -> {0}", result))
      Return MCamReturn.NoErrors
  End Function

  Private Function MirrorLine() As Boolean
      Dim originalLine = New LineGeometry(New Point3D(10, 0, 0), New Point3D(10, 10, 0))
      Dim axisLine = New Line3D(New Point3D(0, 0, 0), New Point3D(0, 25, 0))        
      Dim view = ViewManager.CPlane
      Return originalLine.Mirror(axisLine, view)
  End Function

 

Edited by Roger Martin from CNC Software
Link to comment
Share on other sites

Translation of a point or line

Sir  I've been trying to translate a point using the following code


 

 

Here's my code:

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

   Dim newpoint=translatepoint()

    Return MCamReturn.NoErrors

 

 

Private function  translatepoint() as boolean

Dim firstpoint=New pointgeometry(newpoint3D(0,0,0))

Dim transpoint=New point3D(15,25,30))

Dim Fromview as MC view

Dim Toview as MC view

return transpoint.translate(firstpoint,transpoint,fromview:=,Toview:=)

 

 

I don't  know what variable to assign to the arguments in return statement

Does MC view  ask for machine coordinates?

Link to comment
Share on other sites

Sir If I have to give chaining and toolpath geometry for a component using mastercam APIs how should I proceed.  Can you give me some guidance on this.

I have attached a .mcam file of a component which I want to machine using mastercam APIs. The part is made in 'CATIA' and is imported into mastercam via ".stp" format.

 

Thanks in Advance

 

part x2.mcam

Link to comment
Share on other sites

Translating geometry, see below.

As for "here is a part file, tell me how to do this..."

You'll need to email us with our data and your company ID -> [email protected]

Public Class MyHook : Inherits NetHook3App

  Public Overrides Function Run(ByVal param As Integer) As MCamReturn
      Dim result = TranslatePoint()
      Dim arc = TranslateArc()
      
      ViewManager.GraphicsView = SearchManager.GetSystemView(SystemPlaneType.Iso)      
      GraphicsManager.FitScreen()        
      Return MCamReturn.NoErrors
  End Function

  Private Function TranslatePoint() As Boolean
      Dim myPoint As New PointGeometry(1, 2, 0)
      Dim fromPoint As New Point3D(0, 0, 0)
      Dim toPoint As New Point3D(15, 25, 30)
      Dim fromView = ViewManager.CPlane
      Dim toView = SearchManager.GetSystemView(SystemPlaneType.Front)

      ' Translates (moves) the Geometry object
      Dim result = myPoint.Translate(fromPoint, toPoint, fromView, toView)
      Return result
  End Function

  Private Function TranslateArc() As ArcGeometry
      ' Create an arc at the origin in the current Construction Plane
      Dim myArc As New ArcGeometry(ViewManager.CPlane, New Point3D(0, 0, 0), 5, 0, 180)
      myArc.Commit()

      Dim fromPoint As New Point3D(0, 0, 0)
      Dim toPoint As New Point3D(15, 25, 30)
      Dim fromView = ViewManager.CPlane
      Dim toView = SearchManager.GetSystemView(SystemPlaneType.Front)

      ' A copy the original eobject (myArc), then translate it.
      ' The new translated object is returned
      Dim newArc = myArc.CopyAndTranslate(fromPoint, toPoint, fromView, toView)
      Return newArc
  End Function

End Class

 

Link to comment
Share on other sites

Sir, thanks a lot for your reply on my query on 'translating geometry'

Sir, I am having troubles while calling files from mastercam 

I created dynamic 'button' and an ' open file dialog ' to allow me to open files within mastercam

Here's my code

 

#Creating buttons and openfile dialog#

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
Partial Class MainView
    Inherits System.Windows.Forms.Form

    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()>
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub
    Private components As System.ComponentModel.IContainer
    <System.Diagnostics.DebuggerStepThrough()>
    Private Sub InitializeComponent()
        Me.OKButton = New System.Windows.Forms.Button()
        Me.openfilebutton = New System.Windows.Forms.Button()
        Me.openfiledialog = New System.Windows.Forms.OpenFileDialog

        Me.SuspendLayout()
        '
        'OKButton
        '
        Me.OKButton.Anchor = System.Windows.Forms.AnchorStyles.Right
        Me.OKButton.Location = New System.Drawing.Point(449, 300)
        Me.OKButton.Name = "OKButton"
        Me.OKButton.Size = New System.Drawing.Size(111, 48)
        Me.OKButton.TabIndex = 14
        Me.OKButton.Text = "OK"
        Me.OKButton.UseVisualStyleBackColor = True
        '
        'openfilebutton
        '
        Me.openfilebutton.Anchor = System.Windows.Forms.AnchorStyles.Top
        Me.openfilebutton.Location = New System.Drawing.Point(100, 155)
        Me.openfilebutton.Name = "openfilebutton"
        Me.openfilebutton.Size = New System.Drawing.Size(120, 50)
        Me.openfilebutton.TabIndex = 13
        Me.openfilebutton.Text = "Open"


        '
        'MainView
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(9.0!, 20.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(669, 377)
        Me.Controls.Add(Me.OKButton)
        Me.Controls.Add(Me.openfilebutton)

        Me.Margin = New System.Windows.Forms.Padding(4, 5, 4, 5)
        Me.Name = "MainView"
        Me.Text = "MainView"
        Me.ResumeLayout(False)

    End Sub
    Private WithEvents OKButton As System.Windows.Forms.Button
    Private WithEvents openfilebutton As System.Windows.Forms.Button
    Private WithEvents openfiledialog As System.Windows.Forms.OpenFileDialog

 

 

# For opening dialog box using open file button I created#

 Private Sub OKButton_Click(sender As Object, e As EventArgs) Handles OKButton.Click
        Me.Close()
    End Sub

    Private Sub Openfilebutton_Click(sender As Object, e As EventArgs) Handles openfilebutton.Click
        If openfiledialog.ShowDialog() = DialogResult.OK Then
            openfiledialog.FileName = ""

        End If

#Main run function#

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

  Using view = New MainView()
            view.ShowDialog()
        End Using
        Return MCamReturn.NoErrors

 

When I run the add-in,  'Main form appears without the buttons', Can you help me with this

Thankyou

 

Link to comment
Share on other sites

This question is basic .NET which we really don't do. 
We're here to help you using Mastercam functionality in a Mastercam Add-In.
I created a simple VB.NET Windows Form Application, then I inserted your MainView.Designer.vb code.
The result worked for me. I get a somewhat large Form with (2) buttons.
Click on the 'Open' button and the File Open Dialog opens.
Click on the 'OK' button and the Form closes.

If you are just setting up the user interface for a NET-Hook add-in and
you are not really using any Mastercam “specific” functionality yet.
You can save time by building your project as a std. “Window Form Application”.
Then you don’t need to startup Mastercam, just to run your project to test your UI.
Once you get your UI setup like you want, just switch the Application Type over to “Class Library”,
and add a Reference to the NETHook3_0.DLL and have a class with the “Run” function in your project ->

Imports Mastercam.App
Imports Mastercam.App.Types

Public Class NethookMain
    Inherits NetHook3App
    Public Overrides Function Run(ByVal param As Integer) As MCamReturn

        Using view = New MainView()
            view.ShowDialog()
        End Using

        Return MCamReturn.NoErrors

    End Function
End Class

Now you have a NET-Hook add-in (DLL) and can continue on to implementing the items that rely on Mastercam functionality.

WindowsAppVB.zip

Link to comment
Share on other sites

Sir,  Thanks a lot  for helping me with the UI earlier.

Sir, I am having trouble with generating a bounding box .I know  the syntax is asking for an array, but  don't know what to assign for "Geometry to bound " as geometry()

Can I  get some help with this?

thanks in advance

 


  

ORIGINAL SYNTAX:

Public Shared Function RectangularBoundingBox ( 
	CommonData As BoundingBoxCommonParams,
	RectangularData As BoundingBoxRectangularParams,
	GeometryToBound As Geometry()
) As Geometry()


MY SYNTAX
 Public Shared Function RectangularBoundingBox() As Geometry()
        Dim solid As BoundingBoxCommonParams
        solid.CreateSolid = True
        Dim rectangle As BoundingBoxRectangularParams
        rectangle.ExpandXMinus = 20
        rectangle.ExpandXPlus = 10
        rectangle.ExpandYMinus = 50
        rectangle.ExpandYPlus = 30
        rectangle.ExpandZMinus = 0
        rectangle.ExpandZPlus = 40


        Dim geometrytobound As Geometry()
        geometrytobound



        Return


    End Function

 

 

 

Link to comment
Share on other sites
 Private Sub Isometric_Click(sender As Object, e As EventArgs) Handles Isometric.Click


        Dim view As GraphicsViewType = GraphicsViewType.Iso

    End Sub

Sir , I am facing troubles  with enumerations. I am trying to call  enums from "graphicviewtype" enumerations but nothing worked. 

Is something wrong with my code?. 

Can you please help?

Thanks  in advance

 

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