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

Unprompted debug version it is, then:

 

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

 

 

ShowString "Debug 1"

 

Set objFSO = CreateObject("Scripting.FileSystemObject")

 

ShowString "Debug 2"

 

' 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

 

ShowString "Debug 3"

 

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

 

ShowString "Debug 4"

 

' 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 5"

 

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

objTS.Close

 

ShowString "Debug 6"

 

' Cleanup

Set objFSO = Nothing

Set objTS = Nothing

 

ShowString "Debug 7"

 

' All done!

ShowString ("All done!")

End Sub

Of course you'll have to update the contents of DEF_CSV_FILE so that it matches the path to your CSV file on your computer.

Link to comment
Share on other sites

Does this portion in the script on your computer look exactly like this (excluding the debug messages)?

 

code:

    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

Link to comment
Share on other sites

Found the problem!!! my firewall was blocking access to the folder where I had placed my CSV file.

My script was exactly right, as you wrote it. Thanks . Moved the file to a directory with full access then all worked well.

Thanks.

Link to comment
Share on other sites
Guest CNC Apps Guy 1

Thank you a TON Bullines. WOrks like a charm.

 

BTW you guys struggling with Excel, I created that CSV file in PFE32. A CSV file is just that, data, in a columner fashioned seperated by commas(in this case), tabs, spaces, etc... As long as the format is correct, you can create them in any text editor.

 

HTH

Link to comment
Share on other sites
Guest CNC Apps Guy 1

Oh, and if you don't care to see the "It's Done" you can comment out the "ShowString ("All done!")" line. My Mastercam X fires right up (except for the "Script Warning, do you want to allow this..." message. Gotta be safe you know. biggrin.gif

 

Thanks again friends. Time saver, time saver, timesaver. cheers.gif

Link to comment
Share on other sites

quote:

can it move the entities to the correct level? ie. wireframe is level 100 puts all wireframe on level 100, surfaces level 200 puts all surfaces on leve 200.......

 

 

is that easy to do?


Easy to do with the C-Hook and Nethook APIs. Not possible with the VBScript API as it only has access to basic wireframe entities (points, lines and arcs), and not other entities like surfaces and solids.

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

:bump:

 

Just in case anybody missed this dandy little utility I added it to the "VB_Scripts" folder on the FTP. It's called "CSV2Levels VB Script.zip"

 

Hope it helps others as much as it's helped me. Thanks again for all who contrbuted. cheers.gif

Link to comment
Share on other sites
  • 1 month later...
  • 6 months later...

I set up 2 different short cuts,

 

1. MCX2 new file, that opens mastercam and runs set_level.vbs like Pete said to do and I'm ready to start a new file with all levels set. (Thanks Pete, Bullins, and James)

 

2. MCX2 open file, that opens mastercam and runs Thad's file open.vbs ,so I can open an existing mastercam file. ( Thanks Thad )

 

This forum is so cool biggrin.gifbiggrin.gif

 

Thanks all

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