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:

Creating tool paths with nethook


Recommended Posts

Hello all,

I have been exploring the use of nethooks using visual basic to automate some of our common functions. Currently it looks fairly simple to automate functions such as creating geometries and setting gui parameters and such. The thing I can't figure out, however, is how I would create the various milling tool paths using selected geometry and tools from our library. For example: I would like to select all features on a given layer and then create a pocketing tool path for all the features (assuming they are all closed chains), using 1/4 endmill from alum6061 library.

Is something like this possible using a vb nethook? If so, are there any examples or white papers that could get me started? I'm using visual studio 2005 standard for development.

Thanks very much,

David

Link to comment
Share on other sites

I dont happen to have a VB sample but here is a C# example that should be easy enough to convert over to VB. Feel free to post questions to this thread.

 

code:

 

//Create a pointer to our saved route operation

// operations == fullpath to your *.operations file opId == the op id of the operation you want to use

Mastercam.COperationRef opRef = COperationRef.ImportFromFile(operations, opId);

 

//Does operation exisit in the operations file?

if ( opRef == null )

throw new Exception("RouteLevel::COperationRef.ImportFromFile(" + operations + "," + opId.ToString() + ") not found!!!");

 

//Store original toolside

CutterCompType originalComp = opRef.CutterComp;

 

//Do we need to reverse the chain to set the correct toolside?

bool reverseChain = ( ConventionalRoute && ( originalComp == CutterCompType.CutterCompLeft ) )

|| ( !ConventionalRoute && ( originalComp == CutterCompType.CutterCompRight ) );

 

ArrayList chainrefs = new ArrayList();

 

//Chain all on this level

if ( !Mastercam.Chain.ChainAll(true, true, thisLevel, true, chainrefs) )

throw new Exception("Call to RouteLevel::ChainAll failed on level " + thisLevel + "!!!");

else

{

if ( Chain.ChainManager(opRef, chainrefs, 1, 0) )

{

if ( reverseChain )

foreach ( CChainRef cr in chainrefs )

{

if ( !Chain.ReverseChain(cr) )

throw new Exception("Call to RouteLevel::Chain.ReverseChain() failed on level " + thisLevel + "!!!");

}

 

if ( !Toolpath.RegenOp(opRef) )

throw new Exception("Call to RouteLevel::RegenOp() on level " + thisLevel + " failed!!!");

}

else

throw new Exception("Call to RouteLevel::Chain.ChainManager() on level " + thisLevel + " failed!!!");

}

 

if ( chainrefs.Count > 0 )

{

if ( !Mastercam.Chain.FreeChains(chainrefs) )

throw new Exception("Call to RouteLevel::FreeChains() on level " + thisLevel + " failed!!!");

}

Link to comment
Share on other sites

This was a really nice and helpful example.

 

I tried to use it to make a lathe operation. After a day of trying and retrying I managed to produce this:

code:

string pathMC = Mastercam.GUI.GetMCRootDir();

string pathAL = String.Concat(pathMC, "chooksAutolathe");

string operations = String.Concat (pathAL, "AUTOLATHE.OPERATIONS");

string opId = "OD_ROUGH_R";

COperationRef opRef = COperationRef.ImportFromFile(operations, opId);

This code works only after I have already created (and deleted) a lathe operation in Operation Manager. If I start with a new file, I get the exception message: "Attempted to read or write protected memory. This is often an indication that other memory is corrupt." Nevertheless, the operation is created.

 

Please, help me further in creating a lathe operation and defining its parameters in C#.

Thank you very much.

Link to comment
Share on other sites

Now I have succesfully added these more lines from the Mick's code from the first reply of this Topic:

code:

//Does operation exisit in the operations file?

if ( opRef == null )

throw new Exception("RouteLevel::COperationRef.ImportFromFile(" + operations + "," + opId.ToString() + ") not found!!!");

//Store original toolside

CutterCompType originalComp = opRef.CutterComp;

The next lines are:

code:

//Do we need to reverse the chain to set the correct toolside?

bool reverseChain = ( ConventionalRoute && ( originalComp == CutterCompType.CutterCompLeft ) ) || ( !ConventionalRoute && ( originalComp == CutterCompType.CutterCompRight ) );

I roughly understand the meaning of these lines, but I don't understand how this code works. Therefore, please explain the term: "ConventionalRoute".

 

Thank you.

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

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