Roger Martin from CNC Software

CNC Software
  • Content count

  • Joined

  • Last visited

Community Reputation

74 Excellent


About Roger Martin from CNC Software

  • Rank
    Advanced Member

Recent Profile Visitors

2,927 profile views
  1. Roger Martin from CNC Software

    Creating a chook operation?

    1> "Create" operations using a C-Hook add-in. (Setting parameters, etc.) -or- 2> Create "custom" C-Hook type operations. Two very different things. #1 is usually fairly simple. #2 is very involved work.
  2. The 'Sharp Corner Smoothing' you see here is the RefFit process and occurs after the Spline is created. And as we know, the Spline ReFit functionality is only available via the UI., a discussed above.
  3. 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. 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"); } }
  4. 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; = P_ID; = 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;
  5. Roger Martin from CNC Software


    Peter, There is not a project template for F#. Since F# is .NET, you can create a NET-Hook Add-In using F# that uses the NET-Hook API.
  6. Roger Martin from CNC Software

    Sdk installation Error

    I waiting to hear back from the installer experts as to what they think may be the issue for you. I would be worth trying to download a new copy of the SDK to install. In the CHM I searched for TP_OPCODE Then down in the list found topics selected -> ToolpathOperationCode_CHh File Reference Scroll down to the Enumerations and you'll find the enum TP_OPCODE information.
  7. Roger Martin from CNC Software

    Sdk installation Error

    That's an install error I've not seen in a long time for the SDK. Are you running Windows 7 or 10 ? Download Link -> CHookSDK CHM [2020].zip
  8. Roger Martin from CNC Software

    How to select stl mesh as drive surface

    Harsh, If you send us your contact/company details and exactly what you're wanting to do to -> SDK <at> mastercam <dot> com We can create a support ticket. Be sure to let us know what version of Mastercam !
  9. Peter, Setting the Solid in the operation is just step #1. There is a lot of processing that occurs when you OK out of the FBM Toolpath - Mill dialog. I have a feeling that accomplishing this detection/processing phase this is not possible via the public SDK. You can send us your contact/company details and exactly what you're wanting to do to -> SDK <at> mastercam <dot> com We can then create a support ticket to investigate further.
  10. Peter, From my communications with the CAD Team, this is a know issue. I'm investigating and will let you know if I find out any more information.
  11. Roger Martin from CNC Software

    VBS to NEThook question

    See - GroupManager.GetAllGroups Method in NET-Hook API Docs -> ''' <summary> The names of all the Machine and Toolpath groups. </summary> ''' <param name="machineGroupNames"> [out] A list of names of all the Machine Groups. </param> ''' <param name="toolpathGroupNames"> [out] A list of names of all the Toolpath Groups. </param> ''' <returns> The total number of groups that were processed. </returns> Private Function GetGroupNames(ByRef machineGroupNames As List(Of String), ByRef toolpathGroupNames As List(Of String)) As Integer machineGroupNames = New List(Of String)() toolpathGroupNames = New List(Of String)() Dim groups = New List(Of Group)() Dim onlyMachineGroups As Boolean = False GroupManager.GetAllGroups(groups, onlyMachineGroups) For Each grp In groups If grp.IsMachineGroup() Then machineGroupNames.Add(grp.Name) ElseIf grp.IsToolpathGroup() Then toolpathGroupNames.Add(grp.Name) End If Next Return machineGroupNames.Count + toolpathGroupNames.Count End Function
  12. Roger Martin from CNC Software

    VBS to NEThook question

    The opcode value it gives you is the same code value as in the C-Hook SDK. In the C-Hook SDK, see in \interfaces\Core\ToolpathOperationCodes_CH.h Search for this enumeration of OpCode values -> enum TP_OPCODE Just like in a C-Hook you don't get a (string) "name" like -> TP_MANUAL_ENTRY These names you mention (like TP_MANUAL_ENTRY) are the names of the items in the enum(eration). You could easily create your own lookup for gettg the "name" from the code number. Note that the NET-Hook API does not support manipulating every toolpath operation type. That may (or may not) affect you after you have loaded those operations. It depends on what you are trying to do. You want to be able to have your add-in run when the user right clicks in Mastercam's Toolpath Manager? Not possible. You can start an add-in via an icon clicked in the UI and/or if it's mapped been to a keystroke.
  13. Roger Martin from CNC Software

    VBS to NEThook question

    A NET-Hook can call/execute a VB Script. The script could then write out this “count” to some known location (file) that the NET-Hook add-in would read The NET-Hook equivalent to obtain this information would be the GetOpGroupDataInExternalFile method. ''' <summary> Gets data from an external Mastercam part file. </summary> ''' ''' <remarks> NOTE! A Mill/Router type Machine Group MUST exist in the ''' *active* file (not the file being interrogated) in order ''' for GetOpGroupDataInExternalFile to return any data. </remarks> ''' ''' <param name="filename"> Full path name of the file to interrogate. </param> ''' ''' <returns> A list of the operation names. </returns> Public Function GetData(ByVal filename As String) As List(Of String) Dim opNames = New List(Of String)() If File.Exists(filename) Then ' These parameter values must be pre-initialized as empty. ' They are filled in by GetOpGroupDataInExternalFile Dim grpData = New Mastercam.Support.Types.ExternalGroupsFileData() {} Dim opData = New Mastercam.Support.Types.ExternalOpsFileData() {} Dim result = SearchManager.GetOpGroupDataInExternalFile(filename, grpData, opData) If result Then For Each op As Mastercam.Support.Types.ExternalOpsFileData In opData ' Note that if the "name" has not been altered by the user, ' the operation has no name assigned to it and will be empty! opNames.Add(op.Name) Next End If End If Return opNames End Function
  14. Please always tell us what version of Mastercam! It appears you’re are wanting to create a Chain “directly” from entities, without using any “select a chains” functionality? If so, look at this code snippet. /// <summary> Construct a Chain from the supplied list of entities. </summary> /// <param name="entities"> The (in order!) line and/or arc entities. </param> /// <returns> The new chain if successful, else null. </returns> CHAIN *CreateChain (std::vector<ent> &entities) { CHAIN *chain; short err = alloc_chain (&chain, FALSE /* partial*/); bool result = (err == 0 && chain != nullptr); if (result) { CHAIN_ENT *last_chain_ent = nullptr; for (auto &entity : entities) { short errCode = add_curve_to_chain (&entity, 0, TRUE, 0, chain, &last_chain_ent); if (errCode != CHAIN_OK) // bail out ! { result = false; break; } } } return (result ? chain : nullptr); }
  15. This is not possible to do "from the outside" using an add-in.

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