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
swFeat.GetSpecificFeature2
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)
Else
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)
Else
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)
Else
PAnum = PAnum + 1
If PAnum < 10 Then
PAnumStr = "PA0" & Right(Str(PAnum), 1)
Else
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
Loop
swBodyFolder.UpdateCutList
End Sub
Thanks