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:

Setting TPlane/Cplane using CHOOK sdk


Recommended Posts

Hi,

I realize I am posting a lot, due to a lot of simultaneous projects hopefully its ok, for my automatic programming project I need to set the cplane and tplane to top at the start of my program but so far I havent found one, the only functions I know are in vbscript so I could write to a vbs file and then run it from a nethook but I am trying to consolidate my programming into as few languages as possible.

Any nethook examples would be good too I saw the functions are there but havent had time to dive into it.

Thanks,

Link to comment
Share on other sites

I'm not a developer or a cpp guy, but give the below snippet a shot.  Hopefully a real cpp developer chimes in... 

bool SetToolPlaneToTop(int opID, bool regen = false)
{
	ent operationEntity;
	if (TpMainOpMgr.GetMainOpList().DatabaseRetrieve(opID, operationEntity))
	{
		CInterrogateMastercamFile fileInterrogator;
		fileInterrogator.Load();

		MastercamPlanes * planes = static_cast<MastercamPlanes *>(fileInterrogator.GetpPlanes());

		Plane top = planes->GetTopPlanePtr();

		op_view topView;
		top.Convert(topView, *planes);

		operationEntity.u.op.tpln = topView;

		TpMainOpMgr.GetMainOpList().UpdateListAndDB(operationEntity, false);

		if (regen)
		{
			DB_LIST_ENT_PTR dbPtr;
			bool result = false;
			operation_manager(&operationEntity.u.op,
				              OPMGR_NCI_REGEN,
				              &dbPtr,
				              &result);	
		}

		return true;
	}
	else
	{
		return false;
	}
}

 

Link to comment
Share on other sites

I have been passing the parameters for the view for both top and bottom operations directly into the operation struct prior to creating the operation , however this only seems to work if the starting plane is top otherwise either my chain comes out backwards. My current settings are something like this.

void Make_Op(operation &op, TP_OPCODE op_code, const matrix_33 v_mat, double feed_pln, double clearance_pln, double dpth, double top_stock, short view_num, short command)
{
	DB_LIST_ENT_PTR next_ptr;
	bool o_succf;
	op.opcode = op_code;
	operation_manager(&op, OPMGR_INIT, &next_ptr, &o_succf);//add a contour op?
	op.tpln.m = v_mat;
	op.cpln.m = v_mat;
	op.cmn.stk_remain = 0;
	op.dcuts.stock_t_l = 0;
	op.cmn.rapid_retract = true;
	op.dcuts.on = true;
	op.dcuts.rgh_amt = .75;
	op.dcuts.tool_down = 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.cmn.feed_pln = feed_pln;
	op.cmn.clearance_pln = clearance_pln;
	op.cmn.depth = dpth;
	op.cmn.top_stock = top_stock;
	op.lead.on = false;
	if (op.opcode == TP_POCKET)
	{
		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 = .05, 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 = .05;
		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 (op.opcode == TP_CONTOUR)
	{
		if (command == 2)
		{
			op.u.prm_cntr.look_ahead = true;
			op.dcuts.stock_t_l = 0;
			op.lead.on = false;
			op.cmn.rapid_retract = true;
			op.u.prm_cntr.tab.on = false;
			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.cmn.feed_pln = 0 + .25;
			op.cmn.clearance_pln = 0 + .5;

			op.u.prm_cntr.ex_corner_rad = 0;
			op.u.prm_cntr.in_corner_rad = 0;
			op.cmn.top_stock = 0;
			op.db.head_idn = -1;
			op.lead.overlap = 0;
			op.u.prm_cntr.look_ahead = true;
			op.u.prm_cntr.ctour_type = 6;
			op.u.prm_cntr.kerfLeft = false;
			if (dpth >= -.25)
			{
				op.cmn.depth = 0;
				op.u.prm_cntr.oscillate.depth = dpth + .035;
			}
			if (dpth > -.7 && dpth < -.25)
			{
				op.cmn.depth = -.05;
				op.u.prm_cntr.oscillate.depth = dpth + .085;
			}
			if (dpth <= -.7)
			{
				op.cmn.depth = -.25;
				op.u.prm_cntr.oscillate.depth = -.5;
			}
			op.u.prm_cntr.oscillate.distance = 4;
			op.u.prm_cntr.oscillate.type = 2;
			op.cc.direction = CC_RIGHT;
			op.cmn.stk_remain = .01;
		}
		if (command == 3)
		{
			op.dcuts.stock_t_l = 0;
			op.u.prm_cntr.look_ahead = true;
			op.cmn.rapid_retract = true;
			op.lead.on = false;
			op.lead.entry.on = true;
			op.lead.entry.arc_radius = .0625;
			op.lead.entry.arc_sweep = 90;
			op.lead.entry.line_length = 0;
			op.lead.entry.perp = false;
			op.lead.entry.helix_height = 0;
			op.lead.entry.ramp_height = 0;
			op.lead.exit.on = true;
			op.lead.exit.arc_radius = .0625;
			op.lead.exit.arc_sweep = 90;
			op.lead.exit.line_length = 0;
			op.lead.exit.perp = false;
			op.lead.exit.helix_height = 0;
			op.lead.exit.ramp_height = 0;
			op.lead.gouge_check = true;
			op.lead.overlap = 0;
			op.u.prm_cntr.ex_corner_rad = 0;
			op.u.prm_cntr.in_corner_rad = 0;
			op.db.head_idn = -1;
			op.lead.exit.arc_radius = .0625;
			op.lead.exit.arc_sweep = 90;
			op.u.prm_cntr.tab.on = false;
			op.dcuts.on = false;
			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.cmn.feed_pln = 0 + .25;
			op.cmn.clearance_pln = 0 + .5;
			op.u.prm_cntr.look_ahead = true;
			op.cmn.depth = dpth + .035;
			op.cmn.top_stock = 0;
			op.u.prm_cntr.ctour_type = 1;
			op.u.prm_cntr.kerfLeft = false;
			op.cc.direction = CC_RIGHT;
		}
		if (command == 4)
		{
			op.u.prm_cntr.look_ahead = true;
			op.u.prm_cntr.start_es.on = false;
			op.u.prm_cntr.end_es.on = false;
			op.dcuts.stock_t_l = 0;
			op.cmn.rapid_retract = true;
			op.lead.on = true;
			op.lead.entry.on = true;
			op.lead.enter_at_midpt = false;
			op.lead.overlap = 0;
			op.lead.entry.arc_radius_pct = 25;
			op.lead.entry.arc_sweep = TWO_PI / 4;
			op.lead.entry.line_length_pct = 0;
			op.lead.entry.perp = false;
			op.lead.entry.helix_height = 0;
			op.lead.entry.ramp_height = 0;
			op.lead.exit.on = true;
			op.lead.exit.arc_radius = .03125;
			op.lead.exit.arc_radius_pct = 25;
			op.u.prm_cntr.ex_corner_rad = 0;
			op.u.prm_cntr.in_corner_rad = 0;
			op.u.prm_cntr.ex_corner_rad = 0;
			op.lead.exit.arc_sweep = TWO_PI / 4;
			op.lead.exit.line_length_pct = 0;
			op.u.prm_cntr.look_ahead = true;
			op.lead.exit.perp = false;
			op.lead.exit.helix_height = 0;
			op.lead.exit.ramp_height = 0;
			op.lead.gouge_check = true;
			op.u.prm_cntr.tab.on = false;
			op.dcuts.on = false;
			op.mcuts.on = false;
			op.db.head_idn = -1;
			op.u.prm_cntr.tab.on = false;
			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.cmn.feed_pln = dpth + .25;
			op.cmn.clearance_pln = dpth + .5;
			op.cmn.depth = dpth;
			op.cmn.top_stock = dpth;
			op.u.prm_cntr.ctour_type = 1;
			op.u.prm_cntr.kerfLeft = false;
			op.cc.direction = CC_LEFT;
		}
	}
		
		op.dcuts.on = true;
		op.dcuts.rgh_amt = .75;
		
		op.cmn.stk_remain = 0;
		op.tpln.v_idn = view_num;
		op.cpln.v_idn = view_num;
		operation_manager(&op, OPMGR_ADD, &next_ptr, &o_succf);//add a contour op?
		operation_manager(&op, OPMGR_REWRITE, &next_ptr, &o_succf);//add a contour op?
	

}

 

Link to comment
Share on other sites

That's odd, the below snippet works for me no matter what the Mastercam plane's are set to.  I always get a contour op with the WCS/T Plane/C Plane set to Top.

bool AddContourOp(double clearancePlane, double feedPlane, double topOfStock, double depth)
{
	bool result = false;

	CInterrogateMastercamFile fileInterrogator;
	fileInterrogator.Load();

	MastercamPlanes * mcPlanes = static_cast<MastercamPlanes *>(fileInterrogator.GetpPlanes());

	Plane topPlane = mcPlanes->GetTopPlanePtr();

	op_view topView;
	topPlane.Convert(topView, *mcPlanes);

	operation op = {};
	DB_LIST_ENT_PTR dbPtr;


	operation_manager(&op,
		              OPMGR_INIT,
		              &dbPtr,
		              &result);

	op.opcode = TP_CONTOUR;
	op.WCS = topView;
	op.tpln = topView;
	op.cpln = topView;

	op.cmn.clearance_pln = clearancePlane;
	op.cmn.feed_pln = feedPlane;
	op.cmn.top_stock = topOfStock;
	op.cmn.depth = depth;

	operation_manager(&op,
		              OPMGR_ADD,
		              &dbPtr,
		              &result);

	return result;
}

 

Link to comment
Share on other sites

Yeah, I got it sorted out now, looks like I was passing matrix33 as a parameter instead of opview :/. I couldn't find the function GetTopPlanePtr so I rewrote it to something a little more basic.

#include "StdAfx.h"

bool MakeMillOp(double clearancePlane, double feedPlane, double topOfStock, double depth, TP_OPCODE opcode,short WCSID,short viewId)
{


	bool result = false;  op_view topView{}; op_view setView{};
	
	matrix_33 m33,m33_2;get_view_matrix(WCSID, m33);get_view_matrix(viewId, m33_2);

	topView.m = m33; topView.v_idn = WCSID; topView.on = true; setView.woff_n = 0; 
	
	operation op = {}; DB_LIST_ENT_PTR dbPtr;

	setView.m = m33_2; setView.v_idn = viewId; setView.on = true; setView.woff_n = 0;

	operation_manager(&op, OPMGR_INIT, &dbPtr, &result); op.opcode = opcode;

	op.WCS = topView; op.tpln = setView; op.cpln = setView; 

	op.cmn.clearance_pln = clearancePlane; op.cmn.feed_pln = feedPlane;

	op.cmn.top_stock = topOfStock; op.cmn.depth = depth;

	operation_manager(&op, OPMGR_ADD, &dbPtr, &result);

	return (result ? true : false);
}

 

Link to comment
Share on other sites
On 10/4/2019 at 12:47 PM, jeff.D said:

That's odd, the below snippet works for me no matter what the Mastercam plane's are set to.  I always get a contour op with the WCS/T Plane/C Plane set to Top.


bool AddContourOp(double clearancePlane, double feedPlane, double topOfStock, double depth)
{
	bool result = false;

	CInterrogateMastercamFile fileInterrogator;
	fileInterrogator.Load();

	MastercamPlanes * mcPlanes = static_cast<MastercamPlanes *>(fileInterrogator.GetpPlanes());

	Plane topPlane = mcPlanes->GetTopPlanePtr();

	op_view topView;
	topPlane.Convert(topView, *mcPlanes);

	operation op = {};
	DB_LIST_ENT_PTR dbPtr;


	operation_manager(&op,
		              OPMGR_INIT,
		              &dbPtr,
		              &result);

	op.opcode = TP_CONTOUR;
	op.WCS = topView;
	op.tpln = topView;
	op.cpln = topView;

	op.cmn.clearance_pln = clearancePlane;
	op.cmn.feed_pln = feedPlane;
	op.cmn.top_stock = topOfStock;
	op.cmn.depth = depth;

	operation_manager(&op,
		              OPMGR_ADD,
		              &dbPtr,
		              &result);

	return result;
}

 

Looks like you solved my problem, much appreciated Jeff.

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