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:

Regenerate and Post with multi-threading enabled


Recommended Posts

I am trying to regenerate and post a number of operations from a C# NET-Hook.

 

I iterate through each operation, regenerate if necessary, then start the post processor.

 

If multi-threading is enabled sometimes the regeneration is not completed before the post processor is initiated. When that happens it doesn't post properly. Turn multi-threading off and everything works perfect but slower.

 

How can I make the post processor wait until operations are finished regenerating?

string pathNC = Mastercam.IO.SettingsManager.UserDirectory+@"Router\NC\new";

Mastercam.Database.Operation[] selectedOps = Mastercam.Support.SearchManager.GetOperations(false);

foreach (var op in selectedOps)
{
   op.NCIName = Mastercam.IO.SettingsManager.UserDirectory + @"Router\NCI\cake.nci";
   op.Commit(false);
   if (op.Dirty)
   {
      op.Regenerate();
   }
}

// System.Threading.Thread.Sleep(10000); //Wait... but apparently that locks up the regeneration too.

foreach (var op in selectedOps)
{
   op.Retrieve();
   if (op.Dirty)
   {
      System.Windows.Forms.MessageBox.Show("Error - dirty operation");
      return;
   }
}

Mastercam.Operations.OperationsManager.PostOperations(selectedOps, pathNC, true, false); 

Mastercam X9 Router, C# NET-Hook

Link to comment
Share on other sites

In X9, in a NET-Hook you cannot really know when all of the operations have completed (or not) .

 

In Mastercam 2017 there will be a new Notify method jut for this purpose ->

 

public override MCamReturn MultiThreadOpStateNotify(int opId, MCamMultiThreadOpState state)
{
    string status = "Unknown";
    switch (state)
    {
        case Mastercam.App.Types.MCamMultiThreadOpState.Success:
            status = "Success";
            break;
        case Mastercam.App.Types.MCamMultiThreadOpState.Stopped:
            status = "Stopped";
            break;
        case Mastercam.App.Types.MCamMultiThreadOpState.Failed:
            status = "Failed";
            break;
    }
 
    MessageBox.Show(
        string.Format("opID: {0}\nState: {1}", opId, status), 
        "MultiThread Manager",
        MessageBoxButtons.OK, 
        MessageBoxIcon.Information);
 
    return Mastercam.App.Types.MCamReturn.NoErrors;
}
 
You'd make note of the opIDs that you submitted to be regenerated and then using the MultiThreadOpStateNotify method you can determine their status.
Link to comment
Share on other sites

Be aware that some operations (multi-axis drill comes to mind) require their geometry to be visible during regeneration. If the geometry is not visible it will throw an error, but then show the operation as having been regenerated rather than dirty as it should.

Yeah, that's bucked me in the futt a few times. I've got two where I make one view sheet with every level on before regen when I have multiaxis drill ops.

Link to comment
Share on other sites

Related,

The NC file is opening for editing even when I specify not to. Any ideas what might cause this?

public static bool regenAndPost(string fileName, bool onlySelected){
  //Regenerate toolpaths
  //...
  
  //Post
  Mastercam.Operations.OperationsManager.PostAllOperations(System.IO.Path.GetDirectoryName(fileName),false);
  return true;
} 
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...