Hi all
As described in the title of my question, when importing a file in STEP format that I get from CADENAS (partcommunity) and having a well-defined list of properties (since I will only use it for the Bossard library), I would like to be able to run a macro that would copy some properties (for example "BOMINFO" -> "DESIGNATION 1") from the "Summary" tab to the "Configuration-specific" tab, which has a list of properties from a standard custom properties file in my company.
I've already searched a lot on the forum without finding a method to adapt to my use case. So could you give me some advice, or even give me the macro syntax to use in this case?
Thank you in advance and wish you a good day.
Kind regards
Yann
2022-04-05_10_08_16-proprietes-recapitulatif.png2022-04-05_10_09_32-proprietes-specifiques-configuration.png
To read the properties of a configuration:
https://help.solidworks.com/2018/English/api/sldworksapi/Get_Custom_Properties_for_Configuration_Example_VB.htm
To read the document property:
https://help.solidworks.com/2016/English/api/sldworksapi/Add_and_Get_Custom_Properties_Example_VB.htm
An example of a snippet of code that I found in one of my macros, the first part looks if the configuration property is empty and if so it reads the document property.
Hoping this helps:
Dim swCustPropMgr As SldWorks.CustomPropertyManager
'Récupère la catégorie de la configuration active
Set swCustPropMgr = swPart.Extension.CustomPropertyManager(ActiveConfig) 'get properties
categorie = swCustPropMgr.Get("Categorie") 'get categorie
designation = swCustPropMgr.Get("Designation")
'Si la catégorie de la config active est vide on récupère celle du document
If categorie = "" Then
Set swCustPropMgr = swPart.Extension.CustomPropertyManager("") 'get properties
categorie = swCustPropMgr.Get("Categorie") 'get categorie
If designation = "" Then
designation = swCustPropMgr.Get("Designation") 'get categorie
End If
End If
Debug.Print "Catégorie: " & categorie
Otherwise, here's a course on SW macros for properties:
https://www.codestack.net/solidworks-api/data-storage/custom-properties/
https://blog.codestack.net/custom-properties-automation
Hello
For your information, I have already managed to write this code that creates the properties that do not exist in the "Summary" tab:
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim Value As String
Sub main()
Set swApp = CreateObject("SldWorks.Application")
Set swModel = swApp.ActiveDoc
Value = swModel.CustomInfo("DESIGNATION 1")
If Value <> "" Then
swModel.CustomInfo("DESIGNATION 1") = swModel.CustomInfo("BOMINFO")
Else
swModel.AddCustomInfo3 "", "DESIGNATION 1", swCustomInfoText, swModel.CustomInfo("BOMINFO")
End If
swModel.ForceRebuild3 (False)
swModel.Save
End Sub
How do I edit it so that properties are copied/created in the "Configuration Specific" tab?
Thanks in advance,
Yann
I just saw that you have access to the MyCADservice tools (for free), use Batchproperties or Integration, it may be easier for you and at worst you can make a ticket with Visiativ if you can't do it.
Or ask for help again
https://help.visiativ.com/mycadtools/2020/fr/BatchProperties.html
https://help.visiativ.com/mycadtools/2020/fr/Integration.html
1 Like
Hello sbadenis,
Thank you for your feedback, I'll take a look at the MyCADservice tools, the links and the example macro you gave me.
I will come back to my question quickly.
Otherwise on the same site there is this one that copies all the properties Customize to Configuration Specific (to the active configuration)
https://www.codestack.net/solidworks-api/data-storage/custom-properties/copy-file-specific-to-configuration/
With the addition of a condition like this, it should work:
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swCustPrpMgr As SldWorks.CustomPropertyManager
Dim swConfCustPrpMgr As SldWorks.CustomPropertyManager
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
If Not swModel Is Nothing Then
Set swCustPrpMgr = swModel.Extension.CustomPropertyManager("")
Dim vNames As Variant
Dim vTypes As Variant
Dim vValues As Variant
swCustPrpMgr.GetAll vNames, vTypes, vValues
Dim activeConfName As String
activeConfName = swModel.ConfigurationManager.ActiveConfiguration.Name
Set swConfCustPrpMgr = swModel.Extension.CustomPropertyManager(activeConfName)
Dim i As Integer
For i = 0 To UBound(vNames)
'remplacer ici "Essai" Par le nom ou les noms de propriété à récupérer
If vNames(i) = "Essai" or vNames(i) = "Essai2" Then
swConfCustPrpMgr.Add2 vNames(i), vTypes(i), vValues(i)
swConfCustPrpMgr.Set vNames(i), vValues(i)
End If
Next
Else
MsgBox "Please open part or assembly"
End If
End Sub
1 Like
sbadenis, thank you very much, thanks to your last piece of code, I adapted and it does exactly what I was looking for:
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swCustPrpMgr As SldWorks.CustomPropertyManager
Dim swConfCustPrpMgr As SldWorks.CustomPropertyManager
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
If Not swModel Is Nothing Then
Set swCustPrpMgr = swModel.Extension.CustomPropertyManager("")
Dim vNames As Variant
Dim vTypes As Variant
Dim vValues As Variant
swCustPrpMgr.GetAll vNames, vTypes, vValues
Dim activeConfName As String
activeConfName = swModel.ConfigurationManager.ActiveConfiguration.Name
Set swConfCustPrpMgr = swModel.Extension.CustomPropertyManager(activeConfName)
Dim i As Integer
For i = 0 To UBound(vNames)
'Remplacer la valeur de chaque "vNames(i)" par le nom de la propriété "Personnaliser" dont vous souhaitez récupérer la valeur.
'Pour chaque "swConfCustPrpMgr.Set" dans chaque fonction "If", remplacer le premier argument par le nom de la propriété de destination "Spécifiques à la configuration".
If vNames(i) = "BOMINFO" Then
swConfCustPrpMgr.Set "DESIGNATION 1", vValues(i)
End If
If vNames(i) = "BNARTNR" Then
swConfCustPrpMgr.Set "ARTICLE NUMBER", vValues(i)
End If
If vNames(i) = "BNMAT" Then
swConfCustPrpMgr.Set "MATERIAL", vValues(i)
End If
If vNames(i) = "BNSURFACE" Then
swConfCustPrpMgr.Set "SURFACE TREATMENT", vValues(i)
End If
If vNames(i) = "BNNORM1" Then
swConfCustPrpMgr.Set "SPECIFICATION", vValues(i)
End If
Next
Else
MsgBox "Please open part or assembly"
End If
End Sub
1 Like