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:

NET-Hook: Tell one solid from another.


Recommended Posts

Hello,

 

Could anyone point me please how I could tell one solid from another in .NET code?

 

I have a part file with several block solids which have different names.

 

I'm trying to manipulate with these solids through NET-Hook, but I could not tell one solid from another (I didn't find "name" or "database id" properties in SolidGeometry class or it's base classes).

 

// Get all solids in the part file

SolidGeometry[] parts = SearchManager.GetSolidGeometry();

 

// Loop through all solids

foreach (SolidGeometry part in parts)

{

BlockSolid block = part as BlockSolid;

 

// Here I want to find a solid with the special name, but how?

 

// I would like to have something, like:

// if (block.name == "some_name")

// {

// do something!

// }

}

Link to comment
Share on other sites

It's clear, thanks for the reply.

 

Roger,

 

Could you please send me the pdf document which describes how to set up a C-Hook project in Visual Studio 2010?

 

Unfortunately, my local dealer just gave me the SDK and he knows nothing about additional documentation on how "to prepare" C-Hooks.

 

It would be nice to have any example C-Hook code (Generally I need a guide that could give me clear answers from the stage of setting up a project to the stage of working dll feature).

 

Thanks.

Link to comment
Share on other sites

When you install the SDK, it installs a CHookWizard Project Template into Visual Studio.

That's what you want to use to get started.

 

You'll find the CHookWizard template here in VS ->

The X5 SDK (for VS2008) Create->New Project, now select the template.

Select Other Languages ->C++ and select the MFC "project type" item.

On the right (in Installed Templates) you should see the CHookWizard.

For the X6 SDK (when it's released) the Wizard is essentially the same (rebuilt to work with VS2010)

but the location of the CHookWizard has changed. It's no under Visual C++ -> Mastercam.

 

For creating a CHook that runs in X5, you must use the (v90) "toolset" in Visual Studio 2008.

For creating a CHook that runs in X6, you must use the (v100) "toolset" in Visual Studio 2010.

*And this must be the "professional" (or higher) version of Visual Studio.

 

If you have both 2008 and 2010 installed you can use VS_2010 "as your IDE" and create CHooks that run in X5,

by setting the Platform Toolset (C++ project, General settings) to -> v90.

This tells Vusual Studio 2010 to use the VS 2008 compiler, etc on the system when building the project.

Link to comment
Share on other sites
  • 4 weeks later...

Thank you very much for the information. It works fine.

 

I'm going to write some extensions for MasterCAM using WPF GUI + .NET libraries. NETHook2_0.dll is the way to start but as it doesn't provide all the necessary information

I need to wrap some low-level c-functions in order to obtain necessary data (such as to get the object ID after it has been built).

 

Could you please give me some hints:

 

1. how to wrap c-functions correctly in order to call them from .NET code (should I create COM-objects for the low-level functionality provided by CHook SDK and then call them from my .NET code)?

2. will it be easy to do?

3. any traps?

 

Thanks.

Link to comment
Share on other sites

Calling functions in C++ (unmanaged) from .NET (managed)

 

Depending on what data is involved (in the call), calling an exported function within Mastercam from a NETHook, I would suggest using P/Invoke interop., as it's fairly simple.

 

If marshaling the data across the managed/unmanaged boundary is just too involved, instead of P/Invoke, you could create a C++/CLI DLL layer between the .NET and the unmanaged (C++) side.

 

A very useful tool for setting up data for marshaling is...

P/Invoke Interop Assistant -> http://clrinterop.codeplex.com/releases/view/14120

*Just be sure to alter any Mastercam typedef’d variable types before running it thru this utility

It doesn’t know what these Mastercam types are: MC_BOOL, or _long, _short, etc.

Link to comment
Share on other sites
  • 11 years later...
On 6/17/2023 at 8:19 AM, Tariq Aslam said:

is there a possibility or a method to get names of different solids in a single part file and then get their dimensions also. Please help me in this regards.

Cheers

Tariq

Hi Tariq,

Here is a code sample of getting the min point of the solids bounding box and the description, you should get a result in the event logger like in the picture below

	//dynamic memory allocation on the heap
	NoStackEnt(entity)
		//the start of the database
		auto eptr = db_start;
	//loop while valid pointer
	while (eptr != nullptr)
	{
		//get the entity safely
		if (get_ent_from_eptr(eptr, &entity) == 0)
		{
			//check the alive bit anyway for safety, no undelete stack ents allowed
			if (sel_bit_is_on(entity.sel, ALIVE_BIT))
			{
				//check for parasolid
				if (entity.id == SOLID_ID)
				{
					//let;s make a shared pointer to a cstring because yolo
					auto message = std::make_shared<CString>();
					if (message != nullptr)
					{
						//format the string with some info from the solid
						message->Format(L"solid description -> %s \n min solidmin x -> %lf \n solidmin y -> %lf \n solidmin z -> %lf",
							entity.u.sld.desc,//the description
							entity.u.sld.min[0],//min x of bounding box
							entity.u.sld.min[1], // min y of bounding box
							entity.u.sld.min[2]); // min z of bounding box
						//print the information to the EVENT LOGGER
						LogMastercamEvent(MSGCLASS_INFORMATION, L"", message->GetBuffer());
					}
				}
			}
		}
		//get the next element from the linked list of all entities in the file
		eptr = eptr->next;
	}

image.thumb.png.022a4371eb7fdbf5ade7f102e3ba3fba.png

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