Use Custom Properties in Filename

Can I automatically save a part using custom properties? Like, "PartNo" - Description.sldprt

(This doesn't work:

\\\$PRP:"PartNo" - \\\$PRP:"Description".sldprt)

Thanks!

SolidworksGeneral
Answers 8
JF
JF 2011-10-06 Best Answer

I don't know how it is done, but I believe it could be done with a macro.

ML
ML 2011-10-07
DF
DF 2011-10-07

It looks useful, but I can't download or install anything on the computer I'm working on.  Thanks though.  Any macro expert out there?

DG
DG 2011-10-07

The thing I can think is via macro and then you need to use the macro to save the file first time. Let me check my macro codes basket

It's already here: Save As File name based on custom property

DF
DF 2011-10-07

Thanks Deepak, acn you walk me through it? I'm not a macro guy.

My custom properties look like this:



So does "Number" become "PartNo", etc?

comment imagecomment image
DG
DG 2011-10-07

Yes and then we combine it with description in the macro.

DG
DG 2011-10-07

This is quick code you can test (since I don't have SW installed). This macro will save the part in the active working directory. In case you need to be able to specify a location, the codes needs to be modified. Also this one will overwrite any existing part with same name and will not prompt so be careful.

<p></p><p>Sub main()</p><p>Dim swApp As SldWorks.SldWorks</p><p>Dim swModel As SldWorks.ModelDoc2</p><p>Dim PartNo As String, Description As String </p><p></p><p>Set swApp = Application.SldWorks</p><p>Set swModel = swApp.ActiveDoc</p><p></p><p>PartNo = swModel.CustomInfo("PartNo")</p><p>Description = swModel.CustomInfo("Description")</p><p></p><p>swModel.SaveAs (PartNo + "-" + Description + ".sldprt")</p><p></p><p>End Sub</p>
DF
DF 2011-10-07

That's perfect, thank you!