I currently have a macro opening a 3D file with a family of parts, from the user's choice in a list, as well as the associated drawing. In some cases, my colleagues may need the file in STEP format so I am turning to you for clarification to do this operation using a macro. Here's what I'd like to do:
- Offer the user the STEP file recording of the part that is already open via an "OptionButton", - If the button is selected, I would like to save the file in STEP under another name: STEP_"name entered beforehand per user" - In another file, intended to host only STEP on the server with a basic path C:\Users\.......\STEP\STEP_"name previously entered per user". STEP
I've already looked through the macro recorder but I only get:
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
longstatus = Part.SaveAs3("C:\Users\cbr\Desktop\CAO W25\STEP\STEP.STEP", 0, 0)
End Sub
But does this seem quite light to me or is it really "that simple"?
Again, it's all in SW's API help: http://help.solidworks.com/2017/english/api/sldworksapi/solidworks.interop.sldworks~solidworks.interop.sldworks.imodeldocextension~saveas.html
and to specify the export options: http://help.solidworks.com/2017/english/api/swconst/filesaveasstepoptions.htm
So yes it's also but no it won't be for you because you'll have to replace in the maco cbr by the username which theoretically is different on each post it's the only problem I see ah and also put a variable for the file name :)
EDIT a priori this line would answer your problem of different environment variables
remrem I asked the question directly on the forum because things having already been done I thought I would find solutions faster (which is the case). And avoid running into the explanations of the API (which is also the case..) because I don't understand the Option and ExportData parameters. I understand even less why with the recorder this syntax is not respected.
MaD this recording path is temporary for my tests but in reality it will be a place on the server so I think it solves this problem. The variable with the name is already created and used :). I don't really see what this line does? A quo icorrespond ("WScript.Shell") please?
If you want to do a simple save under and step. That being said, I don't really see the point of making a macro for three clicks...
If you want to force the settings to be sure that your export will be as you want it and not according to the PC settings then everything is explained in the help.
Try to write a piece of code as explained and if you encounter a problem. Come back to us and we will try to explain or advise you... ;-)
That's precisely my goal, well it's not to avoid 3 clicks but it's in order to always have the same folder name, file name and the same record path.
So I tried the easy solution and it works in one case but not in the other:
'Pour l'enregistrement en fichier STEP
If Check_step.Value = True Then
EnregistrementSTEP = Part.SaveAs3("C:\Users\cbr\Desktop\CAO W25\STEP\STEP_" & ActiveConfiguration & ".STEP", 0, 0)
MsgBox "Le fichier STEP a été enregistré dans le dossier suivant : C:\Users\cbr\Desktop\CAO W25\STEP" & Chr(10) & "Sous le nom suivant : STEP_" & ActiveConfiguration, vbInformation, "Emplacement du fichier"
End If
I have the exact same code. In one case it works and in the other I get the error "Run-time error '91'" but I don't see what's wrong. Probably an undefined element but I don't see.
I just found out that the SaveAs3 method became obsolete in 2017. We must now use this: http://help.solidworks.com/2017/english/api/sldworksapi/SOLIDWORKS.Interop.sldworks~SOLIDWORKS.Interop.sldworks.IModelDocExtension~SaveAs.html
Ouch! I'll have to review part of my application in VB.net....
Edit: Pay attention to this paragraph:
"To save as an IGES, STL, or STEP file, the document to convert must be the active document. Before calling this method:
Damn, it's true that the code changes according to the version of SW... I'm in 2015 so SaveAs3 works at home but SaveAs doesn't work... Yes thank you that's what I noticed after posting my comment.
Is there a way where an existing table, allowing you to know "obsolete methods" please? Because I without that it will cause me problems.
Uh, the obsolete functions are not any more usable. I still use vba macros in SaveAs2 on SW2016 and it works very well (for exports in step, stl, iges, pdf)
The availability or not of some SW functions depends on the referenced dll.
From memory, VBA does not create a copy of the referenced DLLs, it uses the available one. It may happen that some functions have been removed in recent DLLs.
Dassault doesn't bother to fix its dlls, it adds functions, parameters and procedures as needed.
This has at least one advantage, which is that you can write backward compatible macros but also compatible with later versions but with loss of certain features.