Hi everyone!
Via an Excel macro, I open a number of parts in SolidWorks. I would like to make a macro that would allow you to open the plan of the first active document, save it as a PDF, close the plan, save the part in STEP and then close the room and move on to the next room.
I'm just starting out in the world of macros so I'm looking at everything that's being done and I've picked it up right and left.
To save a plan in WWTP:
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
swModel.Extension.SaveAs Left(swModel.GetPathName, InStrRev(swModel.GetPathName, ".")) & "STEP", 0, 0, Nothing, 0, 0
swApp.CloseDoc Path
End Sub
To save a plan in WWTP:
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim FeatureData As Object
Dim Feature As Object
Dim Component As Object
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Path = Part.GetPathName 'chemin du fichier
Part.SaveAs2 Left(Path, (Len(Path) - 6)) & "PDF", 0, True, False 'Sauvegarde au format PDF
Set Part = Nothing
swApp.CloseDoc Path
End Sub
The problems I have are the following:
- I can't find a line of code that allows me to open the plan of the active document (which is still a room). I tried to create this line with the SoildWorks macro recorder and right-click/open the bet on the blalba part. SLDPRT in plan but it saves me as a line of code the opening of the plan blah blah. SLDDRW and not the opening of the plan of the active document.
- And my second problem is to create a loop. I found the structure of my loop:
Sub boucle_while()
While ?????????????? 'TANT QUE un document est actif
Wend
End Sub
But I don't know how to ask him to check that there is indeed an active document!
I think I'm not very far from the thing, you just have to check the condition, find how to open the plan...
Thank you to those who will take the time to take a look at my problem =)!