I would like to create a macro to process existing parts:
These parts already have one (or more) configuration(s). I would like to retrieve the " Article Code" custom property from configuration " 00 ". Then get only the first 11 characters and add a suffix.
This new " Article Code" will allow you to fill in configurations that are created in the rest of the macro. This part is already done.
Basically, my macro should activate the " 00 " configuration as follows:
''' Activation de la config 00
boolstatus = swModel.ShowConfiguration2("00")
Then retrieve the value of the " Article Code" property and with a LEFT retrieve the first 11 characters in a variable that I could assign for the other configurations.
I tried this command, but it bugs:
''' Récupération de la propriété Code Article existante
lRetVal = swCustProp.Get6("Code Article", False, ValOut, CodArt00, False, False)
I'm going in the direction of @Maclane and if the lines are from the macro initiated in this topic ( Macro multiplication - Macro - myCAD Forum (visiativ.com)), you have to look in the variable declarations if there is not a problem. In the same way, Get doesn't work if the property you're looking for doesn't exist (you have to add an existence check in this case and create it if necessary)
Thank you both. I made a test code that works. So I'm going to integrate it into my macro so that it informs my RAL configurations.
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swConfigMgr As SldWorks.ConfigurationManager
Dim swConfig As SldWorks.Configuration
Dim vConfigNameArr As Variant
Dim stnameConfig As String
Dim boolstatus As Boolean
Dim swModelDocExt As ModelDocExtension
Dim swCustProp As CustomPropertyManager
Dim sValout As String
Dim CodArt00 As String
Dim CodArtRAL As String
Dim CodeArticle As String
Dim lRetVal As String
Dim ValOut As String
Type ConfigData
confName As String
CodArt00 As String
CodArtRAL As String
End Type
Sub main()
Set swApp = Application.SldWorks
Dim swModel As SldWorks.ModelDoc2
''' Récupération du document actif
Set swModel = swApp.ActiveDoc
Set swConfigMgr = swModel.ConfigurationManager
''' Récupération de la configuration active
Set swConfig = swConfigMgr.ActiveConfiguration
stnameConfig = swConfig.Name
vConfigNameArr = swModel.GetConfigurationNames
Set swModelDocExt = swModel.Extension
Set swModelDocExt = swModel.Extension
''' Activation de la config 00
boolstatus = swModel.ShowConfiguration2("00")
stnameConfig = swConfig.Name
Set swCustProp = swModelDocExt.CustomPropertyManager(stnameConfig)
''' Récupération de la propriété Code Article existante
lRetVal = swCustProp.Get6("Code Article", False, ValOut, CodArt00, False, False)
'Renvoie les onze premiers caractères du Code Article
MsgBox Left(CodArt00, 11)
''' Ajout du Code Article RAL à partir des 11 caractères gauche du Code Article
CodArtRAL = (Left(CodArt00, 11)) & "R6005"
MsgBox (CodArtRAL)
End Sub