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:

csharp and python-scripts-for-mastercam


Guest
 Share

Recommended Posts

This is a powerful new add in I created that allows you to access the NEThook_3.dll functions via a script (text) file. 

It also contains some c++ SDK functions that I will be updating gradually.

This is similar to the old vbscript api. A user interface is launched and scans the targeted files into a list view.

After that simply select the item in the list to run your script.

Download here - > Github

Link to comment
Share on other sites
11 hours ago, LeoC said:

Thank you for your contribution.

 

LeoC

I plan to add a code generating software to write scripts from a user interface dialog, it will be very fast coding then.

Link to comment
Share on other sites
4 hours ago, Zaffin_D said:

I think this is a great idea.

However I couldn't get it to work in 2020.  Are you interested in any constructive feedback regarding the execution?

Yes, Zaffin, your suggestions are always welcome. 

It works for me on multiple pc's and bersions, is it  possible there are some files missing? Did you receive an error message either in the mclogr or messagebox?

Link to comment
Share on other sites

Would you check if the files need to be unblocked please? 

Right click -> Properties -> Unblock

The Source code. ->: This is our chook library.  -> This Is our Nethook Library . 

The .py files need to be located in a folder called scripts in the chook folder.The NetSDK.dll and NetSDK.ft files need to be in the chooks folder. The IronPython files need to be in the c:/program files/Mcam2018 folder.

In the project we should have access to all  of the functions in the Nethook_3.dll file & all the functions in the NetSDK.dll. 

Here is a simpler example of loading a file with python :

	//This is our Nethook Entry Point, Here we are calling a function from python

	//The function we are calling will in turn call functions from this dll file

	//

	public: virtual Mastercam::App::Types::MCamReturn RunScript(int param)

	{









		auto pythonengine = IronPython::Hosting::Python::CreateEngine();

		auto scope = pythonengine->CreateScope();

		pythonengine->ExecuteFile("script.py", scope);

		auto scriptrunner = scope->GetVariable("Scriptrunner");

		auto scriptrunnerInstance = pythonengine->Operations->CreateInstance(scriptrunner);

		auto result = pythonengine->Operations->InvokeMember(scriptrunnerInstance, "runscript");

		auto stringresult = dynamic_cast<System::String^>(result);



		return Mastercam::App::Types::MCamReturn::NoErrors;

	}



	};

}
          

 

Link to comment
Share on other sites
  • 1 month later...

There are notes on the github for where the files need to be stored in the mastercam folder, the iron python files are included in the download.

4 minutes ago, MachiningMike said:

Do you need to use IronPython?

Yes this works with Iron Python and the NEThook_3.dll

Link to comment
Share on other sites
  • 1 month later...
  • gcode pinned this topic
2 hours ago, zero_divide said:

I think it could be more valuable to create an interface with C-hook instead of net-hook. Net-hook, while easy to use, has big limitations. It also does not seem to be updated with support for all toolpaths.

Hi, we can create an interface with the c++ sdk to McPython via a c++/cli wrapper dll .

The advantage of using a nethook is that it supports multiple versions of mastercam.

 

Which operations were you hoping to create access? 

For which version of Mastercam please?

 

The topic of c++/cli dlls for the chook sdk operations is under discussion here -> 

 cli

The tutorial for creating c++/cli nethooks and downloading the sdk is here -> 

 

I will add the linking to the sdk tutorial shortly, thank you for the feedback.

Link to comment
Share on other sites
5 hours ago, zero_divide said:

I think it could be more valuable to create an interface with C-hook instead of net-hook. Net-hook, while easy to use, has big limitations. It also does not seem to be updated with support for all toolpaths.

Just for clarity the reason the chook interface takes longer is because Iron Python auto-magically inherents all the functionality of nethook_3.dll where-as the chook sdk functions have to be manually interfaced one by one.

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