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:

How to find type of curve geometry in c++/cli


Recommended Posts

I'm having trouble figuring out how to look for different types in curve geometry array in c++/cli .net type :

 auto slctedents = Mastercam::Support::SearchManager::GetSelectedGeometry();

		if (slctedents->Length > 0)
		{
			// Iterate through each wireframe entity 
			for (auto i = 0; i < slctedents->Length;i++)
			{
				if (slctedents[i]->GetType() == Mastercam::Curves::ArcGeometry::typeid)
				{
					auto arc = gcnew  Mastercam::Curves::ArcGeometry;

				}
			}
		}

This is not correct obviously, I'm a bit stuck.

Link to comment
Share on other sites

Try this.

/// <summary> Get the selected wireframe geometry by type. </summary>
///
/// <param name="points"> [out] The points. </param>
/// <param name="lines">  [out] The lines. </param>
/// <param name="arcs">   [out] The arcs. </param>
void SelectedWireframeGeometryByType (
	System::Collections::Generic::List<Mastercam::BasicGeometry::PointGeometry ^> ^points,
	System::Collections::Generic::List<Mastercam::Curves::LineGeometry ^> ^lines,
	System::Collections::Generic::List<Mastercam::Curves::ArcGeometry ^> ^arcs)
	{
	auto pointType = Mastercam::BasicGeometry::PointGeometry::typeid;
	auto lineType = Mastercam::Curves::LineGeometry::typeid;
	auto arcType = Mastercam::Curves::ArcGeometry::typeid;

	auto selectedEnts = Mastercam::Support::SearchManager::GetSelectedGeometry ();

	// Iterate through each wireframe entity 
	for (auto i = 0; i < selectedEnts->Length; i++)
		{
		auto gt = selectedEnts[i]->GetType ();
		if (gt == pointType)
			{
			// dynamic_cast here is like the "as" keyword in C#
			points->Add (dynamic_cast<Mastercam::BasicGeometry::PointGeometry ^> (selectedEnts[i]));
			}
		else if (gt == lineType)
			{
			lines->Add (dynamic_cast<Mastercam::Curves::LineGeometry ^> (selectedEnts[i]));
			}
		else if (gt == arcType)
			{
			arcs->Add (dynamic_cast<Mastercam::Curves::ArcGeometry ^> (selectedEnts[i]));
			}
		}	
	}

void TestGetByType ()
	{
	auto points = gcnew System::Collections::Generic::List<Mastercam::BasicGeometry::PointGeometry ^> ();
	auto lines = gcnew System::Collections::Generic::List<Mastercam::Curves::LineGeometry ^> ();
	auto arcs = gcnew System::Collections::Generic::List<Mastercam::Curves::ArcGeometry ^> ();

	SelectedWireframeGeometryByType (points, lines, arcs);
	auto msg = System::String::Format ("{0} - Points\n{1} - Lines\n{2} - Arcs", points->Count, lines->Count, arcs->Count);
	System::Diagnostics::Debug::WriteLine (msg);

	// Using the 'native' MessageBox here just so that we don't need to reference System::WindowsForms.
	MessageBox (nullptr, CString (msg), _T ("Wireframe Geometry"), MB_ICONINFORMATION);
	}

 

Edited by Roger Martin from CNC Software
Link to comment
Share on other sites

Hi Roger,

The example compiles, however, It gives me a warning "no instance of constructor "System::Collections::Generic::List<T>::List[with T=Mastercam::Curves::ArcGeometry ^] matches the argument list, and it returned zero on all the results even with selected geometry, however it gives a bad error if I select solids or non wireframes so..I think its doing something. 

Link to comment
Share on other sites

Pete,

I have no idea what you have going on here. The constructor error make no sense.

To be sure that the code in the previous post was not mangled, I copied that code directly from that post to a C++/CLI project (that references the NETHook API).

And... It builds, runs and produces the expected result. Tested in Mastercam 2018 and 2020.

Expanding it out to include processing of Surfaces/Solids may be a bit more involved.

To see exactly what the "type" you're dealing with, add some diagnotics.

auto gt = selectedEnts->GetType ();
System::Diagnostics::Debug::WriteLine ("gt=> " + gt->ToString ());
if (gt == pointType) {...}

 

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