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:

Accessing non reserved planes with C++ SDK


Recommended Posts

Hello again,

 

trying to access Mastercam Plane which is not one of the reserved, i got Always errors. Don't know why.

This code works:

const Plane *arcPlane = Planes.GetPlanePtrByID(1); 				//get-Plane 1==TOP
swprintf(sztext, L"Name of Plane %s\n", arcPlane->GetName()); 	//tell me name, WORKS and gives TOP

 

and this didn't work with existing plane No. 22. plane 22 is in planemanager visible and ok but

this code CRASHES:

const Plane *arcPlane = Planes.GetPlanePtrByID(22);				//get Plane No. 22
swprintf(sztext, L"Name of Plane %s\n", arcPlane->GetName());	//-----------------------CRASH

 

Do you know why?

Thanks in advance for any help or hint.

Link to comment
Share on other sites

Hi,

 

Try this instead add the name CustomPlane in the mastercam plane dialog to your plane then use this code

		auto plane = Planes.GetPlanePtrByName("CustomPlane");
	char message[5000];
	bool success = false;
	if (plane != nullptr)
	{
		
		sprintf_s(message, "Plane Color :%d ", plane->GetColor());
		success = true;
	}
	MessageBox(NULL, success ? message : "Operation Failed", "Mastercam", MB_OK);

Then change the color of your plane and you will see the result change.

Link to comment
Share on other sites
7 hours ago, Norbert Dalhoff said:

Hello again,

 

trying to access Mastercam Plane which is not one of the reserved, i got Always errors. Don't know why.

This code works:


const Plane *arcPlane = Planes.GetPlanePtrByID(1); 				//get-Plane 1==TOP
swprintf(sztext, L"Name of Plane %s\n", arcPlane->GetName()); 	//tell me name, WORKS and gives TOP

 

and this didn't work with existing plane No. 22. plane 22 is in planemanager visible and ok but

this code CRASHES:


const Plane *arcPlane = Planes.GetPlanePtrByID(22);				//get Plane No. 22
swprintf(sztext, L"Name of Plane %s\n", arcPlane->GetName());	//-----------------------CRASH

 

Do you know why?

Thanks in advance for any help or hint.

What version of Mastercam are you using?  In Mastercam 2020 the GetPlanePtrByID() function works as expected in my testing.

Can you share a file?

 

C++,

Why are you using a char array?  And why so big?  5000 bytes of continuous memory seems excessive.

Link to comment
Share on other sites
3 minutes ago, Zaffin said:

In Mastercam 2020 the GetPlanePtrByID() function works as expected in my testing.

It wasn't working on my 2018 for user defined planes last time I checked, but the GetPlanePtrByName("") worked okay, hmmm. 

Link to comment
Share on other sites
  • 2 weeks later...
3 hours ago, Norbert Dalhoff said:

Hello peter~ and Zaffin,

thanks for your replies. My Mastercam-Version is 2019 (21.0.28020.0).

 

I think I see what's going on here; by non-reserved plane you mean a view that doesn't appear in the view manager?  For example the view of a rotated arc

You should be able to get the arc's view matrix by using the get_view_matrix function.

Link to comment
Share on other sites

Planes

Always remember that -> View ID != Plane ID
What you see in the Planes Manager are the “named” Planes.
An arc does not necessarily have a “named” Plane associated with it!
If you pass a valid Plane ID, you will get the Plane.
It appears that that you are probably passing the “View Number” from the arc entity.
const Plane *arcPlane = Planes.GetPlanePtrByID(22);      //get Plane No. 22
That’s either - not going to retrieve anything, and the acrPlane will be null,
(Which you should always check before attempting to dereference a pointer.)
or you could possibly get Plane that is not associated with the view that arc in is.
To get a “named” Plane you pass the “ID”, which for the View Number “22” you show would be “52”

Link to comment
Share on other sites

This will work in Mastercam 2019

This exact  code will not be valid for Mastercam 2020/2021.

It will very similar in 2020/2021, but getting the list of Planes to search is done differently.

 

/// <summary> Gets the Plane ID of the "named" Plane for a View number. </summary>
///
/// <remarks> A View# may not necessarily have an associated "named" Plane! </remarks>
///
/// <param name="viewNumber"> The View Number to search for. </param>
///
/// <returns> The Plane ID (0 = no match found). </returns>
long GetPlaneID (short viewNumber)
	{
	auto id = 0;
	PLANES_NAMED_PTR_ARRAY planesArray;
	auto count = Planes.GetPlanes (planesArray);
	for (auto i = 0; i < count; ++i)
		{
		auto plane = planesArray.GetAt (i);
		if (plane->GetShortViewNo () == viewNumber)
			{
			id = plane->GetLongID ();
			break;
			}
		}

	(id > 0)
		? TRACE (_T ("View#:%i matches named Plane ID#:%i"), viewNumber, id)
		: TRACE (_T ("No named Plane match found for View#:%i"), viewNumber);

	return id;
	}

 

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