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:

Loading levels


Guest
 Share

Recommended Posts

John, I've been using the script in X from V9. It's not automated to run when getting a file, but all it takes is one separate click

 

quote:

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

 

 

' -- Start Script

Call Main()

 

 

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

' Sub Declaration

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

Sub Main()

SetLevelName 1, "Components"

SetLevelName 10, "Top Insulator Board Solid"

SetLevelName 11, "TCP Solid"

SetLevelName 13, "A Plate Solid"

SetLevelName 14, "B Plate Solid"

SetLevelName 15, "Support Plate Solid"

SetLevelName 17, "Pin Plate Solid"

SetLevelName 18, "KO Plate Solid"

SetLevelName 19, "BCP Solid"

SetLevelName 20, "Bottom Insulator Board Solid"

SetLevelName 21, "Rails Solid"

SetLevelName 110, "Top Insulator Board Layout"

SetLevelName 111, "TCP Layout"

SetLevelName 113, "A Plate Layout"

SetLevelName 114, "B Plate Layout"

SetLevelName 115, "Support Plate Layout"

SetLevelName 117, "Pin Plate Layout"

SetLevelName 118, "KO Plate Layout"

SetLevelName 119, "BCP Layout"

SetLevelName 120, "Bottom Insulator Board Layout"

SetLevelName 121, "Rails Layout"

End Sub

Link to comment
Share on other sites

Here ya go. It prompts you for a CSV file and then sets the level names accordingly.

 

code:

Const DEF_FSO_FORREADING = 1

Const DEF_UNNAMED_LVL = """""""."""""""

 

' Kick off our script

Call Main()

 

' Purpose: The main subroutine

Sub Main()

Dim objFSO

Dim objTS

Dim strCSVPath

Dim strInLine

Dim arrTokLine

 

 

' Prompt the user for a CSV file. Bail if the user cancels

' the dialog.

If Not (AskForFileName("*.CSV", "r", strCSVPath)) Then

ShowString("No file selected. Aborting.")

Exit Sub

End If

 

Set objFSO = CreateObject("Scripting.FileSystemObject")

 

' Make sure the file is actually there and bail if it isn't.

If Not (objFSO.FileExists(strCSVPath)) Then

objFSO = Nothing

ShowString("File not found!" & vbLf & vbLf & strCSVPath)

Exit Sub

End If

 

Set objTS = objFSO.OpenTextFile(strCSVPath, DEF_FSO_FORREADING, False)

 

' Read the CSV file line by line. For each line, make sure that it

' contains a comma. If it does, tokenize on the comma into an array.

' The first element is the level number and the second element is

' the level name. Set the named levels based on what's in the array.

Do While(objTS.AtEndOfStream <> True)

strInLine = Trim(objTS.ReadLine)

 

If (InStr(1, strInLine, ",")) Then

arrTokLine = Split(strInLine, ",")

 

If Not (arrTokLine(1) = DEF_UNNAMED_LVL) Then

Call SetLevelName(arrTokLine(0), Trim(arrTokLine(1)))

End If

End If

Loop

 

' Close the CSV file. We're done with it.

objTS.Close

 

' Cleanup

Set objFSO = Nothing

Set objTS = Nothing

 

' All done!

ShowString ("All done!")

End Sub

HTH

Link to comment
Share on other sites

And....

Did you know that you can add a VBS file name to your Mastercam X shortcut and it'll run it automatically?

For instance, I saved robk's script as SetLevels.VBS and changed the "Target:" of my shortcut to say:

C:mcamxmr1mastercam.exe "C:Mcamxmr1vbsetlevels.vbs"

and, voila, the level names are all loaded up.

Link to comment
Share on other sites
  • 1 month later...
Guest CNC Apps Guy 1

Ok, I got this setup and it works great. One thing that would make it AWESOME would be if it did not prompt at all. I looked in the Mastercam VBS help and could not find it. I did a search for file but the only one applicable to this scenario was the "AskForFileName". Am I missing something?

 

I don't want it to ask for anything. I just want it to automagically run. Here's the script;

 

code:

'//   Title:        CSV2Levels.vbs

'//

'// Props: The Man, the myth, the ledgend... Bullines 8-)

'//

'//

'//

'// Description: Allows for a CSV File to dictate level numbers and names

'//

'//

'//

'// Comments:

'//

'//

'//

'//

'//

'//

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

' | Constants |

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

 

Const DEF_FSO_FORREADING = 1

Const DEF_UNNAMED_LVL = """""""."""""""

 

' Kick off our script

Call Main()

 

' Purpose: The main subroutine

Sub Main()

Dim objFSO

Dim objTS

Dim strCSVPath

Dim strInLine

Dim arrTokLine

 

 

' Prompt the user for a CSV file. Bail if the user cancels

' the dialog.

If Not (AskForFileName("CSV2Levels.CSV", "r", strCSVPath)) Then

ShowString("No file selected. Aborting.")

Exit Sub

End If

 

Set objFSO = CreateObject("Scripting.FileSystemObject")

 

' Make sure the file is actually there and bail if it isn't.

If Not (objFSO.FileExists(strCSVPath)) Then

objFSO = Nothing

ShowString("File not found!" & vbLf & vbLf & strCSVPath)

Exit Sub

End If

 

Set objTS = objFSO.OpenTextFile(strCSVPath, DEF_FSO_FORREADING, False)

 

' Read the CSV file line by line. For each line, make sure that it

' contains a comma. If it does, tokenize on the comma into an array.

' The first element is the level number and the second element is

' the level name. Set the named levels based on what's in the array.

Do While(objTS.AtEndOfStream <> True)

strInLine = Trim(objTS.ReadLine)

 

If (InStr(1, strInLine, ",")) Then

arrTokLine = Split(strInLine, ",")

 

If Not (arrTokLine(1) = DEF_UNNAMED_LVL) Then

Call SetLevelName(arrTokLine(0), Trim(arrTokLine(1)))

End If

End If

Loop

 

' Close the CSV file. We're done with it.

objTS.Close

 

' Cleanup

Set objFSO = Nothing

Set objTS = Nothing

 

' All done!

ShowString ("All done!")

End Sub

My CSV is as follows;

 

code:

1,Original Solid

2,Original Solid Edge Curves

3,OP01 Material

4,OP02 Material

5,OP03 Material

6,Top Solid Extrusion Geometry

7,Front Solid Extrision Geometry

8,Side Solid Extrusion Geometry

10,OP01 Toolpath Geometry 1

11,OP01 Toolpath Geometry 2

20,OP02 Toolpath Geometry 1

21,OP02 Toolpath Geometry 2

30,OP03 Toolpath Geometry 1

31,OP03 Toolpath Geometry 2

110,OP01 Fixture Solid

111,OP01 Fixture Wireframe 1

112,OP01 Fixture Wireframe 2

113,OP01 Fixture Wireframe 3

120,OP02 Fixture Solid

121,OP02 Fixture Wireframe 1

122,OP02 Fixture Wireframe 2

123,OP02 Fixture Wireframe 3

130,OP03 Fixture Solid

131,OP03 Fixture Wireframe 1

132,OP03 Fixture Wireframe 2

133,OP03 Fixture Wireframe 3

201,Form Tool #1

202,Form Tool #2

203,Form Tool #3

204,Form Tool #4

205,Form Tool #5

206,Form Tool #6

207,Form Tool #7

231,OP01 Tombstone Orientetion

232,OP02 Tombstone Orientation

233,OP03 Tombstone Orientation

241,OP01 WCS Lines

242,OP02 WCS Lines

243,OP03 WCS Lines

255,Blanked Entities

Link to comment
Share on other sites

quote:

One thing that would make it AWESOME would be if it did not prompt at all.


Piece o' cake:

 

code:

Const DEF_CSV_FILE = "C:pathtoyourfile.csv"

Const DEF_FSO_FORREADING = 1

Const DEF_UNNAMED_LVL = """""""."""""""

 

' Kick off our script

Call Main()

 

' Purpose: The main subroutine

Sub Main()

Dim objFSO

Dim objTS

Dim strInLine

Dim arrTokLine

 

 

Set objFSO = CreateObject("Scripting.FileSystemObject")

 

' Make sure the file is actually there and bail if it isn't.

If Not (objFSO.FileExists(DEF_CSV_FILE)) Then

objFSO = Nothing

ShowString("File not found!" & vbLf & vbLf & DEF_CSV_FILE)

Exit Sub

End If

 

Set objTS = objFSO.OpenTextFile(DEF_CSV_FILE, DEF_FSO_FORREADING, False)

 

' Read the CSV file line by line. For each line, make sure that it

' contains a comma. If it does, tokenize on the comma into an array.

' The first element is the level number and the second element is

' the level name. Set the named levels based on what's in the array.

Do While(objTS.AtEndOfStream <> True)

strInLine = Trim(objTS.ReadLine)

 

If (InStr(1, strInLine, ",")) Then

arrTokLine = Split(strInLine, ",")

 

If Not (arrTokLine(1) = DEF_UNNAMED_LVL) Then

Call SetLevelName(arrTokLine(0), Trim(arrTokLine(1)))

End If

End If

Loop

 

' Close the CSV file. We're done with it.

objTS.Close

 

' Cleanup

Set objFSO = Nothing

Set objTS = Nothing

 

' All done!

ShowString ("All done!")

End Sub

Change the value of DEF_CSV_FILE, whcih stores the path to your CSV file, as needed.

 

HTH cheers.gif

Link to comment
Share on other sites

Ah, the joys of debugging Mastercam VBScript. Line numbers would be nice, wouldn't they? wink.gif Anywho, I have a hunch what it might be in your case, Pip, but give this a try:

 

code:

Const DEF_FSO_FORREADING = 1

Const DEF_UNNAMED_LVL = """""""."""""""

 

' Kick off our script

Call Main()

 

' Purpose: The main subroutine

Sub Main()

Dim objFSO

Dim objTS

Dim strCSVPath

Dim strInLine

Dim arrTokLine

 

 

ShowString("Debug 1")

 

' Prompt the user for a CSV file. Bail if the user cancels

' the dialog.

If Not (AskForFileName("*.CSV", "r", strCSVPath)) Then

ShowString("No file selected. Aborting.")

Exit Sub

End If

 

ShowString("Debug 2")

 

Set objFSO = CreateObject("Scripting.FileSystemObject")

 

ShowString("Debug 3")

 

' Make sure the file is actually there and bail if it isn't.

If Not (objFSO.FileExists(strCSVPath)) Then

objFSO = Nothing

ShowString("File not found!" & vbLf & vbLf & strCSVPath)

Exit Sub

End If

 

ShowString("Debug 4")

 

Set objTS = objFSO.OpenTextFile(strCSVPath, DEF_FSO_FORREADING, False)

 

ShowString("Debug 5")

 

' Read the CSV file line by line. For each line, make sure that it

' contains a comma. If it does, tokenize on the comma into an array.

' The first element is the level number and the second element is

' the level name. Set the named levels based on what's in the array.

Do While(objTS.AtEndOfStream <> True)

strInLine = Trim(objTS.ReadLine)

 

If (InStr(1, strInLine, ",")) Then

arrTokLine = Split(strInLine, ",")

 

If Not (arrTokLine(1) = DEF_UNNAMED_LVL) Then

Call SetLevelName(arrTokLine(0), Trim(arrTokLine(1)))

End If

End If

Loop

 

ShowString("Debug 6")

 

' Close the CSV file. We're done with it.

objTS.Close

 

ShowString("Debug 7")

 

' Cleanup

Set objFSO = Nothing

Set objTS = Nothing

 

ShowString("Debug 8")

 

' All done!

ShowString ("All done!")

End Sub

Run this "debug" version of the script and let me know what the last debug number you see before you get that runtime error dialog.

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