I am curious if someone could help me write a script that i can run using batchprocess to take all of the properties in a part, custom and config and take whats in there, and force all of the characters to be capitalized.
SolidworksApi macros
I am curious if someone could help me write a script that i can run using batchprocess to take all of the properties in a part, custom and config and take whats in there, and force all of the characters to be capitalized.
SolidworksApi macros
This is a good one, I would like to have that myself. I have a macro that copies the model custom properties to a drawing file. So copying out custom prop's is pretty easy I just don't how to force upper case. If it would help you to get the base code of extracting the prop's let me know and I'll gladly share it.
Tom
Guys,
If you're using VBA just use the UCase() function. In VB.NET / C# you can use .ToUpper.
So during your loop you'll probably have something like this (VBA):
For Each vName In vCustPropNames
swCustPropMgr.Get3 vName, True, strValue, Empty
swCustPropMgr.Set vName, UCase(strValue)
Next vName
Hope this helps,
Keith
Training for the SolidWorks API
So, how would I work that into this type of query. I have written this query to move properties from the config to custom properties sheet.
I'm thinking i can modify it to simply extract the existing, transform it with the Ucase, then reinsert them.
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swConfigMgr = swModel.ConfigurationManager
Set swConfig = swConfigMgr.ActiveConfiguration
Debug.Print "Name of this configuration: " & swConfig.Name
Dim SRCName
SRCName = ModelDoc2.GetPathName
SRCName = ParsePath(SRCName, 0, -7)
Set swCustPropMgr = swConfig.CustomPropertyManager
Set cpm = swModel.Extension.CustomPropertyManager("")
'Copy the value for specified Configuration property. Add more lines for other properties.
swCustPropMgr.Get3 "Description", itemval1, resolveditemval1
swCustPropMgr.Get3 "Description2", itemval2, resolveditemval2
swCustPropMgr.Get3 "Revision", itemval3, resolveditemval3
swCustPropMgr.Get3 "Used On", itemval4, resolveditemval4
swCustPropMgr.Get3 "Date", itemval5, resolveditemval5
swCustPropMgr.Get3 "Created by", itemval6, resolveditemval6
swCustPropMgr.Get3 "Buyer", itemval7, resolveditemval7
swCustPropMgr.Get3 "BuyMake", itemval8, resolveditemval8
swCustPropMgr.Get3 "Finish", itemval9, resolveditemval9
swCustPropMgr.Get3 "Material", itemval10, resolveditemval10
swCustPropMgr.Get3 "Material2", itemval11, resolveditemval11
'Delets the specified Configuration property. Add more lines for other properties.
cpm.Delete "Description"
cpm.Delete "Description2"
cpm.Delete "Revision"
cpm.Delete "Used On"
cpm.Delete "Date"
cpm.Delete "Created by"
cpm.Delete "Buyer"
cpm.Delete "BuyMake"
cpm.Delete "Finish"
cpm.Delete "Material"
cpm.Delete "Material2"
'Add specified Custom property. Add more lines for other properties or change config name if required.
swModel.AddCustomInfo3 "", "Description", swCustomInfoText, itemval1
swModel.AddCustomInfo3 "", "Description2", swCustomInfoText, itemval2
swModel.AddCustomInfo3 "", "Revision", swCustomInfoText, itemval3
swModel.AddCustomInfo3 "", "Used On", swCustomInfoText, itemval4
swModel.AddCustomInfo3 "", "Date", swCustomInfoText, itemval5
swModel.AddCustomInfo3 "", "Created by", swCustomInfoText, itemval6
swModel.AddCustomInfo3 "", "Buyer", swCustomInfoText, itemval7
swModel.AddCustomInfo3 "", "BuyMake", swCustomInfoText, itemval8
swModel.AddCustomInfo3 "", "Finish", swCustomInfoText, itemval9
swModel.AddCustomInfo3 "", "Material", swCustomInfoText, itemval10
swModel.AddCustomInfo3 "", "Material2", swCustomInfoText, itemval11
'Copy the value for specified Configuration property. Add more lines for other properties.
swCustPropMgr.Get3 "Description", itemval1, resolveditemval1
swCustPropMgr.Set "Description", UCase(itemval1)
...
...
And so on for each custom property.
You don't need to delete and re-insert. Just use ICustomPropertyManager::Set to change the value of an existing custom property.
Also if you created a loop you wouldn't need to write out statements for every single custom property, which also means that you'll have to modify the macro any time that this code needs to be run on additional custom properties.
Keith
Video Tutorials for the SolidWorks API
Keith,
Thanks for your reply, I'm trying your avice using the loop you provided, but I keep getting an error
Run-time error '438":
Here is the code i'm referencing. Sorry, I'm very new to VBA and so still trying to learn the API.
Thank you in advance for all of your help!
Thanks,
Jeremiah
Object doesnt support this property or method.
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swConfigMgr = swModel.ConfigurationManager
Set swConfig = swConfigMgr.ActiveConfiguration
Set swCustPropMgr = swConfig.CustomPropertyManager
Set vCustPropNames = swConfig.CustomPropertyManager
Dim vName As Object
For Each vName In vCustPropNames
swCustPropMgr.Get3 vName, True, strValue, Empty
swCustPropMgr.Set vName, UCase(strValue)
Next vName
End Sub
Jeremiah,
Everything you need to get started with the API is available for free at my web site, so I'd encourage you to check it out. There is also a free PDF with causes and solutions to the 15 most common VBA errors, including the one you received.
The following code will change all of the custom properties in the active configuration from lower to upper case.
=======
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swConfigMgr As SldWorks.ConfigurationManager
Dim swConfig As SldWorks.Configuration
Dim swCustPropMgr As SldWorks.CustomPropertyManager
Dim vCustPropNames As Variant
Dim vName As Variant
Dim strValue As String
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swConfigMgr = swModel.ConfigurationManager
Set swConfig = swConfigMgr.ActiveConfiguration
Set swCustPropMgr = swConfig.CustomPropertyManager
vCustPropNames = swCustPropMgr.GetNames
For Each vName In vCustPropNames
swCustPropMgr.Get3 vName, True, strValue, Empty
swCustPropMgr.Set vName, UCase(strValue)
Next vName
End Sub
=======
Keith
Video Tutorials for the SolidWorks API