Sign in to follow this  
byte

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.

Share this post


Link to post
Share on other sites
Posted (edited)

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
  • Thanks 1

Share this post


Link to post
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. 

Share this post


Link to post
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) {...}

 

  • Thanks 1

Share this post


Link to post
Share on other sites

It says gt=> Mastercam.Database.Geometry 😕

Share this post


Link to post
Share on other sites

If you could show me adding arcs to an operation in c++ that might be better. I don't know why Im having trouble.

Share this post


Link to post
Share on other sites

Hi Roger,

I am very sorry, I had a typo

 auto gt = selectedEnts-> GetType() 
//instead of 
auto gt = selectedEnts[i]->GetType() 

 

Share this post


Link to post
Share on other sites

Thank you for the help I see the result now.

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