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:

Chaining multiple lines & or arcs in c-hook


Recommended Posts

Hi, I am working on a c-hook to do some edge curve creation on solids and chain them with operations so I managed so far to import an operation and add a single chains to it but I am not sure if I need to call append_chain after add_curve_to_chain, I would really apprectiate it if anyone could help me. I will include an example of the function I used to add single chains.

void ChainAll(ent &entity12, CHAIN &pChain, CHAIN_ENT * &ce, chain_manager_info &cmi, int &int1, int &leveltocheck)
{
	if (entity12.level == leveltocheck)
	{
		short sn = 0;
		add_curve_to_chain(&entity12, sn, false, SELECT_BIT, &pChain, &ce, -1);

		bool succf1;

		cmi.chns = &pChain;

		cmi.mode = CHNMGR_ADD;

		cmi.op_idn = int1;

		chain_manager(&cmi, CHNMGR_ADD, &succf1);

	}
}

//it is used inside this for loop
chain_manager_info cmi;
	memset(&cmi, 0, sizeof(chain_manager_info));
	for (; ; )
	{
		get_ent(&ptr4, &e_ptr12, &entity12, ALIVE_BIT,
			P_ID | L_ID | A_ID | S_ID | SURF_ID | SOLID_ID | SPLINE_ID | N_ID | W_ID | D_ID,
			&bSuccf11);
		{
			if (!bSuccf11) // No more ents
			{
				break;
			}
			if (bSuccf11)
			{
				if (entity12.level == 1250)
				{
					
					double depth3;
					bool viewok3;
					short view3 = 0;
					find_view_from_ent(&entity12, &view3, &depth3, &viewok3, false);
					p_3d p3d3 = entity12.u.ar.c;
					p_3d pt_out3;

					view_to_view(p3d3,
						view3,
						1,
						pt_out3);
					for (long j3 = 0; j3 < count2; j3++)
					{
						/*bool msgok1 = true;
						char message1[5000];
						sprintf_s(message1, "x : %lf y : %lf z : %lf x : %lf y : %lf z : %lf", pt_out3[0], pt_out3[1], pt_out3[2], entvectxbottom[j3], entvectybottom[j3], entvectzbottom[j3]);
						MessageBox(NULL, msgok1 ? message1 : "Operation Failed", "CmdUnit", MB_OK);*/
						if (pt_out3[0] == entvectxbottom[j3] && pt_out3[1] == entvectybottom[j3])
						{
							bool bSuccf12;
							entity14 = entity12;
							e_ptr14 = e_ptr12;
							delete_ent(e_ptr14, false, false, false, false, true);
							store_ent(&entity14, &e_ptr14, ALIVE_BIT, MC_BLACK, 1875, main_attrib, &bSuccf12);
							break;
						}

					}
					
				}
				if (entity12.level == 1750)
				{
					double depth4;
					bool viewok4;
					short view4 = 0;
					find_view_from_ent(&entity12, &view4, &depth4, &viewok4, false);
					p_3d p3d4 = entity12.u.ar.c;
					p_3d pt_out4;
					
					view_to_view(p3d4,
						view4,
						1,
						pt_out4);
					for (long j4 = 0; j4 < count1; j4++)
					{
						if (pt_out4[0] == entvectxtop[j4] && pt_out4[1] == entvectytop[j4])
						{
							bool bSuccf14;
							entity15 = entity12;
							e_ptr15 = e_ptr12;
							delete_ent(e_ptr15, false, false, false, false, true);
							store_ent(&entity15, &e_ptr15, ALIVE_BIT, MC_BLACK, 1375, main_attrib, &bSuccf14);
							break;
						}
					}
				}
				int vl1 = 1375;
				int int1 = 1;
				ChainAll(entity12, pChain, ce, cmi, int1,vl1);
				int vl2 = 1375;
				int int2 = 2;
				ChainAll(entity12, pChain, ce, cmi, int2, vl1);
			}
		}
	}

 

Link to comment
Share on other sites

Please always tell us what version of Mastercam!

It appears you’re are wanting to create a Chain “directly” from entities, without using any “select a chains” functionality?

If so, look at this code snippet.

/// <summary> Construct a Chain from the supplied list of entities. </summary>
/// <param name="entities"> The (in order!) line and/or arc entities. </param>
/// <returns> The new chain if successful, else null. </returns>
CHAIN *CreateChain (std::vector<ent> &entities)
	{
	CHAIN *chain;
	short err = alloc_chain (&chain, FALSE /* partial*/);
	bool result = (err == 0 && chain != nullptr);

	if (result)
		{
		CHAIN_ENT *last_chain_ent = nullptr;
		for (auto &entity : entities)
			{
			short errCode = add_curve_to_chain (&entity, 0, TRUE, 0, chain, &last_chain_ent);
			if (errCode != CHAIN_OK) // bail out !
				{
				result = false;
				break;
				}
			}
		}

	return (result ? chain : nullptr);
	}

 

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