Macro for saving file using Custom Properties as file name
Macro for saving file using Custom Properties as file name
(OP)
Alright, I am new to Macros so I have just been recording and reading at this point. My goal is to create a macro that will combine two or more fields from the custom properties as the file name and save in the current directory. Is there a macro out that does something similar to this that I can look at?
Thanks!
Joe
Thanks!
Joe






RE: Macro for saving file using Custom Properties as file name
http://www.cadimensions.com/Resources/macros.cfm
Maybe you can rename the configuration to the property you want before running the macro.
Flores
SW06 SP3.0
RE: Macro for saving file using Custom Properties as file name
Just so I understand what you want. Yow want a macro to take the custom property name or the value for the custom property, combine them and then save the current solidworks document using those custom properties as the file name?
SA
RE: Macro for saving file using Custom Properties as file name
New file name would be <sales order #><Unit #>.sldprt
RE: Macro for saving file using Custom Properties as file name
Since you are trying to learn about macros, here is just a code snippet of how you might go about it. The macro will run but it does not include any error checking that you would want to add to make it a more polished macro and I do not include any code on how to obtain the configuration name.
CODE
Dim swModel As SldWorks.ModelDoc2
Dim FileName As String
Dim SaveErrors As Long
Dim SaveWarnings As Long
Dim retval As Boolean
Dim SalesOrderNumber As String
Dim UnitNumber As String
Sub main()
'get SolidWorks object
Set swApp = GetObject(, "SldWorks.Application")
'get active model object
Set swModel = swApp.ActiveDoc
'get sales order #
SalesOrderNumber = swModel.CustomInfo2("ConfigurationName", "SalesOrder")
'get unit #
UnitNumber = swModel.CustomInfo2("ConfigurationName", "Unit")
'create file name
FileName = SalesOrderNumber & UnitNumber & ".sldprt"
'save part with new file name
retval = swModel.SaveAs4(FileName, swSaveAsCurrentVersion, swSaveAsOptions_Silent, SaveErrors, SaveWarnings)
End Sub
One question I forgot to ask was if the custom properties are in the Custom or Configuration Specific tab. If they are in the Custom tab, replace "ConfigurationName" with "".
Just so you know, I did test the code, and it did work on my computer so if you have any problems running it, get back to me and I will try and help you work through it.
SA
RE: Macro for saving file using Custom Properties as file name
Thanks for the code, it works perfectly. I was able to change a couple of the names and now it will save it with the correct name!
I am slowing getting this, thanks for your help!
Joe