Hello team,
I decided to start making a maccro to save time on my work.
Being a novice, I first read a lot of topics on this forum but I didn't necessarily find my answers.
Let me explain: I created a maccro with the "Save" function of it.
The purpose of this maccro would be in order:
- From a room. SLDPRT
- Save it in . STEP
- Open your drawing
- Save as . DxF
- Save as PDF
- Close Drawing
- Close the room
The code that emerges from it is as follows:
’ ******************************************************************************
' C:\Users\bguyetand\AppData\Local\Temp\swx4952\Macro1.swb - macro recorded on 09/20/23 by BGuyetand
’ ******************************************************************************
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
' Save As
longstatus = Part.SaveAs3("C:\Users\bguyetand\Desktop\Part1.STEP", 0, 2)
' Open
Set Part = swApp.OpenDoc6("C:\Users\bguyetand\Desktop\Part1.SLDDRW", 3, 0, "", longstatus, longwarnings)
Dim swDrawing As DrawingDoc
Set swDrawing = Part
Set Part = swApp.ActiveDoc
Dim myModelView As Object
Set myModelView = Part.ActiveView
myModelView.FrameLeft = 0
myModelView.FrameTop = 22
Set myModelView = Part.ActiveView
myModelView.FrameState = swWindowState_e.swWindowMaximized
swApp.ActivateDoc2 "Part1 - Sheet1", False, longstatus
Set Part = swApp.ActiveDoc
Set myModelView = Part.ActiveView
myModelView.FrameState = swWindowState_e.swWindowMaximized
' Save As
longstatus = Part.SaveAs3("C:\Users\bguyetand\Desktop\Pièce1.pdf", 0, 2)
Part.SheetPrevious
' Redraw
Part.GraphicsRedraw2
' Zoom to Area
Part.ViewZoomTo2 0, 0, 0, 0.1, 0.1, 0.1
' Zoom to Area
Part.ViewZoomTo2 0, 0, 0, 0.1, 0.1, 0.1
' Save As
longstatus = Part.SaveAs3("C:\Users\bguyetand\Desktop\Part1.DXF", 0, 2)
' Close Document
Set swDrawing = Nothing
Set Part = Nothing
swApp.CloseDoc "Part1 - Sheet1"
Set Part = swApp.ActiveDoc
Set myModelView = Part.ActiveView
myModelView.FrameLeft = 0
myModelView.FrameTop = 0
Set myModelView = Part.ActiveView
myModelView.FrameState = swWindowState_e.swWindowMaximized
swApp.ActivateDoc2 "Part1.SLDPRT", False, longstatus
Set Part = swApp.ActiveDoc
Set myModelView = Part.ActiveView
myModelView.FrameState = swWindowState_e.swWindowMaximized
' Close Document
Set swPart = Nothing
Set Part = Nothing
swApp.CloseDoc "Part1.SLDPRT"
End Sub
My problem is that currently, when I launch this maccro, it opens my test room that I had created (A simple cube) to unfold the steps.
In addition, it records all on the desktop.
Is it possible to explain to me in my maccro:
- How can I replace my "test" part with the "active" part on my screen?
- How do I save the files in the open room folder?
I hope I have been clear enough in my explanations
Thank you in advance for the time you will give me!!