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:

Roger Martin from CNC Software

CNC Software
  • Posts

    2,870
  • Joined

  • Last visited

  • Days Won

    6

Posts posted by Roger Martin from CNC Software

  1. 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");
                }
            }

     

    • Like 1
  2. 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
  3. 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.

     

    • Like 1
  4. 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.

     

  5. See -

    GroupManager.GetAllGroups Method in NET-Hook API Docs ->
    https://nethookdocs.mastercam.com/content/html/4267c9cf-5183-137f-c8dc-bad2fcdc3aed.htm

     

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

     

    • Thanks 1
  6. 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.

    Quote

    It must be used in Toolpath Manager with right-click every time. I want to set the shortcut to enter, but I have not found a way.

    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.

    • Thanks 1
  7. 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


     

    • Thanks 1
  8. 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);
    	}

     

  9. 3 hours ago, piaofcu said:

    If the toolpath is created in incremental mode (contour), then will get  "linking.DepthIncremental"  - True

    Is there any way to calculate the ABS value? (incremental to absolute)

    The value you get from a specific property in the LinkingParams of an operation,
    is just the "value". It is not an incremental/absolute value, it's just a "value"
    The true/false setting of the DepthIncremental (in the case of Depth) tells the system how to "look at" the (Depth) value.
    If "linking.DepthIncremental"  = True
    Then it is incremental "from somewhere else", such as Top Of Stock.
    Experiment with a simple 2D-Contour path, changing just the DepthIncremental and see what the Depth value is in each case.

  10. Sounds like the Entity Attributes Manager.
    Open the Attributes Manager and check the active settings.
    You don’t say which version of Mastercam you’re using, so how that’s done can differ.

    You can also get to those setting in Mastercam Configuration.
    Configuration – CAD (page). 
    In the lower-right of this page are 'Entity Attribute Manager' settings.
     

  11. The version of Visual Studio used to build a NET-Hook doesn’t really matter. It's the "Target Framework" setting in the project that you're working with that can matter for .NET
    *This is not true for C-Hooks, which must be built using the exact same version (C++ compiler toolset in a specific version of VS) that was used to build the version of Mastercam it is to run in.
    Of course you’ll need to set the Reference to the proper NET-Hook API DLL that is in X6.
    You can try using VS-2017 this for X6 HET-Hook add-in. It may or may not help. 
    But probably not because… If I recall correctly there was an issue in VB.NET itself back then.
    If you build your NET-Hook using C#, it will probably work in X6.
    This is a good VB to C# converter - http://converter.telerik.com/

  12. 3 hours ago, SlaveCam said:

    post-process using command line

    Not exactly sure what you're asking, but I do know the answer is -> No.

    Mastercam needs to be running.

    Of course you can start Mastercam via a command line or "batch" type file.  You can supply several options on the Command-Line that's supplied to the Mastercam.exe itself. Such the path\name of a .mcam file to be opened and the name of a C-Hook/NET-Hook add-in to be run after the file has been loaded.

    "C:\Program Files\Mcam2019\Mastercam.exe" "C:\Users\user1\Documents\my mcam2019\Parts\ToolTest.mcam"  sortcircles.dll

    The add-in could .. 

    Select All operations and then Post Process those operations.

    The add-in can also shut-down Mastercam when it's done.

    *If the Multi-Threading is enabled and some of those operations do get processed by that, this "shut down when done" can get a bit more complicated.

    If the add-in is a C-Hook it could disable Multi-Threading before commanding the Post Processing action.

    • Thanks 1

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