I would like to change the custom properties for all of the sldlfp files that I have.
For example, for all of the square tubes have TS and then the sizes, "TS2.5x2.5x0.25" I would like the macro to replace the "TS" with "SQUARE TUBE" and laeve the sizing alone.
I have never written a macro so I don't know where to start.
SolidworksApi macros
Mike, do you need the macro to make the property as "SQUARE TUBE- 2.5x2.5x0.25" or "SQUARE TUBE2.5x2.5x0.25"
are you familiar with: http://www.spn-technologies.fi/spn-weldmentcreator.html
Either would work, but if I was choosing it would be "SQUARE TUBE 2.5x2.5x.025"
No I'm not, would this be worth the time if all the weldments are already created and all I need to do is change the files properties?
Probably not, if you are looking for a quick fix instead of long term administration of your weldment profiles.
Quick fix of course.
I did something very similar few years ago; here is the code, where you can easly set the custom property name you need to change and a folder where your library feature are stored:
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim swModelDocExt As ModelDocExtension
Dim swCustProp As CustomPropertyManager
Dim val As String
Dim new_val As String
Dim valout As String
Dim bool As Boolean
Const property_name As String = "Description"
Const folder_to_scan As String = "C:\temp\test\"
Sub main()
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Dim fld As Object
Dim fil As Object
Set fld = fso.GetFolder(folder_to_scan)
Set swApp = Application.SldWorks
For Each fil In fld.Files
Set swModel = swApp.OpenDoc(fil, 1)
Set swModelDocExt = swModel.Extension
' Get the custom property data
Set swCustProp = swModelDocExt.CustomPropertyManager("")
bool = swCustProp.Get4(property_name, False, val, valout)
Debug.Print "Value: " & val
Debug.Print "Evaluated value: " & valout
Debug.Print "Up-to-date data: " & bool
If bool Then
new_val = Replace(val, "TS", "SQUARE TUBE ")
bool = swCustProp.Set(property_name, new_val)
End If
swModel.SaveSilent
swApp.CloseDoc (fil)
Next
Set fil = Nothing
Set fld = Nothing
Set fso = Nothing
End Sub
Enjoy!
Try the attached one. Make sure you back up your data. Also the macro may hand while running on too many files (one after another), so better run on small number of files.
This macro has been made and tested on SW2012 SP 4 Win 7 x64, so you might have to fix the library reference issues in case you using a different SW version.
When I run the macro, I go to a folder in the pop up window, but then nothing happens.
Make sure you've the sldlfp files in the folder having the property you described. And what is your SW version.
Did you tried it again or can you send me your weldment profile file for testing.
I tried again and it didn't seem to work.
I did short test with WeldmentCreator, took about 2 minutes. Here is some example files, however I am not familiar with U.S dimensioning of profiles and also your profile file seemed to be lastly saved with SW2005 and earliest version that I do have installed is SW2009..
Oops I gave a wrong macro I made for someone else. I'll upload the correct one soon.
Ok test this one. The only thing which is going to bother you is that you'll be get a prompt window saying file is an older version (for every old file), so I would suggest you to click "Don't ask me again" checkbox. This will stop the prompt window to show again and again. And once you're done, you can go to Tools > Options > Message/Error/Warnings and remove this one from the list.
Hi I am having some trouble with my own custom properties macro. I use the macro in my work place but have moved the macro files onto my laptop and now they will not work. I have debugged the obvious file location detail which is now changed but I still can't get it to run. I am getting a runtime error '91' and the piece of code being flagged up is:
'Get current property values and enter into form
txtDate = swModel.CustomInfo2(strConfigName, "Date Designed")
txtDesignedBy = swModel.CustomInfo2(strConfigName, "Designed By")
txtDescription = swModel.CustomInfo2(strConfigName, "Description")
txtMaterial = swModel.CustomInfo2(strConfigName, "Material")
txtLength = swModel.CustomInfo2(strConfigName, "Length")
txtQty = swModel.CustomInfo2(strConfigName, "Qty/Machine")
txtMachineRef = swModel.CustomInfo2(strConfigName, "Machine Ref")
cboFirstOp = swModel.CustomInfo2(strConfigName, "First_Op")
cboSecondOp = swModel.CustomInfo2(strConfigName, "Second_Op")
cboThirdOp = swModel.CustomInfo2(strConfigName, "Third_Op")
cboForthOp = swModel.CustomInfo2(strConfigName, "Forth_Op")
txtRevNote = swModel.CustomInfo2(strConfigName, "RevNote
If anyone can help or direct me someone who could i would appreciate it greatly! All my other macros such as dxf converter are running fine.
Apologies for jumping on this post also. I've just signed up and havnt got onto the swing of things on the forum!
If your macro fails on these lines most likely your swModel variable is Nothing. Check how the swModel is initialized (opening of document, connection of active document) and check what's wrong. Most likely either there is no active file or the path to file is incorrect or file cannot be opened by some other reasons (newer version, broken) .
______________________
Regards,
Artem Taturevych
Application Engineer at Intercad
http://intercad.com.au/
Tel: +61 2 9454 4444
Hi Matteo
Can this macro be used to change properties in part and assembly file as well? I need to replace a specific text value in the config prop "Model No" to another text or even delete that particular text-string without touching anything else. Can you or someone else help me to modify this, if possible, Thanks
Newer mind. I just bought the Propa-Gator. It seems to be able to solve this