Nathan McCluskey

Move Description Macro

Discussion created by Nathan McCluskey on Sep 15, 2020
Latest reply on Sep 15, 2020 by Deepak Gupta



I have wrote a short macro for moving the configuration description (Capture3 & Capture4) into the custom properties. I have a couple of problems which I hope somebody can help me with. They are below:

1. The custom property "Title" sticks with only the first description it holds and does not update with each configuration.

2. The custom property is placed under the custom tab and it needs to be placed in the configuration specific tab as it can be different for each configuration (Capture & Capture1)


The code I have is below. Sorry for it being messy as im new to macros and have just got code from the solidworks API help.


' Preconditions: Part or assembly is open.
' Postconditions: None
' NOTE: Configurations are not supported on drawings
Option Explicit

Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim vConfigNameArr, vConfigName As Variant
Dim swConfig As SldWorks.Configuration
Dim swParentConfig As SldWorks.Configuration
Dim swConfMgr As SldWorks.ConfigurationManager
Dim vChildConfigArr, vChildConfig As Variant
Dim swChildConfig As SldWorks.Configuration
Dim swCustPropMgr As SldWorks.CustomPropertyManager
Dim i, RetVal As Long
Dim bRet As Boolean
Dim Des As String

Set swApp = CreateObject("SldWorks.Application")
Set swModel = swApp.ActiveDoc
Set swConfMgr = swModel.ConfigurationManager
Set swConfig = swConfMgr.ActiveConfiguration
Set swCustPropMgr = swModel.Extension.CustomPropertyManager("")


' Always at least one configuration will exist
vConfigNameArr = swModel.GetConfigurationNames
For Each vConfigName In vConfigNameArr

Set swConfig = swModel.GetConfigurationByName(vConfigName)

Debug.Print "Description = " & swConfig.Description
Debug.Print "Title = " & swCustPropMgr.Get("Title")

'Set Des varible to the current configuartions description
Des = swConfig.Description

'Add Des varible to the custom specific property manager, under Title
swCustPropMgr.Add3 "Title", swCustomInfoType_e.swCustomInfoText, Des, swCustomPropertyAddOption_e.swCustomPropertyOnlyIfNew

' Process parent
Set swParentConfig = swConfig.GetParent
If Not swParentConfig Is Nothing Then
Debug.Print "Parent = " & swParentConfig.Name
End If

' Process children
vChildConfigArr = swConfig.GetChildren
If Not IsEmpty(vChildConfigArr) Then
For Each vChildConfig In vChildConfigArr
Set swChildConfig = vChildConfig

Debug.Print "Child = " & swChildConfig.Name

End If
Debug.Print ""

End Sub