Macro Property Configuration

Good evening

 

I'm looking for a macro that would update the SOLIDWORKS properties of a configuration.

Currently I use these two lines of code to update the properties but the update is done on the document and not on a specified configuration.

 

bRet = swmodel. DeleteCustomInfo2("", "ma_propriété")

bRet = swmodel. AddCustomInfo3("", "ma_propriété", swCustomInfoText, "here the value of the property")

 

 

Do you have any information to give me on this subject?

 

In advance, thank you

 

 

Sylvain

 

 

 

 

 

 

 

2 Likes
Good evening I advise you to look at this link http://help.solidworks.com/2013/English/api/swdocmgrapi/get_configuration_information_example_vbnet.htm

At the risk of being a bit "heavy", why not use Smartproperties (Axemble utility for sale on Lynkoa) rather than running macros (personally I don't master, that's why !!!).

 

For people who don't master macro programming, this type of utility is still the best thing we do, right?

 

For your information, I don't get a cent on the sale of the Smartproperties van!!!!!!!!

 

 

http://www.lynkoa.com/store/fr/tools-et-macros/utilitaire-smartproperties.html

 

4 Likes

@flegendre

It is true that smartproperties fulfills this function, but it is complex because it does more  

Hello

 

You have to use the CustomPropertyManager api where you specify the name of the configuration to be modified "" for custom properties.

 

Then on the object you have the Add, Get, Set, and Delete APIs to create, retrieve, modify, and delete them:

 

http://help.solidworks.com/2013/English/api/sldworksapi/SolidWorks.Interop.sldworks~SolidWorks.Interop.sldworks.ICustomPropertyManager_members.html

 

@Lucas Prieur : your link is the API to use if the document is closed

 

Example:

 

Option Explicit

Dim swApp As SldWorks.SldWorks

Dim swModel As ModelDoc2

Dim swModelDocExt As ModelDocExtension

Dim swCustProp As CustomPropertyManager

Dim val As String

Dim valout As String

Dim bool As Boolean

 

Sub main()

 

Set swApp = Application.SldWorks

Set swModel = swApp. ActiveDoc

Set swModelDocExt = swModel. Extension

' Get the custom property data

 

Set swCustProp = swModelDocExt. CustomPropertyManager("Configuration Name")

 

bool = swCustProp. Get4("Property_Name", False, val, valout)

 

Debug.Print "Value: " & val

Debug.Print "Evaluated value: " & valout Debug.Print "Up-to-date data: " & bool

 

End Sub

7 Likes

Hello

 

Thanks for those answers, I'll look into it.

As for SMARTPROPERTIES, I use it. In fact, I have a button in the SMARTPROPERTIES that lanes a macro with a SQL query that points to the ERP.

From the values of a property, I retrieve some parameters from the ERP to put them back in the SOLIDWORKS properties.

 

I'll keep you posted

 

Thank you

 

sylvain

 

 

2 Likes

Hello

Here is an example that completes prossignol's answer

 

I use this macro to remove properties in all part and assembly configurations:

 

Option Explicit
    Dim swApp               As SldWorks.SldWorks
    Dim swModel             As SldWorks.ModelDoc2
    Dim swModelDocExt       As SldWorks.ModelDocExtension
    Dim swConfig            As SldWorks.Configuration
    Dim swCustPropMgr       As SldWorks.CustomPropertyManager
    Sun i                   As Long
    Dim vConfName           as Variant
    Dim valOut              As String
    
Public Enum swDocumentTypes_e
    swDocNONE = 0       '  Used to be TYPE_NONE
    swDocPART = 1       '  Used to be TYPE_PART
    swDocASSEMBLY = 2   '  Used to be TYPE_ASSEMBLY
    swDocDRAWING = 3    '  Used to be TYPE_DRAWING
    End Enum

Sub main()
    
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    
  'Removed properties in the Configuration Specific tab
  If swModel.GetType <> swDocDRAWING Then
    vConfName = swModel.GetConfigurationNames
    For i = 0 TB UBound(vConfName)
        Set swConfig = swModel.GetConfigurationByName(vConfName(i))
        'Debug.Print'  Configuration = ' & vConfName(i)
        Set swCustPropMgr = swConfig.CustomPropertyManager
        
        swCustPropMgr.Delete "Author"
        swCustPropMgr.Delete "Project"
        swCustPropMgr.Delete "Status"
        swCustPropMgr.Delete "Number"
 
   Next i
 End If
 
End Sub

2 Likes

For minimal modification with your code

just specify the name of the config instead of the empty field

 

bRet = swmodel. DeleteCustomInfo2("Config Name", "ma_propriété")

bRet = swmodel. AddCustomInfo3("Config name", "ma_propriété", swCustomInfoText, "here is the value of the property")

 

But it is advisable to go through the response of prossignol

8 Likes

Have you managed to update your macro???

1 Like

 Hello everyone,

 

Thank you for your answers that just solved the problem.

 

 

Sylvain