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:

post selected vb script


Recommended Posts

Here is a vb script for posting out only the selected operations and creating a setup sheet.

 

HTH

 

code:

 

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

'//

'// Author: Roger Peterson

'// Date: 10/15/04

'// File Name: post_selected.vbs

'//

'// Description: Post out all selected operation. Scan file to determine which operations are selected,

'// ghost any operation not selected, post to selected post processors, un-ghost operations that were

'// previously ghosted. Prompts the user to select the directory for the nc file and again for the

'// directory for the doc file. Constant spost2 holds the path and name of the second post to be used.

'// If you desire to use a .set file you must rename it so it has a .pst extension.

'//

'// Comments: Requires March Maintenance release

'//

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

 

' -- Start Script

Dim sprompt

 

Call Main()

 

 

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

' Sub Declaration

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

Sub Main()

 

Dim posting(999)

Dim selected(999)

Dim intOpCount, idx, intCount

Const spost2 = "c:mcam9millpostsset.pst"

Const sdoc = ".doc"

Const snc = ".nc"

Const snci = ".nci"

Const spst = ".pst"

Dim spathnci

Dim snamenci

Dim spathnamenci

Dim namepos

Dim ncipos

Dim sname

Dim spathnc

Dim strPath

Dim spathdoc

Dim contposting

Dim spostoriginal

Dim spost1

Dim spathpst

 

'--resume the script on errors

On Error Resume Next

 

' -- Determine how many operations are in the active file?

intOpCount = GetOperationCount(vbNullString)

 

' -- If the file does not contain any operations, exit the script

If intOpCount = 0 Then ShowString "No operations in the current mc9 file": Exit Sub

 

' -- Initialize

intCount = 0

 

'------------------------------------------------------------------------------------

' which and how many operations are selected

'------------------------------------------------------------------------------------

For idx = 1 To intOpCount

 

If GetOperationSelectedFromID(vbNullString, idx) Then

selected(idx) = 1

intCount = intCount + 1

Else

selected(idx) = 0

End If

 

Next

 

'------------------------------------------------------------------------------------

' which and how many operations are NOT ghosted

'------------------------------------------------------------------------------------

For idx = 1 To intOpCount

 

If GetOperationPostingFromID(vbNullString, idx) Then

posting(idx) = 1

Else

posting(idx) = 0

End If

 

Next

 

'------------------------------------------------------------------------------------

' -- If no operations are selected exit post

'------------------------------------------------------------------------------------

If intCount = 0 Then

ShowString "No operations are selected, You will be returned to Mastercam "

Exit Sub

'Else

' ShowString intCount & " of " & intopcount & " operations are currently selected"

End If

 

 

'------------------------------------------------------------------------------------

' -- Turn posting off on all ops not selected

'------------------------------------------------------------------------------------

For idx = 1 To intOpCount

 

If Not GetOperationSelectedFromID(vbNullString, idx) Then

'ShowString " operation # " & idx & " not selected"

Call SetOperationPostingFromID(vbNullString, idx, True)

End If

 

Next

 

 

 

 

'---------------------------------------------------------------------------------------------

'Get NCI file name information

'---------------------------------------------------------------------------------------------

spathnci = GetPathFromExtension("nci")

spathnamenci = GetNciNameFromOperationID(vbNullString, 2)

namepos = Len(spathnci)' Determine the length of the nci path - not included is the name of the nci file

namepos = namepos + 1 ' Add one so is not included in the name

snamenci = Mid(spathnamenci, namepos) ' snamenci includes just the name of the nci file and not the directory path

ncipos = InStr(1, snamenci, snci, 1)

ncipos = ncipos - 1 ' Subtract one so when removing the extension the . is also removed

If ncipos Then

sname = Left(snamenci, ncipos) ' This removes .nci from the name

End If

 

 

'---------------------------------------------------------------------------------------------

'get post to be used so it can be reset at the end of script

'---------------------------------------------------------------------------------------------

' -- Get the currently set post processor

spostoriginal = GetPostName

spathpst = GetPathFromExtension("pst")

spathpst = spathpst & spostoriginal & spst

 

 

'---------------------------------------------------------------------------------------------

'-- Tell the user the post name, the name of the nci file, and how many operations have been selected

'-- and ask if they would like to continue or go back and change the settings

'---------------------------------------------------------------------------------------------

contposting = askYesNo("Postname: " & spostoriginal & " " & vbCrLf & "NC and DOC filenames: " & sname & vbCrLf & intCount & " of " & intopcount & " operations are currently selected" & vbCrLf & vbCrLf & "Select Yes To continue posting, No To return To Mastercam ")

 

 

If contposting = 0 Then

For idx = 1 To intOpCount

Call SetOperationPostingFromID (vbNullString, idx, posting(idx))

Next

Exit Sub

End If

 

 

'---------------------------------------------------------------------------------------------

'get directories for nc and doc files

'---------------------------------------------------------------------------------------------

 

' -- Prompt user for a folder to post nc file-------------------------------------------------

strpath = vbNullString

sprompt = "Select folder for nc file:"

 

While strPath = vbNullString

' -- Invalid path....

strPath = BrowseForFolder

Wend

 

strpath = AddBackSlash(strpath)

spathnc = strpath

 

 

 

' -- Prompt user for a folder to post doc file------------------------------------------------

strpath = vbNullString

sprompt = "Select folder for doc file:"

 

While strPath = vbNullString

' -- Invalid path....

strPath = BrowseForFolder

Wend

 

strpath = AddBackSlash(strpath)

spathdoc = strpath

 

'---------------------------------------------------------------------------------------------

'post .pst and .set files to their specified directories

'---------------------------------------------------------------------------------------------

'---post to the current nci file name, using post #1------------------------------------------

 

Call RunPostAll(spathnc, True)

 

 

'---post to the current nci file name, using post #2------------------------------------------

Call SetPostName(vbNullString)

Call SetPostName(spost2)

Call RunPostAll(spathdoc, True)

 

'---------------------------------------------------------------------------------------------

' -- Set posting (Operations ghosted) back To original settings

'---------------------------------------------------------------------------------------------

For idx = 1 To intOpCount

Call SetOperationPostingFromID (vbNullString, idx, posting(idx))

Next

 

Call SetPostName(vbNullString)

Call SetPostName(spathpst)

Call SetPostName(vbNullString)

Call SetPostName(spostoriginal)

 

End Sub

 

 

 

 

 

 

 

 

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

' Function Declaration

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

 

Function BrowseForFolder()

 

On Error Resume Next

 

Const WINDOW_HANDLE = 0

Const NO_OPTIONS = 0

Dim objShell, objFolder, objFolderItem

 

Set objShell = CreateObject("Shell.Application")

 

Set objFolder = objShell.BrowseForFolder(WINDOW_HANDLE, sprompt, NO_OPTIONS, "Desktop")

 

Set objFolderItem = objFolder.Self

 

If Err.Number <> 0 Then

 

BrowseForFolder = vbNullString

Err.Clear

Exit Function

End If

 

BrowseForFolder = objFolderItem.Path

End Function

 

 

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

' Function Declaration

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

 

Function AddBackSlash(sPath)

 

If Right(sPath, 1) <> "" Then sPath = sPath & ""

AddBackSlash = sPath

 

End Function

 


Link to comment
Share on other sites

Coolness, thanks Roger.

 

Burce,

 

The script posts the Mastercam file TWICE,

with 2 different posts. If you use the .SET

file for making setup sheets, copy the name

of that post and place it in

 

code:

Const spost2    = "c:mcam91millpostsyourpostname.set"

Now when you run the script, it will post the

file with the default (from job setup) post,

and then with the post you specify, which will

create the .DOC file.

Link to comment
Share on other sites

Hey guys, spost2 holds the name of the second post you would like to use.

 

code:

 

Const spost2 = "c:mcam9millpostsset.pst"


I have had some difficulties posting to a .set file on some pc's, so rename your setup sheet .set file to set.pst and it should work fine. Or you can use any name and just modify spost2. I would post it on the ftp but I am having problems with posting files to the ftp site.

 

HTH

Link to comment
Share on other sites

I just tied to put this script in to bryan's menu Chook.

I tried different names for the script and came to the conclusion that

I can not have the letter "s" in the name of the script.

example it is called setpost.vbs and i get an error that it can not find etpot.vbs.

 

so I renamed a different script to have an "s" in it and got the similar error.

if i rename the setpost.vbs to etpot.vbs it will work fine.

 

has anyone else seen this before.

 

thank you

 

Jody

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