Hello
Is it possible to add a custom property by macro, indeed I got old parts of a big folder that don't have "MASS" "SW-Masse@mapiece.SLDPRT" or "DESCRIPTION" "text" properties, it would be faster to add them by a small macro.
If anyone has a start of a track it would be nice, I couldn't find anything on the forum.
Kind regards.
1 Like
Thank you Olivier42,
Yes, convenient, but you can't assign "SW-Masse@", and I prefer to do it as I go along on each part I modify.
Kind regards
Hello
if you do so as you change the parts; Copying and pasting should do the trick.
1 Like
Hello
Thank you d.roger for your very interesting point, after many tinkering I managed to make a macro that works! The problem is that I want to add properties not only to the config but also to the general properties and here I can't do it.
If you could help me it would be nice.
Kind regards
Option Explicit
Public Enum swCustomInfoType_e
swCustomInfoUnknown = 0
swCustomInfoText = 30
swCustomInfoDate = 64
swCustomInfoNumber = 3
swCustomInfoDouble = 5
swCustomInfoYesOrNo = 11
End Enum
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 retVal As Long
Dim noma As String
Dim nomb As String
Dim nom As String
Dim Att As String
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swConfigMgr = swModel.ConfigurationManager
Set swConfig = swConfigMgr.ActiveConfiguration
noma = swModel.GetTitle
nom = noma & """"
nomb = """"
Att = swModel.GetCustomInfoValue("", "DESIGNATION")
Set swCustPropMgr = swConfig.CustomPropertyManager
' Add custom property MASSE ET DESIGNATION to this configuration
retVal = swCustPropMgr.Add2("MASSE", swCustomInfoText, nomb & "SW-Mass@" & nom)
retVal = swCustPropMgr.Add2("DESCRIPTION", swCustomInfoText, Att)
End Sub
Hello
You should not put the configuration name in the swCustPropMgr.Add2 options. Leaving the name conf empty it goes into the general properties.
Hello
Here's a small example that allows you to fill in all configurations, including general properties:
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelDocExt As ModelDocExtension
Dim configNames() As String
Dim configName As String
Dim swConfig As SldWorks.Configuration
Dim cusPropMgr As SldWorks.CustomPropertyManager
Dim i As Long
Dim retVal As Long
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
configNames = swModel.GetConfigurationNames
For i = 0 To UBound(configNames)
configName = configNames(i)
Set swConfig = swModel.GetConfigurationByName(configName)
Set swCustPropMgr = swConfig.CustomPropertyManager
retVal = swCustPropMgr.Add2("MASSE", swCustomInfoText, """SW-Mass@@Défaut@Plaque-2.SLDPRT""")
retVal = swCustPropMgr.Add2("DESCRIPTION", swCustomInfoText, "Ma désignation")
Next i
Set swModelDocExt = swModel.Extension
Set swCustPropMgr = swModelDocExt.CustomPropertyManager("")
retVal = swCustPropMgr.Add2("MASSE", swCustomInfoText, """SW-Mass@@Défaut@Plaque-2.SLDPRT""")
retVal = swCustPropMgr.Add2("DESCRIPTION", swCustomInfoText, "Ma désignation")
End Sub
Kind regards
4 Likes
Thank you d.roger, I'm trying tonight...
Sincerely,
Hello
I'm back to the charge because I manage to retrieve the "DESIGNATION" info in the general properties:
Att = swModel.GetCustomInfoValue("", "DESIGNATION")
But what is the command to retrieve this info if the "DESIGNATION" property is specifically in a (default) configuration.
Thank you for your help...
Cyril.f informed me.
Thank you
Thank you very much d.roger, it works perfectly!!
Top contributor in macro!!
Sincerely,