Sign in to follow this  
c++

C++/Cli NEThook Entry Point

Recommended Posts

Here is the code I am using now to create c++/cli NEThooks that can access both c++ and c# functions compiled into 1 DLL for visual studios :

using Mastercam::App::NetHook3App;

public ref class MyConcreteClass : public NetHook3App
{
public : virtual Mastercam::App::Types::MCamReturn Run(int param) override {
//your code here//
	System::Windows::Forms::MessageBox::Show("msg");

		return Mastercam::App::Types::MCamReturn::NoErrors;
	};
	
};

 

Share this post


Link to post
Share on other sites

To do this :

-> download the c++/cli add on for visual studios 2017 community

->create a new clr empty project in visual studios

-> link in the NEThook3_0.dll file from your mastercam

->add the above code to a new file called main.cpp

->add a .resx file and add in your tool tip information

->create an ft. file with the tooltip and resource information

->compile the project and place the resulting .dll file and .ft file in the chooks folder

-> add a tooltip to your context menu then run the nethook you will see a winforms messagebox dispay : "msg"

-> from there you could add in the desired c++ sdk libraries and nethook3_0 funtions that you want to use.

Thank you for taking the time to read.

  • Like 1

Share this post


Link to post
Share on other sites

some mixed code

	ChainManager::ChainTolerance = 0.015;
			////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		LevelsManager::SetMainLevel(50000);
		
		const auto chains = Mastercam::Database::ChainManager::ChainAll(true, false, nullptr, Mastercam::Database::Types::ChainDirectionType::Clockwise, 50);
		ChainManager::SortChains(chains, ChainManager::SortType::Area, ChainManager::SortOrder::Descending);
		
		const auto offsetChaini = chains[0]->OffsetChain2D(Mastercam::Database::Types::OffsetSideType::Left, 0.0, Mastercam::Database::Types::OffsetRollCornerType::None, 0.0, false, 0.01, true);
		const auto chngeometry = ChainManager::GetGeometryInChain(chains[0]);

		for (long i = 0; i < chngeometry->Length; i++)
		{
			chngeometry[i]->Delete();
		}

 

Share this post


Link to post
Share on other sites
void SplineFromChainsOnLevel(const int &level4)
	{
	    //chain the geometry on a specified level : returns a chain array
		const auto chains4 = ChainManager::ChainAll(true, false, nullptr, Mastercam::Database::Types::ChainDirectionType::Clockwise, level4);
        //check that we have something////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		if (chains4 != nullptr && chains4->Length != 0)
		{
			//convert the current geometry in chain array to parametric spline : delete the original geometry
			GeometryCreationManager::CreateParametricSplineFromChain(chains4[0], 0.015, Mastercam::GeometryUtility::Types::OriginalCurvesDisposition::Delete, 500);
			//////////////////////////////
		}
	}
void GetOuterChainFromLevel(int level)
{
	//chain the geometry on a specified level : returns a chain array
	const auto chains = Mastercam::Database::ChainManager::ChainAll(true, false, nullptr, Mastercam::Database::Types::ChainDirectionType::Clockwise, level);

	if (chains != nullptr && chains->Length != 0)
	{
		//sort chains by area in descending order : largest to smallest area
		ChainManager::SortChains(chains, ChainManager::SortType::Area, ChainManager::SortOrder::Descending);
		//use the offset function to separate the largest area chain from the group: the new geometry will be created on the current active level
		chains[0]->OffsetChain2D(Mastercam::Database::Types::OffsetSideType::Left, 0.0, Mastercam::Database::Types::OffsetRollCornerType::None, 0.0, false, 0.01, true);
		//get the geometry from chain index zero
		const auto chngeometry = ChainManager::GetGeometryInChain(chains[0]);
		//loop through each element in the geometry array derived from the chain
		for (long i = 0; i < chngeometry->Length; i++)
		{
			//delete the orginal geometry
			chngeometry[i]->Delete();
		}
	}
}

 

Share this post


Link to post
Share on other sites

Another Sample for contourOp with c++/cli

int makecsopfromchains(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 tabon)//, EndMillFlatTool ^ tool)
{
	const auto chains = Mastercam::Database::ChainManager::ChainAll(true, false, nullptr, chndir, level);
	//check that we have something///////////////////////////////////////////////////////////////////////////////////////////////////
	operation op = {};

	if (chains != nullptr && chains->Length != 0)
	{
		auto views = Mastercam::Support::SearchManager::GetViews();

		Mastercam::IO::ViewManager::GraphicsView = views[viewId];

		Mastercam::IO::ViewManager::CPlane = views[viewId];

		Mastercam::IO::ViewManager::TPlane = views[viewId];

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

		cntrop->CutterComp.Direction = cuttercompdir;

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

		cntrop->Linking->Depth = depth;

		cntrop->Linking->ClearanceOn = true;

		cntrop->Linking->Clearance = clearancePlane;

		cntrop->Linking->Retract = clearancePlane;

		cntrop->Linking->RetractOn = true;

		cntrop->Linking->TopStock = topOfStock;

		cntrop->MiscValues->UseValuesFromPost = true;

		cntrop->CutParams.LeaveStock.OnFloors = 0.0;

		cntrop->CutParams.LeaveStock.OnWalls = 0.0;

		cntrop->CutParams.InfiniteLookAhead = true;

		cntrop->MultiPass.Enabled = false;
		if (tabon)
		{
			cntrop->Tabs.Enabled = true;

			cntrop->Tabs.NumberOfTabs = 4;

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

			cntrop->Tabs.TabThickness = 0.04;

			cntrop->Tabs.TabWidth = 0.1;
		}
		cntrop->ForceToolChangeOn = false;

		cntrop->BreakThrough.Enabled = false;

		cntrop->ArcFilter.Enabled = false;

		cntrop->RotaryAxis.Enabled = false;

		cntrop->CutParams.ContourSubtype = cntrtpe;

		cntrop->CutParams.InternalCornerRoundingRadius = .001;

		cntrop->Entry.ArcRadius = .025;

		cntrop->Entry.ArcSweep = 90.0;

		cntrop->Entry.HelixHeight = 0.0;

		cntrop->Entry.Enabled = true;

		cntrop->SpindleSpeed = spindlespeed;

		cntrop->FeedRate = FeedRate;

		cntrop->NCIName = "Contour #1";

		cntrop->Name = "Contour operation created via API";
		
		op.op_idn = cntrop->GetOperationID();
		cntrop->SetChainArray(chains);
		if (!cntrop->Commit())
		{
			return 0;
		}
	}

	return 1;
}

 

Share this post


Link to post
Share on other sites

some new functions

int makehlxbreopfromgeo( double clearancePlane, double feedPlane, double topOfStock, double depth, int viewId,  int FeedRate, int spindlespeed, int slot)
{
	auto views = Mastercam::Support::SearchManager::GetViews();

	Mastercam::IO::ViewManager::GraphicsView = views[viewId];

	Mastercam::IO::ViewManager::CPlane = views[viewId];

	Mastercam::IO::ViewManager::TPlane = views[viewId];

	//check that we have something///////////////////////////////////////////////////////////////////////////////////////////////////
	operation op = {};

	System::Collections::Generic::List<Mastercam::Curves::ArcGeometry ^> ^arcs;

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

	auto arcType = Mastercam::Curves::ArcGeometry::typeid;

	auto ptcount = 0;

	auto selectedEnts = Mastercam::Support::SearchManager::GetSelectedGeometry();
	// Iterate through each wireframe entity 
	//System::Windows::Forms::MessageBox::Show(selectedEnts->Length.ToString());
	for (auto i = 0; i < selectedEnts->Length; i++)
	{
		auto gt = selectedEnts[i]->GetType();
		//System::Windows::Forms::MessageBox::Show("gt=> " + gt->ToString());
        if (gt == arcType)
		{
			auto drillPt = gcnew Mastercam::Database::DrillPoint(dynamic_cast<Mastercam::Curves::ArcGeometry ^> (selectedEnts[i]));

			cntrop->DrillPoints->Add(drillPt);

			ptcount++;
		}
	}

	

		



		cntrop->AssignMillToolBySlot(slot);
		//linking params
		cntrop->Linking->FeedPlane = feedPlane;

		cntrop->Linking->Depth = depth;

		cntrop->Linking->ClearanceOn = true;

		cntrop->Linking->Clearance = clearancePlane;

		cntrop->Linking->Retract = clearancePlane;

		cntrop->Linking->RetractOn = true;

		cntrop->Linking->TopStock = topOfStock;

		cntrop->MiscValues->UseValuesFromPost = true;


		cntrop->ForceToolChangeOn = false;

		cntrop->RotaryAxis.Enabled = false;

		cntrop->PlungeRate = 75.0;

		cntrop->RetractRate = 500.0;
		//lead in 

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

		cntrop->NCIName = "Helix #1";

		cntrop->Name = "Helix Bore operation created via API";

		cntrop->Commit();

		cntrop->Regenerate();
		
		
		DB_LIST_ENT_PTR ptr{};

		bool succf{};

		op.op_idn = cntrop->GetOperationID();

		operation_manager(&op, OPMGR_GET, &ptr, &succf);
		op.cmn.stk_remain = 0.0;
		op.dcuts.stock_t_l = 0.0;
		op.u.helix_bore.finish_feedrate_pct = 100.0;
		op.u.helix_bore.entry_exit_sweep = TWO_PI / 4;
		op.u.helix_bore.finish_on = false;
		op.u.helix_bore.rough_pitch = .05;
		op.u.helix_bore.start_at_center = true;
		op.u.helix_bore.n_rough_passes = 1;
		op.u.helix_bore.perp_entry = true;
		op.u.helix_bore.overlap = 50.0;
		op.u.helix_bore.entry_exit_sweep = 45.0;
		op.u.helix_bore.start_angle = 90.0;
		op.u.helix_bore.calcDepthFromStock = false;
		operation_manager(&op, OPMGR_REWRITE, &ptr, &succf);
		operation_manager(&op, OPMGR_NCI_REGEN, &ptr, &succf);
	

	return 1;
}
int makedrillopfromgeo(double clearancePlane, double feedPlane, double topOfStock, double depth, int viewId, int FeedRate, int spindlespeed, int slot)
{
	auto views = Mastercam::Support::SearchManager::GetViews();

	Mastercam::IO::ViewManager::GraphicsView = views[viewId];

	Mastercam::IO::ViewManager::CPlane = views[viewId];

	Mastercam::IO::ViewManager::TPlane = views[viewId];

	//check that we have something///////////////////////////////////////////////////////////////////////////////////////////////////
	operation op = {};

	System::Collections::Generic::List<Mastercam::Curves::ArcGeometry ^> ^arcs;

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

	auto arcType = Mastercam::Curves::ArcGeometry::typeid;

	auto ptcount = 0;

	auto selectedEnts = Mastercam::Support::SearchManager::GetSelectedGeometry();
	// Iterate through each wireframe entity 
	//System::Windows::Forms::MessageBox::Show(selectedEnts->Length.ToString());
	for (auto i = 0; i < selectedEnts->Length; i++)
	{
		auto gt = selectedEnts[i]->GetType();
		//System::Windows::Forms::MessageBox::Show("gt=> " + gt->ToString());
		if (gt == arcType)
		{
			auto drillPt = gcnew Mastercam::Database::DrillPoint(dynamic_cast<Mastercam::Curves::ArcGeometry ^> (selectedEnts[i]));

			cntrop->DrillPoints->Add(drillPt);

			ptcount++;
		}
	}







	cntrop->AssignMillToolBySlot(slot);
	//linking params
	cntrop->Linking->FeedPlane = feedPlane;

	cntrop->Linking->Depth = depth;

	cntrop->Linking->ClearanceOn = true;

	cntrop->Linking->Clearance = clearancePlane;

	cntrop->Linking->Retract = clearancePlane;

	cntrop->Linking->RetractOn = true;

	cntrop->Linking->TopStock = topOfStock;

	cntrop->MiscValues->UseValuesFromPost = true;


	cntrop->ForceToolChangeOn = false;

	cntrop->RotaryAxis.Enabled = false;

	cntrop->PlungeRate = 75.0;

	cntrop->RetractRate = 500.0;
	//lead in 

	//entry params

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

	cntrop->NCIName = "Drill #1";

	cntrop->Name = "Drilling operation created via API";

	cntrop->Commit();

	cntrop->Regenerate();


	DB_LIST_ENT_PTR ptr{};

	bool succf{};

	op.op_idn = cntrop->GetOperationID();

	operation_manager(&op, OPMGR_GET, &ptr, &succf);
	op.cmn.stk_remain = 0.0;
	op.dcuts.stock_t_l = 0.0;
	op.u.prm_drl.brk_thru = 0.0;
	op.u.prm_drl.calcDepthFromStock = false;
	op.u.prm_drl.cycle = 1;
	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;
	operation_manager(&op, OPMGR_REWRITE, &ptr, &succf);
	operation_manager(&op, OPMGR_NCI_REGEN, &ptr, &succf);


	return 1;
}
int makecrcmillopfromgeo(double clearancePlane, double feedPlane, double topOfStock, double depth, int viewId, int FeedRate, int spindlespeed, int slot,double num_fcuts, double size_fcuts,double stk_tl_onwall)
{
	auto views = Mastercam::Support::SearchManager::GetViews();

	Mastercam::IO::ViewManager::GraphicsView = views[viewId];

	Mastercam::IO::ViewManager::CPlane = views[viewId];

	Mastercam::IO::ViewManager::TPlane = views[viewId];

	//check that we have something///////////////////////////////////////////////////////////////////////////////////////////////////
	operation op = {};

	System::Collections::Generic::List<Mastercam::Curves::ArcGeometry ^> ^arcs;

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

	auto arcType = Mastercam::Curves::ArcGeometry::typeid;

	auto ptcount = 0;

	auto selectedEnts = Mastercam::Support::SearchManager::GetSelectedGeometry();
	// Iterate through each wireframe entity 
	//System::Windows::Forms::MessageBox::Show(selectedEnts->Length.ToString());
	for (auto i = 0; i < selectedEnts->Length; i++)
	{
		auto gt = selectedEnts[i]->GetType();
		//System::Windows::Forms::MessageBox::Show("gt=> " + gt->ToString());
		if (gt == arcType)
		{
			auto drillPt = gcnew Mastercam::Database::DrillPoint(dynamic_cast<Mastercam::Curves::ArcGeometry ^> (selectedEnts[i]));

			cntrop->DrillPoints->Add(drillPt);

			ptcount++;
		}
	}







	cntrop->AssignMillToolBySlot(slot);
	//linking params
	cntrop->Linking->FeedPlane = feedPlane;

	cntrop->Linking->Depth = depth;

	cntrop->Linking->ClearanceOn = true;

	cntrop->Linking->Clearance = clearancePlane;

	cntrop->Linking->Retract = clearancePlane;

	cntrop->Linking->RetractOn = true;

	cntrop->Linking->TopStock = topOfStock;

	cntrop->MiscValues->UseValuesFromPost = true;


	cntrop->ForceToolChangeOn = false;

	cntrop->RotaryAxis.Enabled = false;

	cntrop->PlungeRate = 75.0;

	cntrop->RetractRate = 500.0;
	//lead in 

	//entry params

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

	cntrop->NCIName = "Circle milling #1";

	cntrop->Name = "Circle Milling operation created via API";

	cntrop->Commit();

	cntrop->Regenerate();


	DB_LIST_ENT_PTR ptr{};

	bool succf{};

	op.op_idn = cntrop->GetOperationID();

	operation_manager(&op, OPMGR_GET, &ptr, &succf);
	op.cmn.stk_remain = stk_tl_onwall;
	op.dcuts.stock_t_l = 0.0;
	op.dcuts.fin_n = num_fcuts;
	op.dcuts.fin_amt = size_fcuts;
	op.dcuts.on = true;
	op.dcuts.sub_pgm = false;
	op.dcuts.bottom_up = false;
	op.dcuts.by_depth = false;
	op.dcuts.rgh_n = 1;
	op.dcuts.rgh_amt = 1000.0;
	op.dcuts.island_depths = false;
	op.u.circmill.calcDepthFromStock = false;
	op.u.circmill.cmn.brkthru_on = false;
	op.u.circmill.cmp_to_tip = false;
	op.u.circmill.entry_exit_sweep = 90.0;
	op.u.circmill.entry_fr_override_on = false;
	op.u.circmill.exit_fr_override_on = false;
	op.u.circmill.finish_all = false;
	op.u.circmill.fin_fr_override_on = false;
	op.u.circmill.helix_on = false;
	op.u.circmill.fin_ss_override_on = false;
	op.u.circmill.hs_entry_on = false;
	op.u.circmill.mp_fin_on = false;
	op.u.circmill.mp_rgh_on = false;
	op.u.circmill.perp_entry = false;
	op.u.circmill.start_at_center = true;
	op.u.circmill.overlap = 0.0;
	op.u.circmill.rough_on = false;
	op.u.circmill.taper = false;
	operation_manager(&op, OPMGR_REWRITE, &ptr, &succf);
	operation_manager(&op, OPMGR_NCI_REGEN, &ptr, &succf);


	return 1;
}

 

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • 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