Hi all
I am a dissertation student at the ICAM in Lille and I work on Solidworks. I use part families for door assemblies and for the sake of simplification, I would like to use an Excel macro. The latter should allow the saving of Excel files related to Solidworks parts and assemblies and the registration of parts and assemblies on Solidworks (which is a problem for me today).
To explain how I proceeded, here is an explanatory diagram.
Looking forward to reading you.
Kind regards
Arnaud Duhame
explication.pdf
Hello,
I'm only going to answer you partially, but you should be able to add references for SolidWorks in the references (Tools -> References).
Tip: "SOLIDWORKS 2016 Commands type library / SOLIDWORKS 2016 Constant type library", etc.
And then work on it.
This is the same way I perform actions on the vault from Excel (On the other hand, I haven't tested with SolidWorks so I don't know at all if what I'm saying is feasible).
KVuilleumier.
Well, I had little hope but after a few tries, I succeeded.
Dim swApp As SldWorks.SldWorks
Sub TestSW()
Set swApp = New SldWorks.SldWorks
swApp.SendMsgToUser "Hi"
swApp.NewPart
End Sub
This macro (Executed from Excel) sends me the message "Hi" and opens a new 3D document.
Here are the references to add:
- SldWorks 2016 Type Library
- SolidWorks 2016 Exensibility Type Library
- SOLIDWORKS Utilities 2015 Type Library
- SOLIDWORKS 2016 Constant type library
- SOLIDWORKS 2016 Commands type library
Edit: Do you need anything else?
Hello KVuileumier,
Thank you for your answer, I checked the references for solidworks and I had activated them.
To open solidworks files, I use this macro (from Excel):
Sub Macro1()
Dim Software As String
Dim File As String
Dim ToLaunch
Dim RetVal
Software = """C:\Program Files\SOLIDWORKS Corp\SOLIDWORKS\SLDWORKS.exe"""
File2 = """C:\Users\MSI\Desktop\test\round. SLDPRT"""
ToLaunch2 = Software & " " & File2
RetVal = Shell(ToLaunch2, 1)
End Sub
My problem is mainly how to save this file that is open?
Thank you for your help
Kind regards
Arnaud
Well, let's imagine that it's the active file that we want to save, we would have to do a manipulation like this:
In variable definitions:
Dim swModel As SldWorks.ModelDoc2
In the function (As far as swApp is defined, see my previous answer if necessary):
Set swModel = swApp.ActiveDoc
swModel.Save3 swSaveAsOptions_Silent, 0, 0
Do you need something else? Or do you not understand something?
KVuilleumier
Unfortunately I have the impression that I don't understand. I attach the modified macro with your proposals as well as the order file and the solidworks part.
Thank you in advance for your help.
Kind regards
Arnaud Duhamel
teste.zip