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:

Exist any samples of programing the mastercam SDK in C++


Recommended Posts

I'm triing to deploy one c-hook in c++ that loads a lot of points, then generate one spline and before the machining control the distances from several points to the spline.

If on the code I write:

create_point_ent(point3d,*pointer,*ok);

I have one error from the linker 
Error    LNK2019    símbolo externo "__declspec(dllimport) void __cdecl create_point_ent(class p_3d &,struct ent *,bool *)" (__imp_?create_point_ent@@YAXAEAVp_3d@@PEAUent@@PEA_N@Z) sin resolver al que se hace referencia en la función SampleEntry    CHookWizard2    C:\Users\llvilalta\Documents\Visual Studio 2015\Projects\CHookWizard2\CHookWizard2\main.obj 

 

I hope that with some samples I can understand how need to work with mastercam SDK  

Link to comment
Share on other sites
1 hour ago, eProject4 said:

I'm triing to deploy one c-hook in c++ that loads a lot of points, then generate one spline and before the machining control the distances from several points to the spline.

If on the code I write:

create_point_ent(point3d,*pointer,*ok);

I have one error from the linker 
Error    LNK2019    símbolo externo "__declspec(dllimport) void __cdecl create_point_ent(class p_3d &,struct ent *,bool *)" (__imp_?create_point_ent@@YAXAEAVp_3d@@PEAUent@@PEA_N@Z) sin resolver al que se hace referencia en la función SampleEntry    CHookWizard2    C:\Users\llvilalta\Documents\Visual Studio 2015\Projects\CHookWizard2\CHookWizard2\main.obj 

 

I hope that with some samples I can understand how need to work with mastercam SDK  

As Jeff said you most likely did not link the necessary library needed for your function. If you go to the menu under Project --> Properties --> Linker --> Input --> Additional Dependancies , you will see the names of several .lib files (static libraries). Usually I add all the files located in the release folder of the mastercam sdk which is located (on my computer anyway) in c:\mcam\program files (x86)\mcam\x64\release. 

Link to comment
Share on other sites

Hi, 

Thanks Jeff and Peter, it's my first time with the mastercam SDK and I was thinking that the base project has all linked...

Now I have a new problem, now the lib is well linked but when try to create the point I have the error

Excepción producida en 0x0000000003066A6A (MCCore.dll) en Mastercam.exe: 0xC0000005: Infracción de acceso al escribir en la ubicación 0x0000000000000000.

Is possible that i need do some more before, but I don't know the structure of the mastercam data.

 

Is very helpful for my if some body can send me one sample, about how to draw one point in mastercam with cHooks, for instance draw for points at some fixed positions and then draw one spline witht this points.

 

Best regards in advance.

Link to comment
Share on other sites

First, always tell what version of Mastercam your add-in is for.

I see no "create_point_ent" function in the SDK. 
So, where is this function you’re trying to call located?

If you have a list of "p_3d" objects, there is this function that will create a Spline through them.

The make_spline_from_pts function ->
Requires:
SDK\interfaces\CurveSurfGeom\Spline4_CH.h
and the MCCurveSurfGeom.lib

/// <summary> Create a Spline entity with the supplied Points. </summary>
///
/// <param name ="node_pts">  The points to create the spline through. </param>
/// <param name ="num_pts">   The number of points in the list pointed to by node_pts. </param>
/// <param name ="color">     (Optional) The color of the new spline. </param>
/// <param name ="level">     (Optional) The level to place the new spline. </param>
///
/// <returns> The database pointer to the new Spline entity. (NULL if failed) </returns>
DB_LIST_ENT_PTR CreateSpline(p_3d *node_pts, int num_pts, MC_BYTE color = main_color, int level = main_level)
 {
	if ((node_pts == NULL) || (num_pts < 2)) { return nullptr; } // sanity check
	bool succf = false;
	DB_LIST_ENT_PTR d_ptr;	
	 p_3d v_z_3d;
	make_spline_from_pts(node_pts, num_pts, color, level,
				0, v_z_3d, 0, v_z_3d, false, &d_ptr, &succf);
	return succf ? d_ptr : nullptr;
 }

/// <summary> Creates a point entity in the database. </summary>
///
/// <param name="pt">         The point coordinates. </param>
/// <param name="color">      (optional) The color of the point.  </param>
/// <param name="level">      (optional) The level to place the point on.  </param>
/// <param name="attributes"> (optional) The attributes to use when creating the point.. </param>
///
/// <returns> The database pointer to the new point entity. (NULL if failed) </returns>
DB_LIST_ENT_PTR CreatePoint (p_3d pt, MC_BYTE color = main_color, int level = main_level, attributes = main_attribs)
	{
	bool succf = false;
	DB_LIST_ENT_PTR db_ptr = nullptr;
	ent entity;
	entity.id = P_ID;
	entity.u.pt = pt;
	store_ent (&entity, &db_ptr, ALIVE_BIT, color, level, attribs, &succf);
	return (succf) ? db_ptr : nullptr;
	}

Note that these functions return the database pointer to the Entity.
If you wish to retrieve the actual Entity, you can do this ->
ent pointEnt;
bool gotEnt = get_ent_from_eptr (pointDbPtr, &pointEnt) == 0;

  • Like 1
Link to comment
Share on other sites

Thanks for your replly Roger,

I'm working with the mastercam2018

Now I'm able to daw the points and the spline.

Now I need to use some functions of mastercam (buttons on the GUI) but don't know how use it from the software, for instance need use the refitspline on the created spline and then analize distances from several points to the spline refited.

There are any information about the relation of mastercam buttons with the c++ SDK?

Are this functions possible with the library nethooks in c#?

Link to comment
Share on other sites

You can use the ft file to let mastercam know about your Chook. From there a button can be added to your quick access toolbar to run your chook.

 

You can import and export functions from c++ (chook language) to c# or VB.net (NETHOOK language) by creating a wrapper for your functions with a c++/cli project.

Link to comment
Share on other sites

In your project there is a file with a .ft extension. You need to rename it to the name of your project. You also need to rename some of the values Inside. Then copy it into the chook folder in mastercam.

Link to comment
Share on other sites

Sorry Peter, i don't explain well my question.

I know how can do manually on mastercam the thinks that i want to do, but don't know the name of these functions on the SDK or how to find it.

I know the steps to do in mastercam manually and need to automate this steps, but don't know the functions that do this steps.

Link to comment
Share on other sites
Quote

There are any information about the relation of mastercam buttons with the c++ SDK?

You can run can run (virtually) any Mastercam UI command from a (C-Hook or NET-Hook) add-in using…
The post_FT_Command function from a C-Hook add-in. (ref: ft_ch.h)
post_FT_command (_T("Mastercam"), _T("RefitSpline"));
Or
The PostFTCommand method available in the NET-Hook API.
Mastercam.Support.ExternalAppsManager.PostFTCommand("RefitSpline");
These act just as if the user clicked that command in Mastercam’s User Interface.
*This does NOT bypass the user interface that will be displayed if that command requires user input.
Not all commands can be automated from an add-in that bypasses the UI.
And ReFitSpline is one that requires the (Function Panel) UI to be displayed to the user.

Quote

Are this functions possible with the library nethooks in c#?

Yes, here is some sample code.

The support class for creating the geometry.

namespace RunSplineReFitCommand
{
    using Mastercam.BasicGeometry;
    using Mastercam.Curves;
    using Mastercam.Math;
    using Mastercam.Support;
    using System.Collections.Generic;

    public class GeometryCreator
    {
        public PointGeometry CreatePoint(double x, double y, double z)
        {            
            UndoManager.StartTransaction(); // optional
            var point = new PointGeometry(x, y, z);
            var result = point.Commit();
            if (result)
            {
                UndoManager.CommitTransaction(); // optional
                return point;
            }
            else
            {
                UndoManager.CancelTransaction(); // optional
                return null;
            }           
        }

        // This first CreateSpline method takes an list of Point3D objects.
        // If you have PointGeometry objects you can extract the 'Data' data member from the
        // PointGeometry which is a Point3D that contains the X,Y,Z coordinates of the point.
        // See the overload of CreateSpline further below.
        public SplineGeometry CreateSpline(List<Point3D> points)
        {            
            UndoManager.StartTransaction(); // optional
            var spline = new SplineGeometry(points.ToArray());
            var result = spline.Commit();
            if (result)
            {
                UndoManager.CommitTransaction(); // optional
                return spline;
            }
            else
            {
                UndoManager.CancelTransaction(); // optional
                return null;
            }            
        }

        public SplineGeometry CreateSpline(List<PointGeometry> points)
        {
            var ptData = new List<Point3D>();
            foreach (var pt in points)
            {
                ptData.Add(pt.Data);
            }
            return CreateSpline(ptData);
        }
    }
}

Using the above code and calling ReFitSpline...

        private void RunDemo()
        {
            var creator = new GeometryCreator();
            var points = new List<PointGeometry>();                     
            points.Add(creator.CreatePoint(0, 0, 0));
            points.Add(creator.CreatePoint(0.5, 0, 0));
            points.Add(creator.CreatePoint(0.5, 0.5, 0));
            points.Add(creator.CreatePoint(0.4, 1.0, 0));
            points.Add(creator.CreatePoint(0.4, 0.75, 0));
                        
            var spline = creator.CreateSpline(points);
            if (spline != null)
            {
                // Optional - PreSelect the Spline for the ReFit command.
                spline.Selected = true;
                spline.Commit();
                Mastercam.Support.ExternalAppsManager.PostFTCommand("RefitSpline");
            }
        }

 

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

Hi Roger,

Thanks for your reply, this is what I need.

But if I undertand well, I can't pass the parameters to the RefitSpline to automate it.

Now I'm doing some tests with NET-Hooks with the function CreateParametricSplineFromChain, but here I can't give to the function all options that are on the UI Curves Spline, there are any system to add the information for the option "Sharp corner smoothing" and the values for "Detection Angle" and "Blend distance", or another option is if I can configure the mastercam to have these values for default.

I need to fix these values to have the spline that i need.

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