Macro DXF PDF

Hello.

 

I have a macro that goes smoothly ... but where nothing happens. I don't really understand why and where it gets stuck. If anyone has an idea?

I put comments to explain what I'm trying to do there. The idea is to save each sheet of my DRW in DXF and PDF in the right name in the right directory.

 

 

Sub Save()
Dim swapp As SldWorks.SldWorks
Dim swdoc As SldWorks.ModelDoc2
Dim Swdraw As SldWorks.ModelDoc
Dim swSheet As SldWorks.Sheet
Dim vSheetNames As Variant
Dim Nbfeuille As Variant
Set swapp = Application.SldWorks
Set swdoc = swapp. ActiveDoc
Set Swdraw = swdoc
Set swSheet = Swdraw.GetCurrentSheet
'Confirmation message
ret = MsgBox("do you want to convert this drawing to DXF and PDF?", vbOKCancel + vbExclamation + vbMsgBoxSetForeground + vbSystemModal, "Laser Conversion")
If ret = vbCancel Then End
Registration new name
Do
newname = InputBox("Please specify the new name:", "blabla", newname)
If StrPtr(newname) = 0 Then
MsgBox "procedure cancelled"
Exit Sub
End If
'Checking Forbidden Character Windows
Do While InStr(newname, "/") > 0 Or InStr(newname, "*") > 0 Or InStr(newname, "?") > 0 Or InStr(newname, "<") > 0 Or InStr(newnam, ">") > 0 Or InStr(newnam, "!") > 0
newname = InputBox("Warning, the name contains at least one of the forbidden characters \/:*?"" <>!" & vbNewLine & vbNewLine & "Please indicate the new name: ", "save-under by LPR", newname)
Loop
Loop While newname = " "
'Registration Dossier
Do
FilePath = InputBox("Specify the path", "record folder", FilePath)
If StrPtr(FilePath) = 0 Then
MsgBox "procedure cancelled"
Exit Sub
End If
'Adding the \ to the end of the folder name
If Right(FilePath, 1) <> "\" Then FilePath = FilePath & "\"
If Dir$(FilePath) <> "" Then
EXISTS = 1
Else: MsgBox "the directory doesn't exist, please create it"
Debug.Print Dir$(FilePath)
End If
Loop While EXISTS <> 1
'Indicates the number of sheets
Nbfeuille = swdoc. GetSheetCount
For i = 0 To Nbfeuille
swdoc. SheetPrevious
Next i
Moving to the next sheet if < to the total number
For i = 0 To varSheetCount - 1
If i <> 0 Then
swmodel. SheetNext
End If
Recording in DXF and PDF
swdoc. SaveAs (FilePath + newname + "_" + i + ".dxf")
swdoc. SaveAs (FilePath + newname + "_" + i + ".pdf")
Next i
End Sub

1 Like

Hello

For debugging, see this link:

See this link: http://www.tomshardware.fr/forum/id-1348092/tutoriel-excel-macro-vba-debogage.html

Try to make a breakpoint for the lines:

 

swdoc. SaveAs (FilePath + newname + "_" + i + ".dxf")
swdoc. SaveAs (FilePath + newname + "_" + i + ".pdf")

 

The program goes well?

 

If not, see why.

 

If so, do a debug.print just before the lines to see what they contain:

debug.print FilePath + newname + "_" + i + ".dxf"

3 Likes

Not knowing much about macro creation, I only found another macro that can do what you're looking to achieve... If it can help you?

 

 


76430003creat-dxf-pdf-tif-zip.zip
3 Likes

I've already proposed two macros doing this in his last question, but he prefers to do his own macro:

http://www.lynkoa.com/forum/3d/trouver-une-feuille-mep-en-vba-sous-solidworks

2 Likes

So much for me,

I can't help you so, good luck;)

Cdt

Joss

2 Likes

Still a few bugs, but I'm getting close to the ultimate goal (haaaa!)

 

Anyway, thank you for the info on bug resolution

1 Like

Hello
I would like to save my parts in DXF as well but since the Part file, I tried to hack your program to adapt it but nothing works except the message boxes I have no results, someone can take a look at my code, or give me one that already works well for this use :slight_smile:


Sub Enregistrer()
Dim swapp As SldWorks.SldWorks
Dim swdoc As SldWorks.ModelDoc2
Dim SwPart As SldWorks.ModelDoc
Set swapp = Application.SldWorks
Set swdoc = swapp.ActiveDoc
Set SwPart = swdoc

'Message de confirmation
ret = MsgBox("voulez-vous convertir cette piece en DXF?", vbOKCancel + vbExclamation + vbMsgBoxSetForeground + vbSystemModal, "Conversion Laser")
If ret = vbCancel Then End


'Enregistrement nouveau nom
Do
 newname = InputBox("nom du dxf:", "blabla", newname)
 If StrPtr(newname) = 0 Then
 MsgBox "procédure annulée"
 Exit Sub
 End If
 
'Verification caractere interdit Windows
Do While InStr(newname, "/") > 0 Or InStr(newname, "*") > 0 Or InStr(newname, "?") > 0 Or InStr(newname, "<") > 0 Or InStr(newnam, ">") > 0 Or InStr(newnam, "!") > 0
 newname = InputBox("Attention, le nom contient au moins un des caractère interdits \/:*?""<>!" & vbNewLine & vbNewLine & "Merci d'indiquer le nouveau nom: ", "enregistrer-sous par LPR", newname)
 Loop
 Loop While newname = " "
 
 
'Dossier d'enregistrement
Do
 FilePath = InputBox("Indiquez le chemin d'accés", "dossier enregistrement", FilePath)
 If StrPtr(FilePath) = 0 Then
 MsgBox "procédure annulée"
 Exit Sub
End If
'Ajout du \ à la fin du nom de dossier
If Right(FilePath, 1) <> "\" Then FilePath = FilePath & "\"
 If Dir$(FilePath) <> "" Then
 EXISTE = 1
 Else: MsgBox "le répertoire n'existe pas, merci de le créer"
 Debug.Print Dir$(FilePath)
End If
Loop While EXISTE <> 1

'Enregistrement en DXF
swdoc.SaveAs (FilePath + newname + "_" + ".dxf")


End Sub

The macro is made for MEPs and you transform it for a room, no surprise that it doesn't work.
Moreover, the subject being closed since 2014 I invite you to create your own topic with this here as a reference.
I guess that there are already macros to export in dxf from a sheet metal part and that this one is therefore not the most suitable.

1 Like

Ho, an old message to môa! I'm moved! :smiling_face:

And I wasn't careful... 4k views on the topic. :crazy_face: :hot_face: :cold_face:

1 Like

Hello.

… 9 years later...
(you shouldn't dig up old topics, especially if they are already in "solved"...

To export a volume part (SLDPRT) in DXF: replace the "saveas" command with:
ExportToDWG2 (export without unfolded)
or by
ExportFlatPatternView (export with flattening)...

Kind regards.

1 Like