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:

NETHook import geometry + operation


Recommended Posts

Can the NET-Hook API import geometry from another .mcx- file?

Similar to the File Merge/Pattern in Mastercam, but programmatic and also importing operations.

 

The goal is to import from a library of geometry+operation components and place them within the current file.

 

 

The only method I see using the API is

FileManager.Open("Component.mcx-9");

to open a file then read the data I want into memory, reopen the initial file, and add the items to database.

This has drawbacks (I assume it resets the undo stack, for one) and is not sufficient.

 

An alternate solution is to store component data in a file format I can parse myself. Then read it and create the geometry and operations accordingly. If possible, though, I would prefer to use the API and mcx files.

 

 

 

Currently using C#, developing for Mastercam 9.

Link to comment
Share on other sites

The FileManager.Open method has a number of overloads, you can pass in a flag to merge the file with the existing file. The namespace Mastercam.Operations.OperationsManager.ImportOperation allows you to import operations from an external file or operations library. I think that between the two methods you should be able to accomplish what you are after.

 

Feel free to reply if you need further help.

 

 

 

Can the NET-Hook API import geometry from another .mcx- file?

Similar to the File Merge/Pattern in Mastercam, but programmatic and also importing operations.

 

The goal is to import from a library of geometry+operation components and place them within the current file.

 

 

The only method I see using the API is

FileManager.Open("Component.mcx-9");

to open a file then read the data I want into memory, reopen the initial file, and add the items to database.

This has drawbacks (I assume it resets the undo stack, for one) and is not sufficient.

 

An alternate solution is to store component data in a file format I can parse myself. Then read it and create the geometry and operations accordingly. If possible, though, I would prefer to use the API and mcx files.

 

 

 

Currently using C#, developing for Mastercam 9.

Link to comment
Share on other sites

You could certainly use a layering scheme before hand for your files or implement a scheme for each file you merge and move geometry around. 

 

This example opens the first file and moves everything to level 500, the next file is merged and moved to level 501. 

           var file = @"C:\Users\Mick George\Documents\my mcamx9\mcx\T.mcx-9";
            var fileToMerge = @"C:\Users\Mick George\Documents\my mcamx9\mcx\T2.mcx-9";

            // Open 
            if (FileManager.Open(false, file, false))
            {
                // Move everthing currently open to level 500
                var geos = Mastercam.Support.SearchManager.GetGeometry().ToList();
                foreach (var geo in geos)
                {
                    geo.Level = 500;
                    geo.Commit();
                }

                // Merge
                if (FileManager.Open(false, fileToMerge, true))
                {
                    // Grab everything not on level 500
                    var allGeometries = Mastercam.Support.SearchManager.GetGeometry().ToList().Where(geo => geo.Level != 500);

                    // Move to 501
                    foreach (var geo in allGeometries)
                    {
                        geo.Level = 501;
                        geo.Commit();
                    }
                }
            }

            GraphicsManager.ClearColors(new GroupSelectionMask(true));
            GraphicsManager.FitScreen();
  • Like 1
Link to comment
Share on other sites
  • 2 weeks later...

Am I calling GetOpGroupDataInExternalFile correctly?

Mastercam.Support.Types.ExternalOpsFileData[] opData = null;
Mastercam.Support.Types.ExternalGroupsFileData[] groupData = null;
bool success = SearchManager.GetOpGroupDataInExternalFile(@"C:\Users\Samuel Hanson\Documents\my mcamx9\mcx\Components\rect.mcx-9", ref groupData, ref opData);

It always returns false.

Link to comment
Share on other sites

After much head scratching and another set of eyes on the code I finally determined what the issue was and it has to do with the variable initialization.

 

Note: You must have a machine group active in Mastercam or this code will still fail. You can either create a machine group prior to thecode or test for an existing machine group.

Mastercam.Support.Types.ExternalOpsFileData[] opData = null;
Mastercam.Support.Types.ExternalGroupsFileData[] groupData = null;
bool success = SearchManager.GetOpGroupDataInExternalFile(@"C:\Users\Samuel Hanson\Documents\my mcamx9\mcx\Components\rect.mcx-9", ref groupData, ref opData);


// This should have the variables initialized to at least one index.

var opData = Mastercam.Support.Types.ExternalOpsFileData[0];
var groupData = Mastercam.Support.Types.ExternalGroupsFileData[0];
bool success = SearchManager.GetOpGroupDataInExternalFile(@"C:\Users\Samuel Hanson\Documents\my mcamx9\mcx\Components\rect.mcx-9", ref groupData, ref opData);
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...