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:

Questions in VB


Recommended Posts

I have a VB script that does a multi post for 7 posts. I was wondering if there was any way to have the script ask me which post th use and then put the nc code in the right folder.

 

example:

Constantes

 

post 1

post 2

post 3

post 4

post 5

post 6

post 7

 

 

say I want to use post 6 & 7. Have it only create folders for 6 & 7. Then put the NC file in the right folder.

Does this make any since??

Link to comment
Share on other sites

Yes this makes sense. You would need to make a condition stament in the VB script for the varabile like so:

code:

Dim P 'Post vaule for folder

Dim K 'Vaule for Folder Amounts above 5

For P = 1 to 7 ' Count of Post Folders

 

If askValue("What post folder to post to?" ,0 ,7, P) Then

If askVaule("What Number to Have above 5?" ,0 , 2, K) Then

 

If P > 1 Then (what ever your command is for Null to take effect)

If P = 2 Then (what ever you command is for one folder)

If P = 3 Then (what ever your folder command is for 3 folders)

If P <= 5 Then

If K > 3 Then (what ever you folder command is for 2 folders where you want to start at 5 but only have a place for 2 folders)

 


I do not have access to your script or VB with Mastercam at home so just a guess here but Rekd or Mick are the gurus of VB.

 

HTH

Link to comment
Share on other sites

Here is something I quickly put together that might give you some ideas.

 

code:

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

' Sub Declaration

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

Sub Main()

 

On error resume next

 

Dim ret

Dim posts

Dim post

Dim i

 

' -- Prompt for posts

ret = AskString("Input Post numbers 1 - 7 to output, delimit by comma")

 

' -- Simple check

If Len(ret) = 0 Then Exit Sub

 

' -- Create an array for the return

posts = Split(Trim(ret), ",")

 

' -- Iterate over each item

For i = LBound(posts) To UBound(posts)

' -- Get this number

post = posts(i)

' -- Do something with it

Select Case post

 

Case 1

ShowString "Post number 1"

Case 2

ShowString "Post number 21"

Case 3

ShowString "Post number 3"

Case 4

ShowString "Post number 4"

Case 5

ShowString "Post number 5"

Case 6

ShowString "Post number 6"

Case 7

ShowString "Post number 7"

Case Else

ShowString "Invalid post"

 

End Select

 

Next

 

if Err then

Showstring Err.Description

end if

 

End Sub

Link to comment
Share on other sites

Here's a script a whipped up that'll create a sub directory depending on the post that you selected. It allows you to select your post via a File|Open dialog. It will allow some flexibility, should you add new posts, since it'll create sub directories in your NC dir, based on the post's filename.

 

code:

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

'//

'// Author: Chris Bellini [email protected]

'// Date: 01/13/2005 9:03 AM

'// File Name: connormac2.vbs

'//

'// Description: multiposter for connormac

'//

'// Comments:

'//

'//

'//

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

 

 

'//////////////////// My Constants /////////////////////

 

 

'///////////////// My Global Variables /////////////////

 

 

' call the main sub

Call Main()

 

 

' Purpose: The main sub, our script's entry point

Sub Main()

Dim objFSO ' FSO object

Dim strSelPostBname ' post base filename

Dim strNCDir ' our assembled NC directory

Dim strSelPost ' selected post

 

 

If Not AskForFileName(GetPathFromExtension("PST") & "*.pst", mcFILE_ACCESS_READ, strSelPost) Then

ShowString "Error: Post Processor not selected. Exiting."

Exit Sub

End If

 

' create a FileSystem Object

Set objFSO = CreateObject("Scripting.FileSystemObject")

 

' get the posts filename

strSelPostBname = objFSO.GetBaseName(strSelPost)

 

' assemble our new NC dir based on the post selected

strNCDir = GetPathFromExtension("NC") & strSelPostBname

 

' create our NC directory for our post if it doesn't exist

If Not (objFSO.FolderExists(strNCDir)) Then

objFSO.CreateFolder(strNCDir)

End If

 

' set the post

Call SetPostName(strSelPost)

 

' post all ops

Call RunPostAll(strNCDir, False)

 

' cleanup

Set objFSO = Nothing

End Sub

 

[ 01-13-2005, 09:17 AM: Message edited by: Bullines ]

Link to comment
Share on other sites

That's because the MakeFolders() function creates all of the NC folders all in one shot, regardless of whether they were selected or not. Plus MakeFolders() is called before you even select your posts. You can modify the MakeFolders() function so that it also accepts a third parameter; the selected post to build the folder on the fly. To do as little refactoring as possible (although refactoring can be fun biggrin.gif ), let's modify that function a little bit:

 

code:

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

' Function Declaration

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

Public Function MakeFolders(companyname, Program, PostFname)

On Error Resume Next

 

' -- Check to see if folders exist

Dim FSO

Set FSO = CreateObject("Scripting.FileSystemObject")

 

'

' -- This is kinda long winded but does the job

' -- NOTE: If you use an invalid character for a part number you'll have a problem!

 

If Not FSO.FolderExists("C:Regal" & companyname) Then

Call FSO.CreateFolder("C:Regal" & companyname)

End If

 

If Not FSO.FolderExists("C:Regal" & companyname & "" & Program) Then

Call FSO.CreateFolder("C:Regal" & companyname & "" & Program)

End If

 

If Not FSO.FolderExists("C:Regal" & companyname & "" & Program & "Source") Then

Call FSO.CreateFolder("C:Regal" & companyname & "" & Program & "Source")

End If

 

If Not FSO.FolderExists("C:Regal" & companyname & "" & Program & "Model Files") Then

Call FSO.CreateFolder("C:Regal" & companyname & "" & Program & "Model Files")

End If

 

If Not FSO.FolderExists("C:Regal" & companyname & "" & Program & "Docs") Then

Call FSO.CreateFolder("C:Regal" & companyname & "" & Program & "Docs")

End If

 

If Not FSO.FolderExists("C:Regal" & companyname & "" & Program & "NC Code") Then

Call FSO.CreateFolder("C:Regal" & companyname & "" & Program & "NC Code")

End If

 

' let's create NC folders by the name of the post(s) selected

If Not FSO.FolderExists("C:Regal" & companyname & "" & Program & "NC Code" & FSO.GetBaseName(PostFname)) Then

Call FSO.CreateFolder("C:Regal" & companyname & "" & Program & "NC Code" & FSO.GetBaseName(PostFname)

End If

 

If Err Then

MakeFolders = False

Else

MakeFolders = True

End If

End Function

I've added a third parameter called PostFname. This will be the filename of the post selected (you've already defined those constants at the very top of the code). And instead of creating all of those folders each time MakeFolders() is called, it'll now only create the directories of the post that you passed. I used the GetBaseName() method of the FSO object to extract just the base file name...no extension.

 

We can now remove this code entirely:

 

code:

        If Not MakeFolders(companyname, Program) Then

ShowString "Failed to create folders, aborting script"

Exit Sub

End If

Actually, we won't remove it entirely. We'll delete it from where it currently is and move it into the Select statement. For each Case, we'll modify accordingly. For example:

 

code:

Case 1

If Not MakeFolders(companyname, Program, DEF_FIRST_POST) Then

ShowString "Failed to create folders, aborting script"

Exit Sub

End If

 

' -- Set first post as current post

Call SetPostName(DEF_FIRST_POST)

 

' -- Post it

Call RunPostAll(strCNC_1, False)

 

Case 2

If Not MakeFolders(companyname, Program, DEF_SECOND_POST) Then

ShowString "Failed to create folders, aborting script"

Exit Sub

End If

 

' -- Set first post as current post

Call SetPostName(DEF_SECOND_POST)

 

' -- Post it

Call RunPostAll(strCNC_2, False)

 

' and so on

Once you make those changes, let us know how it works. HTH cheers.gif

Link to comment
Share on other sites

---------------------------

MCAMVB

---------------------------

Microsoft VBScript compilation error

Expected ')'

IActiveScriptSite::OnScriptError()

Line: Call FSO.CreateFolder("C:Regal" & companyname & "" & Program & "NC Code" & FSO.GetBaseName(PostFname)

---------------------------

OK

---------------------------

I'm not sure what it means but I don't think it liked it

Link to comment
Share on other sites

You forgot to remove the initial call to MakeFolders().

 

Make this part:

 

code:

Dim companyname

Dim Program

 

Do 'ask until a real company name is entered

companyname=AskString("Company Name?")

Loop While companyname="Company Name?" Or companyname="((ESC))" Or companyname=""

 

Do 'ask until a real program number is used

Program=AskString("Part number?")

Loop While Program="Part number?" Or Program="" Or Program="((ESC))"

 

 

If Not MakeFolders(companyname, Program) Then

ShowString "Failed to create folders, aborting script"

Exit Sub

End If

Look like this:

 

code:

Dim companyname

Dim Program

 

Do 'ask until a real company name is entered

companyname=AskString("Company Name?")

Loop While companyname="Company Name?" Or companyname="((ESC))" Or companyname=""

 

Do 'ask until a real program number is used

Program=AskString("Part number?")

Loop While Program="Part number?" Or Program="" Or Program="((ESC))"

Also, I failed to notice the "_Prog" in all of your post filenames. You don't want that in the NC directories, right? In that case, let's modify MakeFolders() slightly:

 

code:

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

' Function Declaration

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

Public Function MakeFolders(companyname, Program)

 

On Error Resume Next

 

' -- Check to see if folders exist

Dim FSO

 

Set FSO = CreateObject("Scripting.FileSystemObject")

 

'

' -- This is kinda long winded but does the job

' -- NOTE: If you use an invalid character for a part number you'll have a problem!

 

If Not FSO.FolderExists("C:Regal" & companyname) Then

Call FSO.CreateFolder("C:Regal" & companyname)

End If

 

If Not FSO.FolderExists("C:Regal" & companyname & "" & Program) Then

Call FSO.CreateFolder("C:Regal" & companyname & "" & Program)

End If

 

If Not FSO.FolderExists("C:Regal" & companyname & "" & Program & "Source") Then

Call FSO.CreateFolder("C:Regal" & companyname & "" & Program & "Source")

End If

 

If Not FSO.FolderExists("C:Regal" & companyname & "" & Program & "Model Files") Then

Call FSO.CreateFolder("C:Regal" & companyname & "" & Program & "Model Files")

End If

 

If Not FSO.FolderExists("C:Regal" & companyname & "" & Program & "Docs") Then

Call FSO.CreateFolder("C:Regal" & companyname & "" & Program & "Docs")

End If

 

If Not FSO.FolderExists("C:Regal" & companyname & "" & Program & "NC Code") Then

Call FSO.CreateFolder("C:Regal" & companyname & "" & Program & "NC Code")

End If

 

' let's create NC folders by the name of the post(s) selected

 

If Not FSO.FolderExists("C:Regal" & companyname & "" & Program & "NC Code" & Replace(objFSO.GetBaseName(PostFname), "_Prog", "")) Then

Call FSO.CreateFolder("C:Regal" & companyname & "" & Program & "NC Code" & Replace(objFSO.GetBaseName(PostFname), "_Prog", ""))

End If

 

 

 

If Err Then

MakeFolders = False

Else

MakeFolders = True

End If

 

 

End Function

It's a little bit ugly, but you could always store the Replace() on the GetBaseName() in a variable first. It's Friday night, I'm lazy wink.gif

 

How about now?

Link to comment
Share on other sites

Hey Bullines,

 

thanks for all your help. I got it where it will not give me any errors but it also won't do anything. I put it back on the FTP site. I'm going out of town for the weekend and my wife says no VB scripts are allowed. Will get back with you at the end of the weekend.

 

Thanks again

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