Macro to add property

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

Task Scheduler: Property Update

http://help.solidworks.com/2016/french/SolidWorks/sldworks/HIDD_TASK_CUSTOM_PROPS.htm?id=b4a248bb4ed54a87a79966b065a1d4f4#Pg0&ProductType=&ProductName=

 

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

Look http://help.solidworks.com/2016/English/api/sldworksapi/Get_Custom_Properties_for_Configuration_Example_VB.htm, there's an example of an addition.

Kind regards

2 Likes

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,

Thank you very much d.roger, it works perfectly!!

Top contributor in macro!!

Sincerely,

1 Like

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