Equation vs Text type Custom Properties with Add3

Hello everyone,

So with 2021, you get to put equation type custom property for your bodies. The thing is, when I use add3 with the swCustomInfoType for Text , which is 30, I get an equation type property that doesn’t work because well… it’s a text. Does anyone knows the correct/new type for the text or any kind of workaround?

Option Explicit

    Dim swApp               As SldWorks.SldWorks

    Dim vBodies             As Variant

    Dim swmodel             As SldWorks.ModelDoc2

    Dim swFeat              As SldWorks.Feature

    Dim swCustPropMgr       As SldWorks.CustomPropertyManager

    Dim FileNumber          As String

    Dim FileName            As String

    Dim Description         As String

    Dim NUMÉRO_DE_PIÈCE     As String

    Dim swBodyFolder        As SldWorks.BodyFolder

    Dim j                   As Integer

    Dim swBody              As Body2
    Dim sThickness          As String
    Dim PLnum               As Integer
    Dim EMnum               As Integer
    Dim PAnum               As Integer
    Dim PLnumStr            As String
    Dim EMnumStr            As String
    Dim PAnumStr            As String
    Dim BDtype              As Integer
    Dim EMverif             As String
    Dim EMverifNum          As Double
    Dim DescriptionProp     As String
    Dim NumdePieceProp      As String
Sub main()

    Set swApp = Application.SldWorks

    Set swmodel = swApp.ActiveDoc

    Set swCustPropMgr = swmodel.Extension.CustomPropertyManager("")
    FileName = swmodel.GetTitle

    FileName = Left(FileName, InStrRev(swmodel.GetTitle, ".") - 1)
    FileName = Right(FileName, 5)
    Debug.Print (FileName)
    PLnum = 0
    EMnum = 0
    PAnum = 0

    Set swFeat = swmodel.FirstFeature

        Do While Not swFeat Is Nothing


            If swFeat.GetTypeName() = "CutListFolder" Then

            Set swBodyFolder = swFeat.GetSpecificFeature2
            vBodies = swBodyFolder.GetBodies
                Set swCustPropMgr = swFeat.CustomPropertyManager

                Set swBody = vBodies(0)
                swCustPropMgr.Get4 "LONGUEUR", False, "", EMverif
                EMverifNum = Val(EMverif)
                If swBody.IsSheetMetal Then
                    PLnum = PLnum + 1
                    If PLnum < 10 Then
                        PLnumStr = "PL0" & Right(Str(PLnum), 1)
                        PLnumStr = "PL" & Right(Str(PLnum), 2)
                    End If
                    swCustPropMgr.Get4 "Epaisseur de tôlerie", False, "", sThickness
                    DescriptionProp = "PLAQUE " & sThickness
                    NumdePieceProp = FileName & "-" & PLnumStr

                    swCustPropMgr.Add3 "Description", 30, DescriptionProp, 1

                    swCustPropMgr.Add3 "NUMÉRO DE PIÈCE", 30, NumdePieceProp, 2
                    BDtype = swCustPropMgr.GetType2("NUMÉRO DE PIÈCE")
                    Debug.Print (PLnumStr)
                    Debug.Print (BDtype)
                ElseIf EMverifNum > 0 Then
                    EMnum = EMnum + 1
                    If EMnum < 10 Then
                        EMnumStr = "EM0" & Right(Str(EMnum), 1)
                        EMnumStr = "EM" & Right(Str(EMnum), 2)
                    End If
                    Set swCustPropMgr = swFeat.CustomPropertyManager
                    NumdePieceProp = FileName & "-" & EMnumStr

                    swCustPropMgr.Add3 "NUMÉRO DE PIÈCE", 30, NumdePieceProp, 2
                    BDtype = swCustPropMgr.GetType2("NUMÉRO DE PIÈCE")
                    Debug.Print (EMnumStr)
                    Debug.Print (BDtype)
                    PAnum = PAnum + 1
                    If PAnum < 10 Then
                        PAnumStr = "PA0" & Right(Str(PAnum), 1)
                        PAnumStr = "PA" & Right(Str(PAnum), 2)
                    End If
                    Set swCustPropMgr = swFeat.CustomPropertyManager
                    DescriptionProp = "AUTRE"
                    NumdePieceProp = FileName & "-" & PAnumStr
                    swCustPropMgr.Add3 "Description", 30, DescriptionProp, 1

                    swCustPropMgr.Add3 "NUMÉRO DE PIÈCE", 30, NumdePieceProp, 2
                    BDtype = swCustPropMgr.GetType2("NUMÉRO DE PIÈCE")
                    Debug.Print (PAnumStr)
                    Debug.Print (BDtype)
                End If

            End If

        Set swFeat = swFeat.GetNextFeature



End Sub


Do you have a part I can test this on?

Hi, I can’t really send you one, but it should work with any mutlibody part as long as the name of the document is in this format: 000-0000. I took the basic part template from SW, added a fake sheet metal body, saved the document and ran the macro and it worked.

@BigCrazyAl : Any thoughts?

@AmenJlili @jbrault
I wasn’t able to reproduce the issue you’re seeing where it wants to place an equation type property. I used SW version 2021 SP5.1.
The two properties that were added by your macro when run on a blank sheet metal part are shown below. They were added as a text property.

As a note, the filename variable didn’t seem to get the correct data from the Title of the file.


hello all,

I am struggling with the same problem right now.
I am trying to use a macro to add more properties to the cut list using the Add3 method.
Among others also the weight in pounds. Our stamdard is kilograms.
For the conversion from kg to lbs I need a property of type “Equation”. But there is no entry for this in the enumeration. I have already tried with unknown and text. With unknown the property is not created at all and with text I can read my formula as result.
I have also tried to determine the type of an existing property. The result is 30, which corresponds to the type “text”.

@jbrault: Have you found a working solution?

Yes I did resolved my problem by switching my SolidWorks to English.

Excuse me?

And what does switching to English do? Can you then select the type “equation” in the VBA programming?

Can you please explain your solution in more detail?

Well for me, setting up my SolidWorks in English instead of french fixed my issue, which was that I got an equation instead of a text when I used 30 with add3. In English, I directly had a text type property which is what I wanted. So I guess my solution doesn’t apply since you’re trying to do the opposite. I think they fixed this in 2022 but I’m not sure.

1 Like

Well it’s reported under SPR #1197201. Kindly vote for it.


Thanks to all for support

1 Like

I have found a solution!

If you use the oldest version “Add” instead of the newest method “Add3” it works!

The difference is due to the different declaration of the variables for fieldtype.
With “Add3” it is in VBA a variable of the type “Long” or selectable over an enumeration.
With “Add” it is in VBA a variable of the type “String” where I can enter what I want.

A first test with the old method was positive for me!


Can you please paste some code and a file that explains that here. I’d love to report that to API support.


how can I upload a part file and the macro?

You can upload to Dropbox, G Drive or similar websites and share the link here

You can paste the code here and wrap it in two of these ```

This is code

Upload your part file to WeTransfer and paste it here. Cadoverflow does not allow uploads of SOLIDWORKS files at the moment.

see my macro snippet and the example file in the Cadforum.net