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:

Operation Linking


Recommended Posts

            //Surface Finish Contour
            var maximumStepdown = 0.01;
            var contourMinimumDepth = 0;
            var contourMaximumDepth = 0;

            //Surface Finish Pencil
            var depthLimits = true;
            var pencilMinimumDepth = 0;
            var pencilMaximumDepth = 0;

            var selectedOps = SearchManager.GetOperations(true);
            foreach (var op in selectedOps)
            {
                op.Retrieve();
                op.Linking.
                op.Commit();
            }


            GraphicsManager.Repaint(true);
            return MCamReturn.NoErrors;

I've started this code, but I'm not finding a LinkingParams to suit my needs.

Looking to alter the circled boxes

DepthCutsParams also didn't work.

ContourPage.png

PencilPage.png

Link to comment
Share on other sites
12 hours ago, JKLINE said:
            //Surface Finish Contour
            var maximumStepdown = 0.01;
            var contourMinimumDepth = 0;
            var contourMaximumDepth = 0;

            //Surface Finish Pencil
            var depthLimits = true;
            var pencilMinimumDepth = 0;
            var pencilMaximumDepth = 0;

            var selectedOps = SearchManager.GetOperations(true);
            foreach (var op in selectedOps)
            {
                op.Retrieve();
                op.Linking.
                op.Commit();
            }


            GraphicsManager.Repaint(true);
            return MCamReturn.NoErrors;

I've started this code, but I'm not finding a LinkingParams to suit my needs.

Looking to alter the circled boxes

DepthCutsParams also didn't work.

ContourPage.png

PencilPage.png

There is a very short list of Nethook supported operations, contour, pocket,circle mill, drilll, slotmill, that about it

Link to comment
Share on other sites

You make that sound super easy 😅 I think I'm missing a large piece. I just find the parts in the C++ files that I need and copy them to where they go? Do you have a VS Project I can reference?

Solution : ChainDataInterop
  	Namespace : Mastercam
  		Class : NETHookApiReflection
          Public Methods
          		Class : Object
      
  	Namespace : Mastercam.Database.Interop
      	Class : ChainData
        Class : ChainDetails
          	Public Methods
          		 Class : Object

 

 

Untitled.png

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

You make that sound super easy 😅 I think I'm missing a large piece. I just find the parts in the C++ files that I need and copy them to where they go? Do you have a VS Project I can reference?

Solution : ChainDataInterop
  	Namespace : Mastercam
  		Class : NETHookApiReflection
          Public Methods
          		Class : Object
      
  	Namespace : Mastercam.Database.Interop
      	Class : ChainData
        Class : ChainDetails
          	Public Methods
          		 Class : Object

 

 

Untitled.png

Yes, make a copy of the ChainDataInterop project and rename it

Then make it make an operation, I will show you if u want

OR just build using the CLR template from the marketplace

Mastercam C++/CLI New Project Template VS 2022 - Visual Studio Marketplace

  • Thanks 1
Link to comment
Share on other sites

Here is an example of getting the operations..

/// <summary> Retrieves the operations found in the Toolpath Manager of the specified type. </summary>
///
/// <param name="opCode"> (Optional) The operation code to filter on. (TP_NULL for NO Filtering). </param>
///
/// <returns> The list of matching operations found. </returns>
std::vector<operation*> GetOperations(TP_OPCODE opCode = TP_OPCODE::TP_NULL)
{
	std::vector<operation *> ops;
	for (auto index = 0; index < TpMainOpMgr.GetMainOpList().GetSize(); ++index)
	{
		auto op = TpMainOpMgr.GetMainOpList()[index];
		if (op && (opCode == TP_NULL || op->opcode == opCode))
		{
			ops.push_back(op);
		}
	}

	return ops;
}

 

  • Like 1
Link to comment
Share on other sites
55 minutes ago, JKLINE said:

You would post this as a DLL, load it into the resources, and then call on it with opCode?

You need to export a managed function that gets you a list of operation ID's

a std::vector doesn't exist in c#

ref class OperationsManagerInterop abstract sealed
{
public:
/// <summary> Retrieves the operations found in the Toolpath Manager of the specified type. </summary>
///
/// <param name="opCode"> (Optional) The operation code to filter on. (TP_NULL for NO Filtering). </param>
///
/// <returns> The list of matching operations found. </returns>
static System::Collections::Generic::List<int>^ GetOperations(int opCode)
{
     
	auto list = gcnew System::Collections::Generic::List<int>();
	for (auto index = 0; index < TpMainOpMgr.GetMainOpList().GetSize(); ++index)
	{
		auto op = TpMainOpMgr.GetMainOpList()[index];
		if (op && (opCode == TP_NULL || op->opcode == opCode))
		{
			list->Add(op->op_idn);
		}
	}

	return list;
}
};

the in the c# code where you have reference the DLL

var opIDs = OperationsManagerInterop.GetOperations(15);//get only surface finish contour operations

 

Link to comment
Share on other sites
On 12/20/2022 at 12:24 PM, ___ said:

Here is an example of getting the operations..

/// <summary> Retrieves the operations found in the Toolpath Manager of the specified type. </summary>
///
/// <param name="opCode"> (Optional) The operation code to filter on. (TP_NULL for NO Filtering). </param>
///
/// <returns> The list of matching operations found. </returns>
std::vector<operation*> GetOperations(TP_OPCODE opCode = TP_OPCODE::TP_NULL)
{
	std::vector<operation *> ops;
	for (auto index = 0; index < TpMainOpMgr.GetMainOpList().GetSize(); ++index)
	{
		auto op = TpMainOpMgr.GetMainOpList()[index];
		if (op && (opCode == TP_NULL || op->opcode == opCode))
		{
			ops.push_back(op);
		}
	}

	return ops;
}

 

Referencing the ChainDataInterOP source,

this would go into the Main.CPP ?

On 12/20/2022 at 5:03 PM, ___ said:
ref class OperationsManagerInterop abstract sealed
{
public:
/// <summary> Retrieves the operations found in the Toolpath Manager of the specified type. </summary>
///
/// <param name="opCode"> (Optional) The operation code to filter on. (TP_NULL for NO Filtering). </param>
///
/// <returns> The list of matching operations found. </returns>
static System::Collections::Generic::List<int>^ GetOperations(int opCode)
{
     
	auto list = gcnew System::Collections::Generic::List<int>();
	for (auto index = 0; index < TpMainOpMgr.GetMainOpList().GetSize(); ++index)
	{
		auto op = TpMainOpMgr.GetMainOpList()[index];
		if (op && (opCode == TP_NULL || op->opcode == opCode))
		{
			list->Add(op->op_idn);
		}
	}

	return list;
}
};

This would be a header file?

On 12/20/2022 at 5:03 PM, ___ said:
var opIDs = OperationsManagerInterop.GetOperations(15);//get only surface finish contour operations

 

And this would go into my NetHook file?

I'm not sure why this is so difficult for me? 😅

 

https://github.com/UberGamz/SurfaceToolpathInterop

Link to comment
Share on other sites
2 hours ago, JKLINE said:

Referencing the ChainDataInterOP source,

this would go into the Main.CPP ?

This would be a header file?

And this would go into my NetHook file?

I'm not sure why this is so difficult for me? 😅

 

https://github.com/UberGamz/SurfaceToolpathInterop

No, the second block is c# code, you dont need to define the function in a header in c++/cli the managed signature is exported simply by defining the class in main.cpp or another file

The dll will need to be added to the c# project in visual studios by right clicking on dependancies and selecting add reference, then choosing the dll

Link to comment
Share on other sites

It's a Christmas Miracle! Got it to select the pencil and finish contour toolpaths. Thank you so much!

Put this into my NetHook portion ::

            OperationsManager.UnSelectAllOperations();
            var surfaceFinishContourOpID = Mastercam.IO.Interop.SelectionManager.GetOperations(15);
            var surfaceFinishPencilOpID = Mastercam.IO.Interop.SelectionManager.GetOperations(39);
            foreach (var op in surfaceFinishContourOpID)
            {
                var thisOp = SearchManager.GetOperation(op);
                thisOp.SetSelectedState(true);
            }
            OperationsManager.RefreshOperationsManager(true);
            foreach (var op in surfaceFinishPencilOpID)
            {
                var thisOp = SearchManager.GetOperation(op);
                thisOp.SetSelectedState(true);
            }
            OperationsManager.RefreshOperationsManager(true);

            return MCamReturn.NoErrors;

I pasted this into the SelectionMangerExample.h

	static System::Collections::Generic::List<int>^ GetOperations(int opCode)
	{

		auto list = gcnew System::Collections::Generic::List<int>();
		for (auto index = 0; index < TpMainOpMgr.GetMainOpList().GetSize(); ++index)
		{
			auto op = TpMainOpMgr.GetMainOpList()[index];
			if (op && (opCode == TP_NULL || op->opcode == opCode))
			{
				list->Add(op->op_idn);
			}
		}

		return list;
	}

Taking this to the finish line, I've found all the codes I'll need I believe. Just need practice calling them in C++. I feel like i'm sooooo close but soooo far away 🤣😅

	static bool AlterContourFinish(int opCode)
	{
		bool succ = false;

		 /// <summary> operation parameters - surface finish contour. </summary>
		struct prm_srf_fin_contour
		{
			prm_srf_common common;		//!< common parameters for all surface operations
			prm_srf_depths depth;		//!< surface operation's depth settings
		}
		/// <summary> operation parameters - surface operation's depth settings. </summary>
		struct prm_srf_depths
		{
			double min_depth;			 //!< abs: highest cut
			double max_depth;			 //!< abs: lowest cut
		};
		/// <summary> operation parameters - common parameters for all surface operations. </summary>
        struct prm_srf_common
		{
		double max_stepdown;		  //!< maximum stepdown
		};

		if (succ)

		return succ;
	}
	static bool AlterPencilFinish(int opCode)
	{
		bool succ = false;

		/// <summary> operation parameters - surface finish pencil. </summary>
		struct prm_srf_fin_pencil
		{
			prm_srf_limits limit;		//!< surface operation's limit settings
		};
		/// <summary> operation parameters - surface operation's limit settings. </summary>
		struct prm_srf_limits
		{
			bool on;				 //!< T-use cut depth limits
			double z1;				 //!< depth limit 1
			double z2;				 //!< depth limit 2
		};

		if (succ)

			return succ;
	}

 

Link to comment
Share on other sites

Even closer! One problem though 😕 C++ has 'rules' 🤣

"C++ a nonstatic member reference must be relative to a specific object"

 

	static bool AlterContourFinish(long opID, double maxStepdown, double minDepth, double maxDepth)
	{
		//Get
		auto thisOp = TpOpList::OpByID(opID);

		//Set
		thisOp.prm_srf_common::max_stepdown = maxStepdown;
		thisOp.prm_srf_depths::min_depth = minDepth;
		thisOp.prm_srf_depths::max_depth = maxDepth;

		return ;
	}
	static bool AlterPencilFinish(long opID, bool status, double limitOne, double limitTwo)
	{
		//Get
		auto thisOp = TpOpList::OpByID(opID);
		
		//Set
		thisOp.prm_srf_limits::on = status;
		thisOp.prm_srf_limits::z1 = limitOne;
		thisOp.prm_srf_limits::z2 = limitTwo;

		return ;
	}

 

Link to comment
Share on other sites

And I'm officially stuck 😅 The first portion works in Mastercam, but the second portion throws an alarm. 

"Method not found: 'Boolean Mastercam.IO.Interop.SelectionManager.AlterContourFinish(Int32, Double, Double, Double)'."

 

Maybe I put something in the wrong place? Or am calling it incorrectly?

 

	static System::Collections::Generic::List<int>^ GetOperations(int opCode)
	{

		auto list = gcnew System::Collections::Generic::List<int>();
		for (auto index = 0; index < TpMainOpMgr.GetMainOpList().GetSize(); ++index)
		{
			auto op = TpMainOpMgr.GetMainOpList()[index];
			if (op && (opCode == TP_NULL || op->opcode == opCode))
			{
				list->Add(op->op_idn);
			}
		}

		return list;
	};
	static bool SelectionManager::AlterContourFinish(long opID, double maxStepdown, double minDepth, double maxDepth)
	{
		//Get
		prm_srf_common opCommon;
		prm_srf_depths opDepth;
		tp_entity thisToolPath;
		thisToolPath.op_idn = opID;

		//Set
		opCommon.prm_srf_common::max_stepdown = maxStepdown;
		opDepth.prm_srf_depths::min_depth = minDepth;
		opDepth.prm_srf_depths::max_depth = maxDepth;

		return true;
	};
	static bool SelectionManager::AlterPencilFinish(long opID, bool status, double limitOne, double limitTwo)
	{
		//Get
		prm_srf_limits opData;
		tp_entity thisToolPath;
		thisToolPath.op_idn = opID;

		//Set
		opData.prm_srf_limits::on = status;
		opData.prm_srf_limits::z1 = limitOne;
		opData.prm_srf_limits::z2 = limitTwo;

		return true;
	};

 

            OperationsManager.UnSelectAllOperations();
            var surfaceFinishContourOpID = Mastercam.IO.Interop.SelectionManager.GetOperations(15);
            var surfaceFinishPencilOpID = Mastercam.IO.Interop.SelectionManager.GetOperations(39);
            foreach (var op in surfaceFinishContourOpID)
            {
                var thisOp = SearchManager.GetOperation(op);
                thisOp.SetSelectedState(true);
                Mastercam.IO.Interop.SelectionManager.AlterContourFinish(op, 0.2, -0.2, -0.2);
            }
            OperationsManager.RefreshOperationsManager(true);
            foreach (var op in surfaceFinishPencilOpID)
            {
                var thisOp = SearchManager.GetOperation(op);
                thisOp.SetSelectedState(true);
            }
            OperationsManager.RefreshOperationsManager(true);

            return MCamReturn.NoErrors;

https://github.com/UberGamz/SurfaceInterop (CLI)

https://github.com/UberGamz/Rotary-PD---Copy (Nethook)

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

Is the function marked as public?

 

It won't let me mark it 'public' because it says ": expected". Your portion also doesn't say public, is there another way to mark it so?

Everything is inside the public class "public ref class SelectionManager"

3 hours ago, ___ said:

Second question, was the dll copied over correctly?

My code is directly under yours, inside the same file. Since yours works, I'd assume the dll was copied correctly.

Link to comment
Share on other sites

You want to edit the operation union, then use the operation_manager () function with the OPMGR_REWRITE flag

 

 

 

 

 

for (auto index = 0; index < TpMainOpMgr.GetMainOpList().GetSize(); ++index)
{
auto op = TpMainOpMgr.GetMainOpList()[index];
if (op && ( op->opcode == TP_SRF_FIN_CONTOUR
))
{
bool success = false;
DB_LIST_ENT_PTR operationPointer = nullptr;
//set cut method to zig zag
op->u.f_contour.cut_method = (short)0;
operation_manager(op, OPMGR_REWRITE, &operationPointer, &success);
if (success == false)
{
//TO DO : Handle any errors rewriting the operation
}
}
}
 
Link to comment
Share on other sites
1 hour ago, ___ said:

You will need to include the header file and library

 

In your header file or at the top of your source code add these lines

 

#include "m_mill.h"

#pragma comment(lib,"MCMill.lib")

Brilliant! :D  Thank you soooo much!

Solution ::

 

CLI ::

		static bool SelectionManager::AlterContourFinish(double maxStepdown, double minDepth, double maxDepth)
		{

			for (auto index = 0; index < TpMainOpMgr.GetMainOpList().GetSize(); ++index)
			{
				auto op = TpMainOpMgr.GetMainOpList()[index];
				if (op && (op->opcode == TP_SRF_FIN_CONTOUR
					) && op->db.select_flag == true)
				{
					bool success = false;
					DB_LIST_ENT_PTR operationPointer = nullptr;
					//set cut method to zig zag
					op->u.r_contour.common.max_stepdown = maxStepdown;
					op->u.f_contour.depth.max_depth = maxDepth;
					op->u.f_contour.depth.min_depth = minDepth;
					operation_manager(op, OPMGR_REWRITE, &operationPointer, &success);
					if (success == false)
					{
						//TO DO : Handle any errors rewriting the operation
					}
				}
			}
			return true;
		}
		static bool SelectionManager::AlterPencilFinish(bool status, double limitOne, double limitTwo)
		{
			for (auto index = 0; index < TpMainOpMgr.GetMainOpList().GetSize(); ++index)
			{
				auto op = TpMainOpMgr.GetMainOpList()[index];
				if (op && (op->opcode == TP_SRF_FIN_PENCIL
					) && op->db.select_flag == true)
				{
					bool success = false;
					DB_LIST_ENT_PTR operationPointer = nullptr;
					//set cut method to zig zag
					op->u.f_pencil.limit.on = status;
					op->u.f_pencil.limit.z1 = limitOne;
					op->u.f_pencil.limit.z2 = limitTwo;
					operation_manager(op, OPMGR_REWRITE, &operationPointer, &success);
					if (success == false)
					{
						//TO DO : Handle any errors rewriting the operation
					}
				}
			}
			return true;
		};

NetHook ::

            var contourList = new List<int>();
            var pencilList = new List<int>();
            var selectedOps = SearchManager.GetOperations(true);
            var surfaceFinishContourOpID = Mastercam.IO.Interop.SelectionManager.GetOperations(15);
            var surfaceFinishPencilOpID = Mastercam.IO.Interop.SelectionManager.GetOperations(39);
            foreach (var op in surfaceFinishContourOpID)
            {
                foreach (var thisOp in selectedOps)
                {
                    var selectedOp = thisOp.GetOperationID();
                    if (selectedOp == op)
                    {
                        contourList.Add(selectedOp);
                    }
                }
            }
            foreach (var op in surfaceFinishPencilOpID)
            {
                foreach (var thisOp in selectedOps)
                {
                    var selectedOp = thisOp.GetOperationID();
                    if (selectedOp == op)
                    {
                        pencilList.Add(selectedOp);
                    }
                }
            }
            foreach (var op in contourList)
            {
                Mastercam.IO.Interop.SelectionManager.AlterContourFinish(0.2, -0.2, -0.2);
                var thisOp = SearchManager.GetOperation(op);
                thisOp.MarkDirty();
                thisOp.Commit(false);
            }
            OperationsManager.RefreshOperationsManager(true);
            foreach (var op in pencilList)
            {
                Mastercam.IO.Interop.SelectionManager.AlterPencilFinish(true, -0.020, 0.00);
                var thisOp = SearchManager.GetOperation(op);
                thisOp.MarkDirty();
                thisOp.Commit(false);
            }
            OperationsManager.RefreshOperationsManager(true);

            return MCamReturn.NoErrors;

 

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