Is it to hard to do?
Is it to hard to do?
(OP)
Hello people...
Let's see if anyone can help me... is it too hard to create a macro that to the following:
- Open a drawing file
- Save as Sheet 1 as dwg file
- Save as Sheet 2 as dxf file
- Close the file
- Open the next file and then so with all other drwaings into the folder.
Is it possible?
Thank you so much and Merry Xtmas for all! :)
Rodrigo Basniak
Let's see if anyone can help me... is it too hard to create a macro that to the following:
- Open a drawing file
- Save as Sheet 1 as dwg file
- Save as Sheet 2 as dxf file
- Close the file
- Open the next file and then so with all other drwaings into the folder.
Is it possible?
Thank you so much and Merry Xtmas for all! :)
Rodrigo Basniak






RE: Is it to hard to do?
Thats my first question.
If you don't know what a map file is look in the help real quick.
Regards,
Scott Baugh, CSWP

3DVision Technologies
credence69@REMOVEhotmail.com
http://www.3dvisiontech.com
http://www.3dmca.com
*When in doubt always check the help*
RE: Is it to hard to do?
related to saving to autocad format...
I have had problems saving piping assembly drawings to dwg and dxf, additional piping centerlines gets into the drawing, offset from the pipes. No fun, have to delete them manually....
RE: Is it to hard to do?
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swPart As ModelDoc2
Dim swDwg As DrawingDoc
Const swDocDrawing = 3
Sub main()
Dim sPath As String
Dim sFileSW As String
Dim sFileDWG As String
Dim sFileDXF As String
Dim sFileTitle As String
sPath = "C:\Temp\"
Set swApp = CreateObject("SldWorks.Application")
sFileSW = Dir(sPath & "*.slddrw")
Do While sFileSW <> ""
'Open Drawing - Define Titles
Set swPart = swApp.OpenDoc(sPath & sFileSW, swDocDrawing)
Set swDwg = swPart
sFileDWG = Left(sFileSW, Len(sFileSW) - 6) & "DWG"
sFileDXF = Left(sFileSW, Len(sFileSW) - 6) & "DXF"
sFileTitle = swPart.GetTitle
'Save Sheet 1 (If Present)
If swDwg.ActivateSheet("Sheet1") Then
swPart.SaveAs2 sPath & sFileDWG, 0, True, False
Else
swApp.SendMsgToUser "No Sheet1 in " & sFileSW
End If
'Save Sheet 2
If swDwg.ActivateSheet("Sheet2") Then
swPart.SaveAs2 sPath & sFileDXF, 0, True, False
Else
swApp.SendMsgToUser "No Sheet2 in " & sFileSW
End If
'Close File
swApp.CloseDoc sFileTitle
'Next File
sFileSW = Dir
Loop
swApp.SendMsgToUser "Done!"
End Sub
If you use this code, you must add the SldWrks200? Type Library to your Project > References. Or, you can simple late bind the SolidWorks objects:
Dim swApp As Object
Dim swPart As Object
Dim swDwg As Object
This will go through all SolidWorks Drawings in the folder specified in the definition of sPath.
Hope it helps...
DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
RE: Is it to hard to do?
Sorry, but I don't know anything about macros
Dim swApp As Object
Dim swPart As Object
Dim swDwg As Object
Where should I put it?
Thanks for the attention,
Rodrigo Basniak
RE: Is it to hard to do?
With your macro open, go to Tools > References.
Scroll down until you find the SldWrks 200? Type Library
and check it. You will not have to do anything with the
"Dim swXXX as Object" statements.
Then, make sure to change sPath so that it points to the directory that contains the drawings you with to convert.
Let me know if this clears things up.
DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
RE: Is it to hard to do?
What T-E-R-R-I-F-I-C results!!!!! I don't have idea of how much work you saved for me in every new project
Just two questions about it:
- can macros print into a PRN file?
- in this macro, there's this line that should close the file: "swApp.CloseDoc sFileTitle", right? At the end, all files are still opened. This is correct? If yes, don't worry, it's not a problem if I have to close them at the end.
[]'s
Rodrigo Basniak
RE: Is it to hard to do?
- Yes, the macro should close each file by name. It works on my system, so I am not sure why it wouldn't on yours.
Glad I could help...
DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
RE: Is it to hard to do?
- Sheet1 is always the Detail drawing, sheet2 is always a file that goes to the laser cutting machine, there's no need to print this one. Only sheet1 must be printed.
Don't worry about closing files it's not a big problem
[]'s
Rodrigo Basniak
RE: Is it to hard to do?
'Close File
sFileTitle = swPart.GetTitle
swApp.CloseDoc sFileTitle
I will work on the printing portion and repost the corrected code.
DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
RE: Is it to hard to do?
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swPart As ModelDoc2
Dim swDwg As DrawingDoc
Const swDocDrawing = 3
Sub main()
Dim sPath As String
Dim sFileSW As String
Dim sFileDWG As String
Dim sFileDXF As String
Dim sFilePRN As String
Dim sFileTitle As String
sPath = "C:\Temp\"
Set swApp = CreateObject("SldWorks.Application")
sFileSW = Dir(sPath & "*.slddrw")
Do While sFileSW <> ""
'Open Drawing - Define Titles
Set swPart = swApp.OpenDoc(sPath & sFileSW, swDocDrawing)
Set swDwg = swPart
sFileDWG = Left(sFileSW, Len(sFileSW) - 6) & "DWG"
sFileDXF = Left(sFileSW, Len(sFileSW) - 6) & "DXF"
sFilePRN = Left(sFileSW, Len(sFileSW) - 6) & "PRN"
'Save Sheet 1 (If Present)
If swDwg.ActivateSheet("Sheet1") Then
'Save as DWG
swPart.SaveAs2 sPath & sFileDWG, 0, True, False
'Print to PRN
swPart.PrintOut2 1, 1, 1, False, "", 1, True, sPath & sFilePRN
Else
swApp.SendMsgToUser "No Sheet1 in " & sFileSW
End If
'Save Sheet 2
If swDwg.ActivateSheet("Sheet2") Then
swPart.SaveAs2 sPath & sFileDXF, 0, True, False
Else
swApp.SendMsgToUser "No Sheet2 in " & sFileSW
End If
'Close File
sFileTitle = swPart.GetTitle
swApp.CloseDoc sFileTitle
'Next File
sFileSW = Dir
Loop
swApp.SendMsgToUser "Done!"
End Sub
DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
RE: Is it to hard to do?
Simply replace the one line:
sPath = "C:\Temp\"
with
Dim sMsg As String
sMsg = "Enter the Path to the Drawings." & vbCrLf * _
"Make sure to end it with a \"
sPath = InputBox(sMsg, "Enter Drawing Path", "C:\Temp\")
If sPath = "" Then Exit Sub
DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
RE: Is it to hard to do?
I'd run the macro but it didn't create any .PRN file. Only the .DWG and .DXF files. Do you know why?
The scale of the drawings are 1:1 all of them are always with page setup correct, the macro only needs to print them into a .PRN file with the same name of the Drawing file.
[]'s
Rodrigo Basniak
RE: Is it to hard to do?
DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
RE: Is it to hard to do?
Thanks....
Rodrigo Basniak
RE: Is it to hard to do?
DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
RE: Is it to hard to do?
If so, you may want to carefully check your dxf: sometimes bend lines, tiny datum points, (and in 2003, the centermark holes for points) come thru in the dxf.
I never had much success getting a perfectly 'clean' dxf using the MAP files, I ended up having to write code to manually extract the geometry from the View and code my own DXF exporter.. if you succeed in exporting a SW dxf file that comes thru clean, Id love to hear about it.
What app are you using to code for the laser?