Sps82zgz

Select operations and post them off with vbs

Recommended Posts

Hi everybody, I’m working with X4 and creating a vbs file script.

I’m wondering if it’s possible to select operations from the toolpaths and post them off using vbscript? I mean: I want to select some operations and automatically (using the vbs script) post them off (as if I were using toggle posting button).

Thanks 

Share this post


Link to post
Share on other sites
Guest
8 minutes ago, Sps82zgz said:

Hi everybody, I’m working with X4 and creating a vbs file script.

I’m wondering if it’s possible to select operations from the toolpaths and post them off using vbscript? I mean: I want to select some operations and automatically (using the vbs script) post them off (as if I were using toggle posting button).

Thanks 

X4 , that's a very old version.

Link to similar topic -> 

 

Share this post


Link to post
Share on other sites

Check your \Users\Public\Documents\shared mastercam_version\VB folder as I know we shipped several script examples and I know there was a couple post examples.

Share this post


Link to post
Share on other sites

This might help but it is old.

'////////////////////////////////////////////////////////////////////////////////
'//
'//        Author:   Mick George [email protected]
'//          Date:   11/11/2003 06:34 PM
'//     File Name:   NC for each OP.vbs
'//
'//   Description:   
'//
'//      Comments:   I should be home playing threewave... 
'//
'////////////////////////////////////////////////////////////////////////////////




' -- Start Script
Call Main()


' ////////////////////
' Sub Declaration
' ////////////////////
Sub Main()


Dim intOpsCount, intThisOp

' -- Pass a null string to tell MC we want this files ops
intOpsCount = GetOperationCount(vbNullString)       

If intOpsCount > 0 Then

    For intThisOp = 1 To intOpsCount
        
        If Not RunPost(intThisOp, GetOperationNameFromID(vbNullString, intThisOp)) Then      
           ShowString "Failed to create NC for operation " & intThisOp
        End If
    Next

Else
  ShowString "Nothing to post"
End If


End Sub

 

Another for groups, again might be helpful

'////////////////////////////////////////////////////////////////////////////////
'//
'//        Author:   Mick George [email protected]
'//          Date:   16/03/2004 01:35 PM
'//     File Name:   OperationGroups.vbs
'//
'//   Description:   Demo script that highlights various group functions
'//
'//      Comments:   SP2 req + March Main 2004 mcamvb CHook 
'//
'////////////////////////////////////////////////////////////////////////////////


'///////////////// My Constants /////////////////
Const GROUP_ALL        = -1
Const GROUP_GEOMETRY   = 0
Const GROUP_OPERATIONS = 1
Const SYSTEM_GROUP     = 2
Const SYSTEM_RESULT    = 3
Const GROUP_TOOLPATH   = 4

' -- Start Script
Call Main()         

' ////////////////////
' Sub Declaration
' ////////////////////
Sub Main()


   Dim idx, intGroup
  
   ' -- Get all groups                
   intGroup = GetGroupCount
   
   ' -- Do we have at least one?
   If intGroup = 0 Then 
      ShowString "No operation groups"
      Exit Sub
   Else
      ShowString intGroup & " operation groups found"
   End If        
   
   If askYesNo("List all group types?") = mcMSG_YES Then
        
       ' -- Iterate all groups                                   
       For idx = 1 To intGroup  
     
           Select Case GetGroupTypeFromNumber(idx)
           
                  Case GROUP_ALL: ShowString "Group #" & idx & " is of type group all" 
                  Case GROUP_GEOMETRY: ShowString "Group #" & idx & " is of type geometry group"    
                  Case GROUP_OPERATIONS: ShowString "Group #" & idx & " is of type operation group" 
                  Case SYSTEM_GROUP: ShowString "Group #" & idx & " is of type system group"      
                  Case SYSTEM_RESULT: ShowString "Group #" & idx & " is of type system result"     
                  Case GROUP_TOOLPATH: ShowString "Group #" & idx & " is of type group toolpath" 
          
           End Select
       Next   
   End If
                                     
   
   ' -- Iterate all groups                                   
   For idx = 1 To intGroup
      ' -- Echo their name
      ShowString GetGroupNameFromNumber(idx) 
      
      ' -- Rename groups
      If Not SetGroupNameFromNumber(idx, "My New Operation Group #" & idx) Then
         ShowString "Could not set operation group name for " & GetGroupNameFromNumber(idx)
      End If                        
                                
   Next        
   
   ' -- Create a temp group
   If CreateGroupFromName("Test Group") Then
      ' -- Delete it?
      If askYesNo("Delete new test group?") = mcMSG_YES Then
         If DeleteGroupFromName("Test Group") Then
            ShowString "Group Deleted"
         End If   
      End If 
      
   Else
     ShowString "Could not create Test Group but it was created??"     
   End If 
   
   
   intGroup = GetGroupCount     
   
   If intGroup = 0 Then 
      ShowString "No operation groups"
      Exit Sub
   Else    
      If intGroup = 1 Then
         ' -- We can't remove the only group
         ShowString "One group remains"
         Exit Sub
      End If
   
      ShowString intGroup & " operation groups found"
   End If        
   
   If askYesNo("Delete last operation group by number?") = mcMSG_YES Then
      ' -- Delete the last operation group
      DeleteGroupFromNumber intGroup
   
   End If   
   
   intGroup = GetGroupCount     
   
   If intGroup = 0 Then 
      ShowString "No operation groups"
      Exit Sub
   Else
      ShowString intGroup & " operation groups found"
   End If        
   
End Sub

 

And one more

'////////////////////////////////////////////////////////////////////////////////
'//
'//        Author:   Mick George [email protected]
'//          Date:   15/03/2004 09:30 AM
'//     File Name:   SetEveryOtherOpForPostingOff.vbs
'//
'//   Description:   Iterate all operations in current drawing, set every other
'//                  operation off for posting.
'//
'//      Comments:   Requires March Maintenance release
'//
'////////////////////////////////////////////////////////////////////////////////

' -- Start Script
Call Main()


' ////////////////////
' Sub Declaration
' ////////////////////
Sub Main()
    

Dim intOpCount, idx, intCount

' -- How many operations do we have?              
intOpCount = GetOperationCount(vbNullString)

' -- Test
If intOpCount = 0 Then ShowString "No operations in current drawing": Exit Sub  

' -- Initialize
intCount = 0

' -- Let's see how many operations are off before we do anything
For idx = 1 To intOpCount 

    If GetOperationPostingFromID(vbNullString, idx) Then
       intCount = intCount + 1
    End If     

Next        

' -- Test
If intCount  = 0 Then
   ShowString "All operations are set to post off"
Else
   ShowString intCount & " operations are currently set to posted on, we will now set all of them post off"
End If            

                            
' -- Turn off all ops first regardless if they are on or not
For idx = 1 To intOpCount

 If SetOperationSelectedFromID(vbNullString, idx, False) Then    
     If Not SetOperationPostingFromID(vbNullString, idx, False) Then
        ShowString "Could not turn off operation # " & idx
     End If
 End If
Next  
              
             
' -- Initialize
intCount = 0

' -- All operations should now be off, lets do a quick check
For idx = 1 To intOpCount 

    If GetOperationPostingFromID(vbNullString, idx) Then
       intCount = intCount + 1
    End If     

Next        

If intCount  = 0 Then
   ShowString "All operations are set to post off after call to SetOperationPostingFromID(FALSE)"
Else
   ShowString intCount & " operations are posted on!!??"
End If

intCount = 0

' -- Select every other operation 
For idx = 1 To intOpCount Step 2  

 If SetOperationSelectedFromID(vbNullString, idx, True) Then      
        
     If SetOperationPostingFromID(vbNullString, idx, True) Then
        ' -- Success
        intCount = intCount + 1
     Else
        ShowString "Could not set operation # " & idx & " off"
     End If
 End If
 
Next        

If intCount > 0 Then
   ShowString intCount & " operations are set to post off from " & intOpCount &  " total operations"
End If   
                       
' -- Post only what is not ghosted                       
'Call RunPostAll(GetPathOfThisScript, True)                       
    
    
    
End Sub

 

Share this post


Link to post
Share on other sites

Thanks guys for your help, and for wasting your appreciate time answering my question.

I have created my needed VB script, basing it on what you told me here, changing my original idea.

Finally, I convert the toolpath from post off to post on, because it was very difficult for me to choose only the operations to change.

Below I’m going to share my script, so that anybody can use it if needed.

 

'////////////////////////////////////////////////////////////////////////////////

' -- Start Script
Call Main()


Sub Main()

    

Dim intOpCount, idx

' -- COGEMOS TODAS LAS OPERACIONES QUE TENEMOS          
intOpCount = GetOperationCount(vbNullString)

                            
' -- MARCAMOS POST OFF AQUELLAS OPERACIONES QUE ESTÁN POST ON
Dim success

For idx = 1 To intOpCount

    success=SetOperationPostingFromID(vbNullString, idx, False)
    
Next  
 
 
 RunPostAll "", 1
    
    
End Sub

'////////////////////////////////////////////////////////////////////////////////


Thanks again.

Share this post


Link to post
Share on other sites
Guest

Thank you for sharing,

you may want to incorporate some error handling in your code as Mick did. 

I noticed you created a variable called success but never use it.

Jm2c

 

Also, if you learned something, it's never a waste of time! 😀

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • 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