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:

C++/Cli Operations : Delete and Replace Method


Recommended Posts

Hi,

These are my latest operations exported to .Net, they contain the Delete and Replace method to deal with unwanted associated entities

typedef struct MastercamChookSdk
{
	typedef struct OperationsManager
	{

		///////////////////////////////////////////////////////////////////////////////
		//
		// GetOperationList
		//
		//define the functions parammeters
		typedef struct GetOperationListParams
		{

			TP_OPCODE opCode = TP_OPCODE::TP_NULL;

		};
		// define the functions
		typedef std::vector<operation*>(*GetOperationsList)(GetOperationListParams);

		typedef struct GetOperationListFunctions
		{
			GetOperationsList getoperationslist;

			std::vector<operation*> getoperationslistresult;

		};
		//
		// GetPointsToOperation
		//
				//define the functions parammeters
		typedef struct GetPointsInOperationParams
		{
			operation *op;

			std::vector<ent_tp> drillPointTPEnts;
		};
		// define the functions
		typedef std::vector<ent_tp>(*GetPointsInOperation)(GetPointsInOperationParams);

		typedef struct GetPointsInOperationFunctions
		{
			GetPointsInOperation getpointsinoperation;

			std::vector<ent_tp> getpointsinoperationresult;

		};

		//
		// AddPointsToOperation
		//
		//define the functions parammeters
		typedef struct AddPointsToOperationParams
		{
			operation *op;
			std::vector<ent> points;

		};
		// define the functions
		typedef int(*AddPointsToOperation)(AddPointsToOperationParams);

		typedef struct AddPointsToOperationFunctions
		{
			AddPointsToOperation addpointstooperation;

			int addpointstooperationresult;

		};
		//
	// GetChainsInOperation
	//
			//define the functions parammeters
		typedef struct GetChainsInOperationParams
		{

			long opID;
		};
		// define the functions
		typedef CHAIN*(*GetChainsInOperation)(GetChainsInOperationParams);

		typedef struct GetChainsInOperationFunctions
		{
			GetChainsInOperation getchainsinoperation;

			CHAIN* getchainsinoperationresult;

		};
		//
// AddChainsToOperation
//
		//define the functions parammeters
		typedef struct AddChainsToOperationParams
		{

			long opID = 0;

			CHAIN* chain;
		};
		// define the functions
		typedef bool(*AddChainsToOperation)(AddChainsToOperationParams);

		typedef struct AddChainsToOperationFunctions
		{
			AddChainsToOperation addchainstooperation;

			bool addchainstooperationresult;

		};
		// CloneChainBasedOperations
//
		//define the functions parammeters
		typedef struct  CloneChainBasedOperationsParams
		{
			long op_id = 0;

			TP_OPCODE opCode = TP_OPCODE::TP_NULL;
		};
		// define the functions
		typedef operation*(*CloneChainBasedOperations)(CloneChainBasedOperationsParams);

		typedef struct  CloneChainBasedOperationsFunctions
		{
			CloneChainBasedOperations  clonechainbasedoperations;

			operation* clonechainbasedoperationsresult;

		};
		// CloneChainBasedOperations
//
		//define the functions parammeters
		typedef struct CloneDrillingOperationsParams
		{
			long op_id = 0;

			TP_OPCODE opCode = TP_OPCODE::TP_NULL;
		};
		// define the functions
		typedef operation*(*CloneDrillingOperations)(CloneDrillingOperationsParams);

		typedef struct CloneDrillingOperationsFunctions
		{
			CloneDrillingOperations clonedrillingoperations;

			operation* clonedrillingoperationsresult;

		};
	};

};

std::vector<operation*> GetOperationsList(MastercamChookSdk::OperationsManager::GetOperationListParams params);

MastercamChookSdk::OperationsManager::GetOperationListFunctions InitGetOperationsListFunctions();

std::vector<ent_tp> GetPointsInOperation(MastercamChookSdk::OperationsManager::GetPointsInOperationParams params);

MastercamChookSdk::OperationsManager::GetPointsInOperationFunctions InitGetPointsInOperationFunctions();

int AddPointsToOperation(MastercamChookSdk::OperationsManager::AddPointsToOperationParams params);

MastercamChookSdk::OperationsManager::AddPointsToOperationFunctions InitAddPointsToOperationFunctions();

MastercamChookSdk::OperationsManager::CloneDrillingOperationsFunctions InitCloneDrillingOperationsFunctions();

operation* CloneDrillingOperations(MastercamChookSdk::OperationsManager::CloneDrillingOperationsParams cdparams);

CHAIN * GetChainsInOperation(MastercamChookSdk::OperationsManager::GetChainsInOperationParams params);

MastercamChookSdk::OperationsManager::GetChainsInOperationFunctions InitGetChainsInOperationFunctions();

bool AddChainsToOperation(MastercamChookSdk::OperationsManager::AddChainsToOperationParams params);

MastercamChookSdk::OperationsManager::AddChainsToOperationFunctions InitAddChainsToOperationFunctions();

operation* CloneChainBasedOperations(MastercamChookSdk::OperationsManager::CloneChainBasedOperationsParams cbparams);

MastercamChookSdk::OperationsManager::CloneChainBasedOperationsFunctions InitCloneChainBasedOperationsFunctions();

/// <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*> GetOperationsList(MastercamChookSdk::OperationsManager::GetOperationListParams params)
// (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 && (params.opCode == TP_NULL || op->opcode == params.opCode))
		{
			ops.push_back(op);
		}
	}

	return ops;
}
MastercamChookSdk::OperationsManager::GetOperationListFunctions InitGetOperationsListFunctions()
{
	MastercamChookSdk::OperationsManager::GetOperationListFunctions functions;
	functions.getoperationslist = GetOperationsList;
	return functions;
}
std::vector<ent_tp> GetPointsInOperation(MastercamChookSdk::OperationsManager::GetPointsInOperationParams params)
{
	std::vector<ent_tp> drillPointTPEnts;
	drillPointTPEnts.clear(); // out





	// Starting in Mastercam 2018 you use 'GetAllTpEntities' instead of 'tp_get_all'.

	// It returns a vector of 'ent_tp' items which is simple to iterate through

	// and does not require using FREE to clean up.

	ent opEnt;

	auto tpEnts = GetAllTpEntities(params.op->op_idn, opEnt);

	for (const auto &tpEnt : tpEnts)

	{

		if (tpEnt.u.tp.tp_id == TP_PT_PT || tpEnt.u.tp.tp_id == TP_PT_SOLID)// || tpEnt.u.tp.tp_id == TP_ARC_SOLID || tpEnt.u.tp.tp_id == TP_PT_CIRC_MILL)

		{

			ASSERT(tpEnt.u.tp.op_idn == op->op_idn);

			drillPointTPEnts.push_back(tpEnt);

		}

	}



	return drillPointTPEnts;

}

MastercamChookSdk::OperationsManager::GetPointsInOperationFunctions InitGetPointsInOperationFunctions()
{
	MastercamChookSdk::OperationsManager::GetPointsInOperationFunctions functions;
	functions.getpointsinoperation = GetPointsInOperation;
	return functions;
}
MastercamChookSdk::OperationsManager::AddPointsToOperationFunctions InitAddPointsToOperationFunctions()
{
	MastercamChookSdk::OperationsManager::AddPointsToOperationFunctions functions;
	functions.addpointstooperation = AddPointsToOperation;
	return functions;
}

int AddPointsToOperation(MastercamChookSdk::OperationsManager::AddPointsToOperationParams params)
{



#define IDS_POINT_NAME 13

	if (params.points.empty())

	{

		return 0;

	}



	bool succf = false;

	int ptsAdded = 0;



	// Retrieve the operation 'entity' for this operation.

	ent opEnt;

	if (TpMainOpMgr.GetMainOpList().DatabaseRetrieve(params.op->op_idn, opEnt))

	{

		int index = 0;

		for (const auto &entity : params.points)

		{

			if (entity.id == P_ID || entity.id == A_ID)

			{

				// Create a point type toolpath entity.

				auto pointCode = (entity.id == P_ID) ? PEC_POINT : PEC_CENTER;

				auto pt = (entity.id == A_ID) ? entity.u.pt : entity.u.ar.c;

				double tval[2] = { 0 };

				ent tpEnt;

				init_tp_ent(&entity, P_ID, TP_PT_PT, pointCode, pt, tval, params.op, &tpEnt);

				//tpEnt.u.tp.u.pt.z_depth = entity.u.pt[ZCOORD];



				// We can give the drill point a "name".

				CString name;

				name.LoadString(IDS_POINT_NAME);

				name.Format(_T("Arc %i (\u2300%1.4f)"), ++index, entity.u.ar.r * 2);

				_tcsncpy_s(tpEnt.u.tp.u.pt.name, name, _TRUNCATE);



				// Update the optr data in the toolpath entity to point to this operation!

				tpEnt.u.tp.optr = opEnt.eptr;

				DB_LIST_ENT_PTR dbPtr = nullptr;

				bool ok = false;

				store_ent_assoc(&tpEnt, &dbPtr, TP_ID, &ok);

				if (ok)

				{

					ptsAdded++;

				}

			}

		}



		// Adjust for the number of points we added to the operation.

		opEnt.u.op.db.ent_count += ptsAdded;

		opEnt.u.op.db.disp_count += ptsAdded;



		if (ptsAdded > 0)

		{

			// Update the "associated" ents in the operation.

			rewrite_ent_assoc(&opEnt, true);



			// Update the caller's operation pointer with the data we've updated.

			if (TpMainOpMgr.GetMainOpList().DatabaseRetrieve(params.op->op_idn, opEnt))

			{

				*params.op = opEnt.u.op;

				succf = true;

			}

			else

			{

				succf = false;

			}

		}



#ifdef DEBUG // See the toolpath entities after we've updated the operation.

#if C_H_VERSION >= 2000 // Mastercam 2018 or later.

		// In Mastercam 2018 you can use 'GetAllTpEntities' instead of 'tp_get_all'.

		// It returns a vector of 'ent_tp' items which is simple to iterate through

		// and does not require using FREE to clean up.

		auto tpEnts = GetAllTpEntities(op->op_idn, opEnt);

		bool debugStop = true; // Set a breakpoint here to see what was retrieved.

#else

		ent_tp *tp_ents = nullptr;

		long n_tp_ents = 0;

		bool ok = false;

		tp_get_all(op->op_idn, &opEnt, &tp_ents, &n_tp_ents, &ok);

		bool debugStop = true; // Set a breakpoint here to see what was retrieved.

		free(tp_ents); // MUST free what tp_get_all retrieved for us!

#endif

#endif

	}



	return ptsAdded;

}
operation* CloneDrillingOperations(MastercamChookSdk::OperationsManager::CloneDrillingOperationsParams cdparams)
{
	operation op;
	int ptCount = 0;
	auto succf = false;
	DB_LIST_ENT_PTR dbPtr = nullptr;

	// Find the Drill toolpath operations.
	MastercamChookSdk::OperationsManager::GetOperationListFunctions functions;
	MastercamChookSdk::OperationsManager::GetOperationListParams params;
	functions = InitGetOperationsListFunctions();
	params.opCode = cdparams.opCode;
	auto operationlist = functions.getoperationslist(params);
	auto count = 0;
	for (auto drillop : operationlist)
	{
		if (drillop && (cdparams.opCode == drillop->opcode || cdparams.opCode == TP_OPCODE::TP_NULL))
		{
			if (drillop && (cdparams.op_id == drillop->op_idn || cdparams.op_id == 0))
			{
				//CString str;
				//str.Format(_T("op#  : %d"), ptCount);
				//count++;
				//MessageBox(NULL, str,
				//	TEXT("Message"), 3);
				auto validoperation = true;

				prm_drill prm_drill;

				prm_circmill prm_circmill;

				if (drillop->opcode == TP_DRILL)
				{
					prm_drill = drillop->u.prm_drl;
				}
				else if (drillop->opcode == TP_CIRCMILL)
				{
					prm_circmill = drillop->u.circmill;
				}
				else
				{
					validoperation = false;
				}
				if (validoperation)
				{
					auto WCS = drillop->WCS;

					auto tpln = drillop->tpln;

					auto cpln = drillop->cpln;

					auto tewl = drillop->tl;

					auto cmn = drillop->cmn;


					auto dcuts = drillop->dcuts;

					auto mcuts = drillop->mcuts;

					auto lead = drillop->lead;

					auto prm_drl = drillop->u.prm_drl;

					std::vector<ent_tp> drillPointTPEnts;
					std::vector<ent> drillPointEnts;
					// GetPointsInOperationFunctions functions;
					MastercamChookSdk::OperationsManager::GetPointsInOperationFunctions functions2;
					MastercamChookSdk::OperationsManager::GetPointsInOperationParams params2;
					functions2 = InitGetPointsInOperationFunctions();
					params2.op = drillop;
					params2.drillPointTPEnts = functions2.getpointsinoperation(params2);
					///params2.opCode = TP_DRILL;
					if (!params2.drillPointTPEnts.empty())
					{
						// Go through the Drill Points of this operation and
						// replicate the geometry used by those points to a new level.
						for (auto point : params2.drillPointTPEnts)
						{
							ent entity;
							if (get_ent_from_eptr(point.u.tp.eptr, &entity) == 0)
							{

								auto ent = entity;
								short sel = ALIVE_BIT;
								MC_BYTE color = MC_RED;
								int level = point.u.tp.eptr->eptr->level;
								store_ent(&ent, &ent.eptr, sel, color, level, main_attrib, &succf);//nothing happens?this must not be the ptr
								if (succf)
								{
									drillPointEnts.push_back(ent);
								}
							}
						}


						// We are replicating the original operation we're going delete later.
						// We get its OpCode and the Tool that it's using.										

						ZeroMemory(&op, sizeof(operation));
						op.opcode = drillop->opcode;
						operation_manager(&op, OPMGR_INIT_ADD, &dbPtr, &succf);
						auto boolfind = false;
						auto boolassign = false;
						if (succf)
						{

							//Mastercam::IO::EventManager::LogEvent(Mastercam::IO::Types::MessageSeverityType::InformationalMessage, boolfind.ToString(), boolassign.ToString());
							// Create new Drill Points for the new operation.
							// ToolPath Entities CANNOT be shared between operations.
							// We must create new ones for this new operation.
							MastercamChookSdk::OperationsManager::AddPointsToOperationParams params3;
							MastercamChookSdk::OperationsManager::AddPointsToOperationFunctions functions3;
							functions3 = InitAddPointsToOperationFunctions();
							params3.op = &op;
							params3.points = drillPointEnts;
							ptCount = functions3.addpointstooperation(params3);

							op.WCS = WCS;

							op.tpln = tpln;

							op.cpln = cpln;

							op.tl = tewl;

							op.tl.feed = tewl.feed;

							op.cmn = cmn;
							if (drillop->opcode == TP_DRILL)
							{
								op.u.prm_drl = prm_drill;
							}
							else if (drillop->opcode == TP_CIRCMILL)
							{
								op.u.circmill = prm_circmill;

								op.dcuts = dcuts;

								op.mcuts = mcuts;

								op.lead = lead;

								op.lead.on = true;

								op.u.circmill.hs_entry_on = true;

								op.u.circmill.hs_trans_angle = 90.0;

								op.u.circmill.start_at_center = true;

								op.u.circmill.start_angle = 90.0;
							}
							else
							{
								//unreachable
							}

							if (ptCount > 0)
							{

								operation_manager(&op, OPMGR_REWRITE, &dbPtr, &succf);
								// Regenerate the new operation.
								operation_manager(&op, OPMGR_NCI_REGEN, &dbPtr, &succf);
							}

							// Delete the old operation.
							operation_manager(drillop, OPMGR_DELETE, &dbPtr, &succf);
						}
						//System::Windows::Forms::MessageBox::Show("boolassign is : " + boolassign.ToString());
						//System::Windows::Forms::MessageBox::Show("boolfind is : " + boolfind.ToString());

					}
					else
					{
						//auto txt = " f";

					}

				}
			}
		}
	}
	return &op;
}
MastercamChookSdk::OperationsManager::CloneDrillingOperationsFunctions InitCloneDrillingOperationsFunctions()
{
	MastercamChookSdk::OperationsManager::CloneDrillingOperationsFunctions functions;

	functions.clonedrillingoperations = CloneDrillingOperations;

	return functions;
}
/// <summary> Gets the chains in an operation. </summary>
///
/// <param name="opID"> Identifier for the operation. </param>
///
/// <returns> Null if it fails, else the chains referenced by the operation. </returns>
CHAIN *GetChainsInOperation(MastercamChookSdk::OperationsManager::GetChainsInOperationParams params)
{
	bool succf = false;
	chain_manager_info ChainManagerInfo;
	ChainManagerInfo.mode = CHNMGR_GET;
	ChainManagerInfo.op_idn = params.opID;
	chain_manager(&ChainManagerInfo, 0, &succf);
	return (succf) ? ChainManagerInfo.chns : nullptr;
}
MastercamChookSdk::OperationsManager::GetChainsInOperationFunctions InitGetChainsInOperationFunctions()
{
	MastercamChookSdk::OperationsManager::GetChainsInOperationFunctions functions;
	functions.getchainsinoperation = GetChainsInOperation;
	return functions;
}
/// <summary> Gets the chains in an operation. </summary>
///
/// <param name="opID"> Identifier for the operation. </param>
///
/// <returns> Null if it fails, else the chains referenced by the operation. </returns>
bool AddChainsToOperation(MastercamChookSdk::OperationsManager::AddChainsToOperationParams params)
{
	bool succf = false;
	chain_manager_info ChainManagerInfo;
	ChainManagerInfo.mode = CHNMGR_ADD;
	ChainManagerInfo.op_idn = params.opID;
	ChainManagerInfo.chns = params.chain;

	chain_manager(&ChainManagerInfo, 0, &succf);
	return succf;
}
MastercamChookSdk::OperationsManager::AddChainsToOperationFunctions InitAddChainsToOperationFunctions()
{
	MastercamChookSdk::OperationsManager::AddChainsToOperationFunctions functions;
	functions.addchainstooperation = AddChainsToOperation;
	return functions;
}

operation* CloneChainBasedOperations(MastercamChookSdk::OperationsManager::CloneChainBasedOperationsParams cbparams)
{
	auto succf = false;
	DB_LIST_ENT_PTR dbPtr = nullptr;
	operation op;
	// Find the Drill toolpath operations.
	MastercamChookSdk::OperationsManager::GetOperationListFunctions functions;
	MastercamChookSdk::OperationsManager::GetOperationListParams params;
	functions = InitGetOperationsListFunctions();
	params.opCode = cbparams.opCode;
	auto operationlist = functions.getoperationslist(params);
	auto count = 0;
	for (auto currentop : operationlist)
	{
		if (currentop && (cbparams.opCode == currentop->opcode || cbparams.opCode == TP_OPCODE::TP_NULL))
		{
			if (currentop && (cbparams.op_id == currentop->op_idn || cbparams.op_id == 0))
			{
				auto validoperation = true;

				prm_contour prm_cntr;

				prm_pocket prm_pkt;

				if (currentop->opcode == TP_CONTOUR)
				{
					prm_cntr = currentop->u.prm_cntr;
				}
				else if (currentop->opcode == TP_POCKET)
				{
					prm_pkt = currentop->u.prm_pkt;
				}
				else
				{
					validoperation = false;
				}
				//CString str;
				//str.Format(_T("op#  : %d"), ptCount);
				//count++;
				//MessageBox(NULL, str,
				//	TEXT("Message"), 3);
				if (validoperation)
				{

					auto WCS = currentop->WCS;

					auto tpln = currentop->tpln;

					auto cpln = currentop->cpln;

					auto tewl = currentop->tl;

					auto cmn = currentop->cmn;

					auto dcuts = currentop->dcuts;

					auto mcuts = currentop->mcuts;

					auto lead = currentop->lead;

					// GetPointsInOperationFunctions functions;
					MastercamChookSdk::OperationsManager::GetChainsInOperationFunctions functions2;
					MastercamChookSdk::OperationsManager::GetChainsInOperationParams params2;
					functions2 = InitGetChainsInOperationFunctions();
					params2.opID = currentop->op_idn;
					functions2.getchainsinoperationresult = functions2.getchainsinoperation(params2);
					///params2.opCode = TP_DRILL;
					if (functions2.getchainsinoperationresult != nullptr)
					{

						// We are replicating the original operation we're going delete later.
						// We get its OpCode and the Tool that it's using.										

						ZeroMemory(&op, sizeof(operation));
						op.opcode = currentop->opcode;
						operation_manager(&op, OPMGR_INIT_ADD, &dbPtr, &succf);
						auto boolfind = false;
						auto boolassign = false;
						if (succf)
						{

							//Mastercam::IO::EventManager::LogEvent(Mastercam::IO::Types::MessageSeverityType::InformationalMessage, boolfind.ToString(), boolassign.ToString());
							// Create new Drill Points for the new operation.
							// ToolPath Entities CANNOT be shared between operations.
							// We must create new ones for this new operation.
							MastercamChookSdk::OperationsManager::AddChainsToOperationParams params3;
							MastercamChookSdk::OperationsManager::AddChainsToOperationFunctions functions3;

							functions3 = InitAddChainsToOperationFunctions();

							params3.chain = functions2.getchainsinoperationresult;

							params3.opID = op.op_idn;

							functions3.addchainstooperationresult = functions3.addchainstooperation(params3);

							op.WCS = WCS;

							op.tpln = tpln;

							op.cpln = cpln;

							op.dcuts = dcuts;

							op.mcuts = mcuts;

							op.lead = lead;

							op.tl = tewl;

							op.cmn = cmn;

							if (currentop->opcode == TP_CONTOUR)
							{
								op.u.prm_cntr = prm_cntr;
							}
							else if (currentop->opcode == TP_POCKET)
							{
								op.u.prm_pkt = prm_pkt;
							}
							else
							{
								//unreachable
								return false;
							}


							operation_manager(&op, OPMGR_REWRITE, &dbPtr, &succf);


							if (functions3.addchainstooperationresult)
							{
								// Regenerate the new operation.
								operation_manager(&op, OPMGR_NCI_REGEN, &dbPtr, &succf);

							}
							// Delete the old operation.
							operation_manager(currentop, OPMGR_DELETE, &dbPtr, &succf);
						}
					}
				}
			}
		}
	}

	return &op;
}
MastercamChookSdk::OperationsManager::CloneChainBasedOperationsFunctions InitCloneChainBasedOperationsFunctions()
{
	MastercamChookSdk::OperationsManager::CloneChainBasedOperationsFunctions functions;
	functions.clonechainbasedoperations = CloneChainBasedOperations;
	return functions;
}


namespace ChookSdkLibrary
{
	// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ChangeAttributes ">
//   Copyright (c) 2020 PeterRussellEvans, Inc.
// </copyright>
// <summary>
//   NET-Hook
// </summary>
	namespace OperationManagerUtilities
	{
		/// <summary> A make contour operation from chains parameters package. </summary>
		public ref struct MakeCircleMillOpFromGeometryParams
		{
			int level;
			double clearancePlane;
			double feedPlane;
			double topOfStock;
			double depth;
			int viewId;
			int FeedRate;
			int spindlespeed;
			int slot;
			int num_fcuts = 0;
			double stock_to_leave_on_wall = 0.0;
			double size_fcuts = 0.0;
		};
		public ref struct MakeContourOpFromChainsParams
		{
			int level;
			double clearancePlane;
			double feedPlane;
			double topOfStock;
			double depth;
			int viewId;
			Mastercam::Operations::Types::ContourSubtypeType cntrtpe;
			Mastercam::Database::Types::CutterCompDir cuttercompdir;
			Mastercam::Database::Types::ChainDirectionType chndir;
			double FeedRate;
			int spindlespeed;
			bool tabison;
			int slot;
			bool osciateison;
			int num_fcuts = 0;
			double stock_to_leave_on_wall = 0.0;
			double size_fcuts = 0.0;
			bool leadinoutison = false;
			double line_length_pct = 0.0;
			bool doleadin;
			double minz;
		};

		/// <summary> A make pocket operation from chains parameters package. </summary>
		public ref struct MakePocketOpFromChainsParams
		{
			int level;
			double clearancePlane;
			double feedPlane;
			double topOfStock;
			double depth;
			int viewId;
			Mastercam::Database::Types::CutterCompDir cuttercompdir;
			Mastercam::Database::Types::ChainDirectionType chndir;
			double FeedRate;
			int spindlespeed;
			int slot;
			int num_fcuts = 0;
			double stock_to_leave_on_wall = 0.0;
			double size_fcuts = 0.0;
			bool leadinoutison = false;
			double line_length_pct = 0.0;
		};

		/// <summary> A make drill operation from geometry parameters package. </summary>
		public ref struct MakeDrillOpFromGeometryParams
		{
			double clearancePlane;
			double feedPlane;
			double topOfStock;
			double depth;
			int viewId;
			double FeedRate;
			int spindlespeed;
			int slot;
			int targetlevel;
		};
		public ref class CreateOperations abstract sealed
		{
		public:

#pragma once

		


			
			//create an endmill
			static int ChookSdkLibrary::OperationManagerUtilities::CreateOperations::makendmil(int tlnum, double flutelen, double shldrlen, double shldrdia,
				double tooldia, double feedrate, int rpm, System::String ^Name, double tipangle);

			//create a contour operation
			static int ChookSdkLibrary::OperationManagerUtilities::CreateOperations::MakeContourOpFromChains(const MakeContourOpFromChainsParams ^params);
			////int level, double clearancePlane, double feedPlane, double topOfStock, double depth, int viewId,
			////Mastercam::Operations::Types::ContourSubtypeType cntrtpe, Mastercam::Database::Types::CutterCompDir cuttercompdir,
			////Mastercam::Database::Types::ChainDirectionType chndir, int FeedRate, int spindlespeed, bool tabison, int slot, bool osciateison,
			////int num_fcuts, double stock_to_leave_on_wall, double size_fcuts, bool leadinoutison, double line_length_pct

			//create a pocket operation
			static int ChookSdkLibrary::OperationManagerUtilities::CreateOperations::MakePocketOpFromChains(const MakePocketOpFromChainsParams ^params);
			////int level, double clearancePlane, double feedPlane, double topOfStock, double depth, int viewId,
			////Mastercam::Database::Types::CutterCompDir cuttercompdir,
			////Mastercam::Database::Types::ChainDirectionType chndir, int FeedRate, int spindlespeed, int slot

			//create a drilling operation
			static int ChookSdkLibrary::OperationManagerUtilities::CreateOperations::MakeDrillOpFromGeometry(const MakeDrillOpFromGeometryParams ^params);
			////double clearancePlane, double feedPlane, double topOfStock,
			////double depth, int viewId, int FeedRate, int spindlespeed, int slot, int targetlevel
			static int ChookSdkLibrary::OperationManagerUtilities::CreateOperations::MakeCircleMillOpFromGeometry(const MakeCircleMillOpFromGeometryParams ^params);

		};
	};
}
int ChookSdkLibrary::OperationManagerUtilities::CreateOperations::makendmil(int tlnum, double flutelen, double shldrlen, double shldrdia, double tooldia, double feedrate, int rpm, System::String ^ Name, double tipangle)
{
	Mastercam::Tools::EndMillFlatTool tool;
	tool.Diameter = tooldia;
	tool.Feed = feedrate;
	tool.Length = 2.0;
	tool.FluteLength = flutelen;
	tool.Flutes = 4;
	tool.MfgToolCode = _T("Code : Tcode");
	tool.TipAngle = tipangle;
	tool.Feed = feedrate;
	tool.PlungeFeed = 50.0;
	tool.DiameterOffset = tlnum;
	tool.LengthOffset = tlnum;
	tool.Number = tlnum;
	tool.Name = Name;
	tool.SpindleRotation = 0;
	tool.RadiusType = Mastercam::Database::Types::ToolRadiusType::None;
	tool.RPM = rpm;
	tool.RetractFeed = 500.0;
	tool.ShoulderDia = shldrdia;
	tool.ShankDia = tooldia;
	tool.ShoulderLength = shldrlen;
	tool.IsMetric = false;
	tool.Coolant = Mastercam::Database::Types::CoolantMode::COOL_OFF;
	return tool.Commit() ? tool.Slot : 0;
}


int ChookSdkLibrary::OperationManagerUtilities::CreateOperations::MakeContourOpFromChains(const ChookSdkLibrary::OperationManagerUtilities::MakeContourOpFromChainsParams ^params)

//int level, double clearancePlane, double feedPlane, double topOfStock, double depth, int viewId,
//Mastercam::Operations::Types::ContourSubtypeType cntrtpe, Mastercam::Database::Types::CutterCompDir cuttercompdir,
//Mastercam::Database::Types::ChainDirectionType chndir, int FeedRate, int spindlespeed, bool tabison, int slot, bool osciateison,
//int num_fcuts, double stock_to_leave_on_wall, double size_fcuts, bool leadinoutison, double line_length_pct)//, EndMillFlatTool ^ tool)
{

	auto views = Mastercam::Support::SearchManager::GetViews();

	Mastercam::IO::ViewManager::GraphicsView = views[params->viewId];

	Mastercam::IO::ViewManager::CPlane = views[params->viewId];

	Mastercam::IO::ViewManager::TPlane = views[params->viewId];
	Mastercam::Database::ChainManager::ChainTolerance = .001;
	const auto chains = Mastercam::Database::ChainManager::ChainAll(false, false, nullptr, params->chndir, params->level);

	//check that we have something///////////////////////////////////////////////////////////////////////////////////////////////////
	double stock_to_leave_on_floor = 0.0;

	//System::Windows::Forms::MessageBox::Show("chk");
	if (chains != nullptr && chains->Length != 0)
	{
		auto cntrop = gcnew Mastercam::Operations::ContourOperation;

		cntrop->AssignMillToolBySlot(params->slot);

		cntrop->CutterComp.Direction = params->cuttercompdir;

		cntrop->CutterComp.RollCorners = Mastercam::Database::Types::CutterCompRoll::CutterCompRollAll;

		cntrop->OperationTool->SpindleRotation = 0;

		//linking params
		cntrop->Linking->FeedPlane = params->feedPlane;

		cntrop->DepthCuts.Enabled = true;

		cntrop->DepthCuts.CutOrderByDepth = true;

		cntrop->DepthCuts.FinishNumberCuts = params->num_fcuts;

		cntrop->DepthCuts.FinishStep = params->size_fcuts;

		cntrop->DepthCuts.MaxRoughStep = .755;

		cntrop->DepthCuts.TaperedWalls = false;

		cntrop->DepthCuts.UseSubprogram = false;

		cntrop->Linking->Depth = params->depth;

		cntrop->Linking->ClearanceOn = true;

		cntrop->Linking->Clearance = params->clearancePlane;

		cntrop->Linking->Retract = params->clearancePlane;

		cntrop->Linking->RetractOn = true;

		cntrop->Linking->TopStock = params->topOfStock;

		//		cntrop->UpdateToolSettings();

		cntrop->MiscValues->UseValuesFromPost = true;

		cntrop->MultiPass.Enabled = false;
		if (params->doleadin)
		{
			cntrop->LeadInOut.Enabled = true;
			cntrop->LeadInOut.GougeCheck = true;
			cntrop->LeadInOut.EnterAtMidPt = true;
			cntrop->LeadInOut.Entry.Enabled = true;
			cntrop->LeadInOut.Entry.ArcRadius = .05;
			cntrop->LeadInOut.Entry.ArcSweep = 90.0;
			cntrop->LeadInOut.Entry.LineLength = params->minz + .125;
			cntrop->LeadInOut.Entry.RampHeight = params->minz + .125;
			cntrop->LeadInOut.Entry.OneDepth = false;
			cntrop->LeadInOut.Entry.Feedrate = params->FeedRate;
			cntrop->LeadInOut.Entry.HelixHeight = 0.0;
			cntrop->LeadInOut.Entry.Perpendicular = true;
			cntrop->LeadInOut.Exit.Enabled = false;
			cntrop->LeadInOut.ContourStart.Enabled = false;
			cntrop->LeadInOut.ContourEnd.Enabled = false;
			cntrop->Entry.EnterFirstOrExitLastOnly = false;
			cntrop->LeadInOut.OverLap = 0;
			cntrop->LeadInOut.Enabled = true;
			cntrop->LeadInOut.GougeCheck = true;
			cntrop->LeadInOut.ContourStart.Enabled = false;
			cntrop->LeadInOut.ContourEnd.Enabled = false;

			cntrop->Entry.Enabled = true;
			cntrop->Entry.UseFeedOverride = false;
			cntrop->Entry.EnterFirstOrExitLastOnly = false;
			cntrop->Entry.Perpendicular = true;
			cntrop->Entry.UsePoint = false;
			cntrop->Entry.UsePointDepth = false;
			cntrop->Exit.Enabled = true;
			cntrop->Exit.UseFeedOverride = false;
			cntrop->Exit.EnterFirstOrExitLastOnly = false;
			cntrop->Exit.Perpendicular = true;
			cntrop->Exit.UsePoint = false;
			cntrop->Exit.UsePointDepth = false;
		}
		if (params->tabison)
		{
			cntrop->Tabs.AutomaticPosition = true;

			cntrop->Tabs.TabAll = true;

			cntrop->Tabs.Enabled = true;

			cntrop->Tabs.AutoTabByDistance = false;

			cntrop->Tabs.NumberOfTabs = 4;

			cntrop->Tabs.EntryExitMode = Mastercam::Operations::Types::TabEntryExitType::Arc;

			cntrop->Tabs.TabThickness = 0.04;

			cntrop->Tabs.TabWidth = 0.3;

			cntrop->Tabs.RampAngle = 45.0;
		}

		if (!params->tabison)
		{
			cntrop->Tabs.Enabled = false;
		}
		auto osclinkdepth = 0.0;
		if (params->viewId == 0)
		{
			osclinkdepth = 0.0;
		}
		if (params->viewId == 3)
		{
			osclinkdepth = params->minz;
		}
		if (params->osciateison)
		{
			if (params->minz <= .25)
			{
				cntrop->Linking->Depth = osclinkdepth;
				cntrop->Oscillate.MaximumDepth = 0.035 - params->minz;
			}

			if (params->minz <= .755 && params->minz > .25)
			{
				cntrop->Linking->Depth = osclinkdepth - .05;
				cntrop->Oscillate.MaximumDepth = 0.085 - params->minz;
			}

			if (params->minz > .755)
			{
				cntrop->Linking->Depth = osclinkdepth - .25;
				cntrop->Oscillate.MaximumDepth = -.5;
			}

			cntrop->Oscillate.OscillationDistance = 4.0;
			cntrop->Oscillate.MovementType = Mastercam::Operations::Types::OscillationMovementType::Highspeed;
		}

		cntrop->ForceToolChangeOn = false;

		cntrop->BreakThrough.Enabled = false;

		cntrop->ArcFilter.Enabled = false;

		cntrop->RotaryAxis.Enabled = false;

		cntrop->CutParams.ContourSubtype = params->cntrtpe;

		cntrop->CutParams.InternalCornerRoundingRadius = .001;

		cntrop->PlungeRate = 75.0;

		cntrop->RetractRate = 500.0;
		//lead in

		//entry params

		//end lead in
		//
		cntrop->SpindleSpeed = params->spindlespeed;
		//set feedrate
		cntrop->FeedRate = params->FeedRate;

		cntrop->NCIName = _T("Contour #1");

		cntrop->Name = _T("Contour operation created via API");
		operation op = {};
		DB_LIST_ENT_PTR ptr;
		bool succf;
		cntrop->SetChainArray(chains);
		if (!cntrop->Commit())
		{
			return 0;
		}
		cntrop->Regenerate();
		op.op_idn = cntrop->GetOperationID();
		operation_manager(&op, OPMGR_GET, &ptr, &succf);
		op.u.prm_cntr.ex_corner_rad = 0.001;
		op.dcuts.stock_t_l = stock_to_leave_on_floor;
		op.misc.on = false;

		op.cmn.rapid_retract = true;

		op.cmn.retract_inc = false;

		op.cmn.retract_on = false;

		op.cmn.clearance_inc = false;

		op.cmn.depth_inc = false;

		op.cmn.top_stock_inc = false;

		op.cmn.feed_inc = false;

		op.cc.type = CC_COMPUTER;

		op.cmn.stk_remain = params->stock_to_leave_on_wall;

		op.dcuts.fin_n = params->num_fcuts;

		op.dcuts.fin_amt = params->size_fcuts;

		op.u.prm_cntr.tab.adv_auto = true;

		op.u.prm_cntr.tab.full_thick = false;

		if (params->leadinoutison)
		{
			op.lead.entry.on = true;

			op.lead.entry.arc_radius_pct = 0.0;

			op.lead.entry.arc_sweep = TWO_PI / 4;

			op.lead.entry.line_length_pct = params->line_length_pct;

			op.lead.entry.perp = true;

			op.lead.entry.helix_height = 0.0;

			op.lead.entry.ramp_height = 0.0;

			op.lead.exit.on = true;

			op.lead.exit.arc_radius_pct = 0.0;

			op.lead.exit.arc_sweep = TWO_PI / 4;

			op.lead.exit.line_length_pct = params->line_length_pct;

			op.lead.exit.perp = true;

			op.lead.exit.helix_height = 0.0;

			op.lead.exit.ramp_height = 0.0;

			cntrop->CutParams.InternalCornerRoundingRadius = .000;
			op.u.prm_cntr.ex_corner_rad = 0.000;
		}
		op.tl.feed = params->FeedRate;
		operation_manager(&op, OPMGR_REWRITE, &ptr, &succf);
		//operation_manager(&op, OPMGR_NCI_REGEN, &ptr, &succf);
		auto chaincloner = InitCloneChainBasedOperationsFunctions();
		MastercamChookSdk::OperationsManager::CloneChainBasedOperationsParams chainclonerparams;
		chainclonerparams.op_id = op.op_idn;
		auto newop = chaincloner.clonechainbasedoperations(chainclonerparams);
		//RefreshOperation(newop->op_idn);

		Mastercam::Operations::OperationsManager::RefreshOperationsManager();
	}

	return 1;
}

int ChookSdkLibrary::OperationManagerUtilities::CreateOperations::MakePocketOpFromChains(const ChookSdkLibrary::OperationManagerUtilities::MakePocketOpFromChainsParams ^params)
//int level, double clearancePlane, double feedPlane, double topOfStock, double depth, int viewId, Mastercam::Database::Types::CutterCompDir cuttercompdir,
//Mastercam::Database::Types::ChainDirectionType chndir, int FeedRate, int spindlespeed, int slot)//, EndMillFlatTool ^ tool)
{
	//CString strname = "Mastercam";
	//CString entryname = "delete_duplicates_basic";
	//post_FT_command(
	//	strname,
	//	entryname);
	auto views = Mastercam::Support::SearchManager::GetViews();

	Mastercam::IO::ViewManager::GraphicsView = views[params->viewId];

	Mastercam::IO::ViewManager::CPlane = views[params->viewId];

	Mastercam::IO::ViewManager::TPlane = views[params->viewId];

	Mastercam::Database::ChainManager::ChainTolerance = .01;

	const auto chains = Mastercam::Database::ChainManager::ChainAll(true, false, nullptr, params->chndir, params->level);
	repaint_graphics();
	//check that we have something///////////////////////////////////////////////////////////////////////////////////////////////////
	operation op = {};

	if (chains != nullptr && chains->Length != 0)
	{

		auto cntrop = gcnew Mastercam::Operations::PocketOperation;

		cntrop->AssignMillToolBySlot(params->slot);

		cntrop->Roughing.Enabled = true;

		//		cntrop->UpdateToolSettings();

		cntrop->OperationTool->SpindleRotation = 0;

		cntrop->Finishing.Enabled = false;
		//linking params
		cntrop->Linking->FeedPlane = params->feedPlane;

		cntrop->Linking->Depth = params->depth;

		cntrop->DepthCuts.Enabled = true;

		cntrop->PocketRoughEntry.Helix.MaxRadius = .2;

		cntrop->PocketRoughEntry.Helix.FollowBoundaryOnlyFail = true;

		cntrop->PocketRoughEntry.Helix.Tolerance = .001;

		cntrop->PocketRoughEntry.Helix.MinRadius = .005;

		cntrop->PocketRoughEntry.Helix.ClearanceXY = .005;

		cntrop->PocketRoughEntry.Helix.ClearanceZ = .05;

		cntrop->PocketRoughEntry.EntryMode = Mastercam::Operations::Types::PocketRoughEntryMode::Helix;

		cntrop->Linking->ClearanceOn = true;

		cntrop->Linking->Clearance = params->clearancePlane;

		cntrop->Linking->Retract = params->clearancePlane;

		cntrop->Linking->RetractOn = true;

		cntrop->Linking->TopStock = params->topOfStock;

		cntrop->MiscValues->UseValuesFromPost = true;

		cntrop->ForceToolChangeOn = false;

		cntrop->BreakThrough.Enabled = false;

		cntrop->RotaryAxis.Enabled = false;

		cntrop->DepthCuts.Enabled = true;

		cntrop->DepthCuts.CutOrderByDepth = true;

		cntrop->DepthCuts.MaxRoughStep = .755;

		cntrop->DepthCuts.TaperedWalls = false;

		cntrop->DepthCuts.UseIslandDepths = false;

		cntrop->DepthCuts.UseSubprogram = false;

		cntrop->PlungeRate = 75.0;

		cntrop->RetractRate = 500.0;

		cntrop->CutParams.LinearizeTolerance = .0001;



		//lead in

		//entry params

		//end lead in
		//
		cntrop->SpindleSpeed = params->spindlespeed;
		//set feedrate
		cntrop->FeedRate = params->FeedRate;

		cntrop->NCIName = _T("Pocket #1");

		cntrop->Name = _T("Pocket operation created via API");

		op.op_idn = cntrop->GetOperationID();
		cntrop->SetChainArray(chains);
		if (!cntrop->Commit())
		{
			return 0;
		}
		cntrop->Regenerate();
		DB_LIST_ENT_PTR ptr{};
		bool succf{};
		op.op_idn = cntrop->GetOperationID();
		operation_manager(&op, OPMGR_GET, &ptr, &succf);
		op.dcuts.stock_t_l = 0.0;
		op.misc.on = false;

		op.cmn.rapid_retract = true;

		op.cmn.retract_inc = false;

		op.cmn.retract_on = false;

		op.cmn.clearance_inc = false;

		op.cmn.depth_inc = false;

		op.cmn.top_stock_inc = false;

		op.cmn.feed_inc = false;
		op.u.prm_pkt.add_finish = false;
		op.u.prm_pkt.climb = false;
		op.u.prm_pkt.taper.on = false;
		op.u.prm_pkt.rough = true;
		op.u.prm_pkt.ch_sort.sort_method = 1;
		op.u.prm_pkt.co_spir_disp = true;
		op.u.prm_pkt.add_finish = true;
		op.u.prm_pkt.rgh_step_pct = 50;
		//op.u.prm_pkt.rgh_entry.on = true;
		//op.u.prm_pkt.rgh_entry.entry_type = 0;
		//op.u.prm_pkt.rgh_entry.helix.angle = TWO_PI / 36;
		//op.u.prm_pkt.rgh_entry.helix.z_clear = .05;
		double min = .01, max = .5;
		//op.u.prm_pkt.rgh_entry.helix.rad_min = min;
		//op.u.prm_pkt.rgh_entry.helix.rad_max = max;
		//op.u.prm_pkt.rgh_entry.helix.xy_clear = .005;
		short stk_mde = 2;
		short cut_mthd = 2;
		op.u.prm_pkt.cp.cmp_to_tip;
		double dbl = .005;
		op.u.prm_pkt.cp.lin_tol = dbl;
		op.u.prm_pkt.cut_method = cut_mthd;
		op.u.prm_pkt.rough = true;
		op.u.prm_pkt.add_finish = false;
		op.u.prm_pkt.tool_down = true;
		short pck_typ = 0;
		op.dcuts.tool_down = true;
		op.u.prm_pkt.pock_type = pck_typ;
		op.u.prm_pkt.finish = false;
		op.u.prm_pkt.spiral_out = true;
		op.u.prm_pkt.rgh_step_pct_flat = true;
		op.u.prm_pkt.climb = false;
		if (params->leadinoutison)
		{
			op.lead.entry.on = true;

			op.lead.entry.arc_radius_pct = 0.0;

			op.lead.entry.arc_sweep = TWO_PI / 4;

			op.lead.entry.line_length_pct = params->line_length_pct;

			op.lead.entry.perp = true;

			op.lead.entry.helix_height = 0.0;

			op.lead.entry.ramp_height = 0.0;

			op.lead.exit.on = true;

			op.lead.exit.arc_radius_pct = 0.0;

			op.lead.exit.arc_sweep = TWO_PI / 4;

			op.lead.exit.line_length_pct = params->line_length_pct;

			op.lead.exit.perp = true;

			op.lead.exit.helix_height = 0.0;

			op.lead.exit.ramp_height = 0.0;

			op.u.prm_pkt.finish = true;

			op.u.prm_pkt.rough = false;

			op.u.prm_pkt.fin_n = 1;

			op.u.prm_pkt.fin_step = .01;

			op.u.prm_pkt.rgh_entry.on = false;

			op.u.prm_pkt.fin_outer = true;

			op.u.prm_pkt.fin_w_rgh = false;

			op.u.prm_pkt.n_spring_cuts = 0;


		}

		op.cmn.stk_remain = params->stock_to_leave_on_wall;

		op.dcuts.fin_n = params->num_fcuts;

		op.dcuts.fin_amt = params->size_fcuts;

		operation_manager(&op, OPMGR_REWRITE, &ptr, &succf);
		operation_manager(&op, OPMGR_NCI_REGEN, &ptr, &succf);

		auto chaincloner = InitCloneChainBasedOperationsFunctions();
		MastercamChookSdk::OperationsManager::CloneChainBasedOperationsParams chainclonerparams;
		chainclonerparams.op_id = op.op_idn;
		auto newop = chaincloner.clonechainbasedoperations(chainclonerparams);
		//RefreshOperation(newop->op_idn);
		repaint_graphics();
		Mastercam::Operations::OperationsManager::RefreshOperationsManager();
	}

	return 1;
}


int ChookSdkLibrary::OperationManagerUtilities::CreateOperations::MakeDrillOpFromGeometry(const ChookSdkLibrary::OperationManagerUtilities::MakeDrillOpFromGeometryParams ^params)
////double clearancePlane, double feedPlane, double topOfStock, double depth, int viewId, int FeedRate, int spindlespeed, int slot, int targetlevel
{
	operation op = {};

	const auto views = Mastercam::Support::SearchManager::GetViews();

	Mastercam::IO::ViewManager::GraphicsView = views[params->viewId];

	Mastercam::IO::ViewManager::CPlane = views[params->viewId];

	Mastercam::IO::ViewManager::TPlane = views[params->viewId];
	//////////////////////////////////////////////////////////////////////////////////////////////////
	Mastercam::Database::ChainManager::ChainTolerance = .0001;
	//create a new mastercam drilling opertation
	auto drilloperation = gcnew Mastercam::Operations::DrillOperation;
	//use the chainmanager to get the geometry from the mastercam database //closed chains only
	const auto chains = Mastercam::Database::ChainManager::ChainAll(true, false, nullptr, Mastercam::Database::Types::ChainDirectionType::Clockwise, params->targetlevel);
	//array
	int size = 2;
	System::Collections::Generic::List<Mastercam::Database::CurveGeometry^>^ curvegeometry = gcnew System::Collections::Generic::List<Mastercam::Database::CurveGeometry^>(0);
	//array<Mastercam::Database::CurveGeometry^>^ curvegeometry;
	//check that we have something
	if (chains != nullptr && chains->Length > 0)
	{
		//loop through the chains of the target geometry
		for (auto i = 0; i < chains->Length; i++)
		{
			//System::Windows::Forms::MessageBox::Show("chains Detected");
			//get the tot
			//retrieve the geometry in the target level
			const auto selectedEnts = Mastercam::Database::ChainManager::GetGeometryInChain(chains[i]);
			if (selectedEnts != nullptr)
			{
				//loop through the geometry assicuated with the chains
				for (auto j = 0; j < selectedEnts->Length; j++)
				{
					//System::Windows::Forms::MessageBox::Show("Curvegeometry Detected");
					//add the geometry to the list
					curvegeometry->Add(selectedEnts[j]);

				}
			}

		}
	}

	System::Collections::Generic::List<Mastercam::Curves::ArcGeometry^>^ arcgeometry = gcnew System::Collections::Generic::List<Mastercam::Curves::ArcGeometry^>(0);
	//convert the list to an array
	auto curvearray = curvegeometry->ToArray();
	//loop through the array
	for (auto i = 0; i < curvearray->Length; i++)
	{
		//declare the arc type id as a variable
		const auto arcType = Mastercam::Curves::ArcGeometry::typeid;
		//get the current type id
		const auto gt = curvearray[i]->GetType();

		//System::Windows::Forms::MessageBox::Show(gt->ToString());feedrate
		//check if we have an arc
		if (gt == arcType)
		{
			//add the arc into the arc list
			arcgeometry->Add(dynamic_cast<Mastercam::Curves::ArcGeometry ^> (curvearray[i]));
			//System::Windows::Forms::MessageBox::Show("Arc Detected");
		}
	}
	curvegeometry = gcnew System::Collections::Generic::List<Mastercam::Database::CurveGeometry^>(0);
	//convert the arc list to an array
	auto arcarray = arcgeometry->ToArray();
	//define a variable to count the amount of arcs assigned as drill point
	auto ptcount = 0;
	//loop through the arc array
	for (auto i = 0; i < arcarray->Length; i++)
	{
		auto drillPt = gcnew Mastercam::Database::DrillPoint(arcarray[i]);
		if (arcarray[i]->Validate())
		{
			if (!arcarray[i]->Blanked)
			{

				if (arcarray[i]->Data.Radius > 0.0)
				{
					drilloperation->DrillPoints->Add(drillPt);
					ptcount++;
				}
			}
		}
	}
	drilloperation->ReverseDrillPoints();
	arcgeometry = gcnew System::Collections::Generic::List<Mastercam::Curves::ArcGeometry^>(0);

	//	drilloperation->UpdateToolSettings();

	drilloperation->AssignMillToolBySlot(params->slot);

	drilloperation->OperationTool->SpindleRotation = 0;
	//linking params
	drilloperation->Linking->FeedPlane = params->feedPlane;

	drilloperation->Linking->Depth = params->depth;

	drilloperation->Linking->ClearanceOn = true;

	drilloperation->Linking->Clearance = params->clearancePlane;

	drilloperation->Linking->Retract = params->clearancePlane;

	drilloperation->Linking->RetractOn = true;

	drilloperation->Linking->TopStock = params->topOfStock;

	drilloperation->MiscValues->UseValuesFromPost = true;

	drilloperation->ForceToolChangeOn = false;

	drilloperation->RotaryAxis.Enabled = false;

	drilloperation->PlungeRate = 75.0;

	drilloperation->RetractRate = 500.0;
	//lead in

	//entry params

	//end lead in
	//
	drilloperation->SpindleSpeed = params->spindlespeed;
	//set feedrate
	drilloperation->FeedRate = params->FeedRate;

	drilloperation->NCIName = _T("Drill #1");

	drilloperation->Name = _T("Drilling operation created via API");

	drilloperation->Commit();

	//cntrop->Regenerate();

	DB_LIST_ENT_PTR ptr{};

	bool succf{};

	op.op_idn = drilloperation->GetOperationID();

	operation_manager(&op, OPMGR_GET, &ptr, &succf);

	op.cmn.stk_remain = 0.0;

	op.dcuts.stock_t_l = 0.0;

	op.misc.on = false;

	op.cmn.rapid_retract = true;

	op.cmn.retract_inc = false;

	op.cmn.retract_on = false;

	op.cmn.clearance_inc = false;

	op.cmn.depth_inc = false;

	op.cmn.top_stock_inc = false;

	op.cmn.feed_inc = false;
	op.u.prm_drl.brk_thru = 0.0;
	op.u.prm_drl.calcDepthFromStock = false;
	op.u.prm_drl.cycle = 0;
	op.u.prm_drl.drill_tip = false;
	op.u.prm_drl.dwell = 0.0;
	op.u.prm_drl.peck1 = 0.55;
	op.u.prm_drl.peck2 = 0.05;
	op.u.prm_drl.peck_clr = 0.5;
	op.u.prm_drl.start_hole = false;
	op.u.prm_drl.sub_pgm = false;
	op.u.prm_drl.do_custom = false;
	op.u.prm_drl.TipControl = 0;
	op.u.prm_drl.sort_method = 1;
	operation_manager(&op, OPMGR_REWRITE, &ptr, &succf);
	operation_manager(&op, OPMGR_NCI_REGEN, &ptr, &succf);
	drilloperation->Regenerate();
	auto drillcloner = InitCloneDrillingOperationsFunctions();
	MastercamChookSdk::OperationsManager::CloneDrillingOperationsParams drillclonerparams;
	drillclonerparams.op_id = op.op_idn;
	auto newop = drillcloner.clonedrillingoperations(drillclonerparams);
	//RefreshOperation(newop->op_idn);
	repaint_graphics();
	return 1;

}

Target Mastercam 2018 & 2020

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