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:

How to post selected operations


Recommended Posts

Hi,

 

another problem: how can I post selected operations?

 

With this code nothing happend:

 

    Public Shared Function PostOp(ByVal ncFilePath As String, ByVal boEdit As Boolean) As Boolean

       Dim opInfos1 As Mastercam.Database.Operation
       Dim flag_OP_Selected As Boolean
       Dim flag_OP_Dirty As Boolean

       Dim OpList() As Mastercam.Database.Operation = SearchManager.GetOperations()
       Dim op As Mastercam.Database.Operation

       For Each op In OpList

           opInfos1 = op

           flag_OP_Selected = opInfos1.Selected
           flag_OP_Dirty = opInfos1.Dirty

           If (flag_OP_Selected And Not flag_OP_Dirty) Then
               PostOp = opInfos1.Post(ncFilePath, boEdit)
           End If
       Next op

   End Function

Link to comment
Share on other sites

Hi,

 

another problem: how can I post selected operations?

 

With this code nothing happend:

 

    Public Shared Function PostOp(ByVal ncFilePath As String, ByVal boEdit As Boolean) As Boolean

       Dim opInfos1 As Mastercam.Database.Operation
       Dim flag_OP_Selected As Boolean
       Dim flag_OP_Dirty As Boolean

       Dim OpList() As Mastercam.Database.Operation = SearchManager.GetOperations()
       Dim op As Mastercam.Database.Operation

       For Each op In OpList

           opInfos1 = op

           flag_OP_Selected = opInfos1.Selected
           flag_OP_Dirty = opInfos1.Dirty

           If (flag_OP_Selected And Not flag_OP_Dirty) Then
               PostOp = opInfos1.Post(ncFilePath, boEdit)
           End If
       Next op

   End Function

 

 

Im more of a VB/VBA/VBS guy, so maybe Im misunderstanding the nuances of the .NET booleans ... but it looks like you are checking for the DIRTY status, ("flag_OP_Dirty = opInfos1.Dirty")

and only posting code if the dirty status is NOT what you just checked it to be? ("And Not flag_OP_Dirty")

 

In other words, if the dirty flag comes back as FALSE, you only post code if its TRUE, but if the dirty flag comes back TRUE, you only post if is FALSE ?

Shouldnt the logic be something more like "If (flag_OP_Selected And flag_OP_Dirty = False) Then" ....

Link to comment
Share on other sites

Do you really even want to checking the 'dirty' flag ?

 

Posting Operations with a NETHook (C#) ->

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Text;

using Mastercam.App;
using Mastercam.App.Types;
using Mastercam.Support;
using Mastercam.Database;
using Mastercam.Operations;

namespace NetHookApp
{
   public class NETHOOK : Mastercam.App.NetHook2App
   {
       // NETHook Entry Point
       public override Mastercam.App.Types.MCamReturn Run(int param)
       {
           MCamReturn result = MCamReturn.NoErrors;
           try
           {
               // Get the selected operations
               Operation[] selectedOps = SearchManager.GetOperations(true);
               MessageBox.Show("Posting [" + selectedOps.Length.ToString() + "] operations!", "PostOperations", MessageBoxButtons.OK);
               // Use 'default' destination path
               //OperationsManager.PostOperations(selectedOps); 

               // Use specified destination path
               string user = Mastercam.IO.SettingsManager.UserDirectory;
               string NCDestinationPath = System.IO.Path.Combine(user, @"mill\nc\");
               OperationsManager.PostOperations(selectedOps, NCDestinationPath);    

               // Just post them ALL !
               //OperationsManager.PostAllOperations(NCDestinationPath, true); 
           }
           catch (Exception ex)
           {
               MessageBox.Show(ex.Message, "UnHandled Exception: " + ex.Source,
                               MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
               result = MCamReturn.ErrorOccurred;
           }
           return result | MCamReturn.AppUnloaded;
       }

   } // class NETHOOK
}

Link to comment
Share on other sites

Do you really even want to checking the 'dirty' flag ?

 

Posting Operations with a NETHook (C#) ->

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Text;

using Mastercam.App;
using Mastercam.App.Types;
using Mastercam.Support;
using Mastercam.Database;
using Mastercam.Operations;

namespace NetHookApp
{
   public class NETHOOK : Mastercam.App.NetHook2App
   {
       // NETHook Entry Point
       public override Mastercam.App.Types.MCamReturn Run(int param)
       {
           MCamReturn result = MCamReturn.NoErrors;
           try
           {
               // Get the selected operations
               Operation[] selectedOps = SearchManager.GetOperations(true);
               MessageBox.Show("Posting [" + selectedOps.Length.ToString() + "] operations!", "PostOperations", MessageBoxButtons.OK);
               // Use 'default' destination path
               //OperationsManager.PostOperations(selectedOps); 

               // Use specified destination path
               string user = Mastercam.IO.SettingsManager.UserDirectory;
               string NCDestinationPath = System.IO.Path.Combine(user, @"mill\nc\");
               OperationsManager.PostOperations(selectedOps, NCDestinationPath);    

               // Just post them ALL !
               //OperationsManager.PostAllOperations(NCDestinationPath, true); 
           }
           catch (Exception ex)
           {
               MessageBox.Show(ex.Message, "UnHandled Exception: " + ex.Source,
                               MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
               result = MCamReturn.ErrorOccurred;
           }
           return result | MCamReturn.AppUnloaded;
       }

   } // class NETHOOK
}

 

Again, Im not sure how things are, internally, with CHooks, but in VBS, I couldnt get information about the Op that would normally be available - if the Op wasnt dirty (and hiding the fact that it wouldnt rebuild normally)

Link to comment
Share on other sites

I don't know how useful this is, but it certainly works.

 

I have 3 operations selected, and 1 op (in this case the 2nd op) in the selected ops is "dirty".

Running this NETHook function it will post the 1st non-Dirty operation and then display the NC in the editor.

It will skip the 2nd operation since it is "dirty"

It will post the next non-Dirty (the 3rd op in the selected list) operation and then display the NC in the editor.

 

Yes, it's C# code.

I leave it to you to convert to VB is you must.

 

       /// <summary>
       /// PostSelectedAndNotDirtyOperations
       /// </summary>
       /// <param name="NCDestinationPath"></param>
       /// <param name="EditNC"></param>
       /// <returns>The number of operations that where posted</returns>
       private int PostSelectedAndNotDirtyOperations(string NCDestinationPath, bool EditNC)
       {
           int postedOpCount = 0;
           Operation[] selectedOps = SearchManager.GetOperations(true); // Get only 'selected' ops            
           foreach (Operation op in selectedOps)
           {
               if (op.Dirty == false)
               {
                   op.Post(NCDestinationPath, EditNC);
                   postedOpCount++;            
               }              
           }
           return postedOpCount;
       }

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