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:
I cannot thank you enough Roger. It is a big help to what were trying to do.
Again, thanks.
Also thank you Manuel for helping to convey my ideas to Roger.
I am indeed. I think a problem is solved and another arises.
We will always be adding the files to the sub-directory folder within the current directory named '\RPC Reference Files'
eg
C:\001 -To-
C:\001\RPC Reference Files
C:\002 -To-
C:\002\RPC Reference Files
or whatever our directory is.
We would normally save to a sub-directory.
Eg.
D:\RP\2011\RPC-11-00768
to
D:\RP\2011\RPC-11-00768\RPC Reference Files
However dragging the file afterwards is easy. It would be neat if it could do that as well tho.
I am still looking at different ways that this goal can be achieved. I appreciate your input. I didnt think of doing it the other way around. Does it give you the same end result?
Thank you so much Roger. That is a great start. There are a few more things I want to add so I will start on that.
I did notice that this opens the files, and not imports it. Is there a way to import instead?
Also I figure this is really close to what I wanted to do.
' *****************************************************************************
' * Script Name: Batch Import DXF Files.vbs
' * Written By: Mick George [email protected]
' * Date: August 15 2002
' * Dependency: Microsoft Scripting Runtime (scrrun.dll)
' * Microsoft Windows Scripting Host (WScript.exe)
' *
' * Function: Batch Import dxf files and save as native mastercam drawings
' * Select folder containing dxf files and select a folder to save drawings to
' *
' * Updated: Mick George added LCase() call to correctly identify dxf file extension.
' * January 21 2003
' *
' * Updated: Mick George added call to PROGRESS class
' *****************************************************************************
'
Include "CProgress.vbs"
Public Const DEF_CENTERED = " "
' -- Kick off script --
'
Call Main
'
' --------------------
' ////////////////////
' Sub Declaration
' ////////////////////
Sub main()
Dim FSO ' -- File System Object
Dim fsoDXFFolder ' -- Folder containing DXF Files
Dim fsoSaveToFolder ' -- Folder to save *.MC9 files
Dim fsoFiles ' -- Files located in selected folder
Dim fsoDXF ' -- A dxf File
Dim strDXFPath ' -- Return value of selected folder containing dxf files
Dim strSavePath ' -- Return value of selected folder to save files to
Dim blnOkToGo ' -- Flag
Dim strPrompt
Dim strMC ' -- Stores a Mastercam filename from a dxf filename
'
' ======================================
Dim CProgressBar ' -- Our progressbox
' ======================================
' -- Prompt user for a folder containing dxf files
strDXFPath = BrowseForFolder("Choose DXF Files Folder")
' -- Make sure a valid folder was selected
If IsNull(strDXFPath) Then
ShowString "Invalid Folder Selection"
Exit Sub
Else
' -- Prompt user for a save folder
strSavePath = BrowseForFolder("Save Drawings")
' -- Make sure a valid folder was selected
If IsNull(strSavePath) Then
ShowString "Invalid Folder Selection"
Exit Sub
End If
' -- Create an instance of a File System Object
Set FSO = CreateObject("Scripting.FileSystemObject")
' -- Get the selected folder
Set fsoDXFFolder = FSO.GetFolder(strDXFPath)
' -- Get all files in this folder
Set fsoFiles = fsoDXFFolder.Files
' -- Make sure we have some files
If fsoFiles.Count = 0 Then
ShowString "There are no files in the selected folder"
Exit Sub
Else
' -- Initialize to be sure
blnOkToGo = False
' -- Make sure there is at least one dxf file
For Each fsoDXF In fsoFiles
' -- dxf file?
If Right(LCase(fsoDXF.Name), 3) = "dxf" Then
' -- ok to go
blnOkToGo = True
Exit For
End If
Next
If blnOkToGo Then
Dim blnRet
strPrompt = fsoFiles.Count & " dxf files found" & DEF_CENTERED
strPrompt = strPrompt & vbCrLf
strPrompt = strPrompt & "Do you wish to continue?" & DEF_CENTERED
blnRet = askYesNo(strPrompt)
If blnRet = mcMSG_NO Then Exit Sub
' -- Check for Root
Call AddBackSlash(strSavePath)
' -- Erase the Mastercam prompt area at the bottom of the Mastercam window and Menus
Call ClearMenuAndPrompts
' -- Clear screen
Call ResetAll
' ======================================
Set CProgressBar = New PROGRESS
'
CProgressBar.Show 500, 100, 550, 550
' ======================================
' -- Convert each dxf file
For Each fsoDXF In fsoFiles
' -- dxf file?
If Right(LCase(fsoDXF.Name), 3) = "dxf" Then
' ======================================================
CProgressBar.Caption "Converting " & fsoDXF.Name & "..."
' ======================================================
' -- Display current file in prompt area
Call WriteString("Converting " & fsoDXF.Name & "...")
' -- Import this DXF file into the current Mastercam session
Call ReadDXF(fsoDXF.Path)
' -- Fit screen
Call RepaintScreen(True)
' -- Build Mastercam filename
strMC = Mid(fsoDXF.Name, 1, InStrRev(fsoDXF.Name, "."))
' -- Build fullpath to folder
strMC = strSavePath & strMC & "MC9"
' -- Save the current Mastercam file
If Not SaveMCAs(strMC, True) Then
If Not askYesNo("Unable to save file '" & strMC & "' Do you wish to continue?" & DEF_CENTERED) Then
Exit For
End If
End If
' -- Clear screen
Call ResetAll
End If
Next
Call ResetAll
' =====================================
CProgressBar.Caption "Process Complete"
'
CProgressBar.Shutdown
' =====================================
' -- If blnOkToGo
Else
ShowString "There are no dxf files in the selected folder"
End If
End If
End If
Set CProgressBar = Nothing
End Sub
' ////////////////////
' Function Declaration
' ////////////////////
Function AddBackSlash(sPath)
If Right(sPath, 1) <> "\" Then sPath = sPath & "\"
AddBackSlash = sPath
End Function
' ////////////////////
' Function Declaration
' ////////////////////
Function BrowseForFolder(strPrompt)
On Error Resume Next
Dim objShell, objFolder, intColonPos, objWshShell
Set objWshShell = CreateObject("WScript.Shell")
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder(&H0&, strPrompt, &H1&)
BrowseForFolder = objFolder.ParentFolder.ParseName(objFolder.Title).Path
If Err.Number <> 0 Then
BrowseForFolder = Null 'will be null of no special case applies
If objFolder.Title = "Desktop" Then
BrowseForFolder = objWshShell.SpecialFolders("Desktop")
End If
intColonPos = InStr(objFolder.Title, ":")
If intColonPos > 0 Then
BrowseForFolder = Mid(objFolder.Title, intColonPos - 1, 2) & "\"
End If
End If
End Function
' ////////////////////
' Function Declaration
' ////////////////////
Sub ResetAll()
' -- Clear screen
Call NewMC(False)
' -- Fit screen
Call RepaintScreen(True)
' -- Clear prompt area
Call ClearPromptLines
End Sub
' '//////////////////////////
' '// Sub Declaration
' '//////////////////////////
Sub Include(sNameScript)
Dim FSO
Dim fsoInclude
Set FSO = CreateObject("Scripting.FileSystemObject")
sNameScript = GetPathOfThisScript & sNameScript
Set fsoInclude = FSO.OpenTextFile(sNameScript)
With fsoInclude
ExecuteGlobal .ReadAll()
.Close
End With
' -- Clean up
Set fsoInclude = Nothing
Set FSO = Nothing
End Sub
Hello Forum,
My name is Matt and this is my first post. I work in kitchener and have a small vbs program that I wanted to create since we do this string of instructions over and over.
Pretty much we want to be able to have a hotkey that will import a SLDPRT file into mastercam and resave it in another directory with the same name so we can edit it. We dont want to edit the original file, just import and resave. I have no real VB experience since college and am unsure how to do this. Any pointers are appreciated.
Thank-you Forum.
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.