×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Macro for saving file using Custom Properties as file name
3

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

RE: Macro for saving file using Custom Properties as file name

Not exactly what you are looking for, but it might be a start. Save Configurations macro:
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

2
JoeMoss,

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

(OP)
SA, you are correct. We are importing data into a DT, part of that data is sales order # and a unit #. I am assigning those values to custom properties (for drawings and file name) and I would like to pull from custom properties to save off the new file.

New file name would be <sales order #><Unit #>.sldprt

RE: Macro for saving file using Custom Properties as file name

JoeMoss,

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 swApp As SldWorks.SldWorks
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

(OP)
SA,
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources