Deepak Kumar

How to add equation using macro ?

Discussion created by Deepak Kumar on Oct 6, 2020
Latest reply on Oct 7, 2020 by Eddy Alleman

Hi,

   I am trying to add an equation for a boss extrude dimension but it is showing syntax error like this -

 

 Can someone please help me out?

Thanks in advance!

Here is the code -

 

Option Explicit
Dim swApp As SldWorks.SldWorks
Dim Part As SldWorks.ModelDoc2
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long

Sub main()

Set swApp = Application.SldWorks

Set Part = swApp.ActiveDoc
boolstatus = Part.Extension.SelectByID2("Sketch2", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Neck Height", "PLANE", 0.032516860993212, -0.236429924300808, 6.79395168642856E-02, True, 1, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Boss-Extrude1", "SOLIDBODY", 0, 0, 0, True, 8, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Boss-Extrude2", "SOLIDBODY", 0, 0, 0, True, 8, Nothing, 0)
Dim myFeature As Object
Set myFeature = Part.FeatureManager.FeatureExtrusion2(True, False, False, 4, 0, 0.00254, 0.00254, True, False, True, False, 0.5235987755983, 0.5235987755983, False, False, False, False, True, True, False, 0, 0, False)
Part.SelectionManager.EnableContourSelection = False

boolstatus = Part.Extension.SelectByID2("Equations", "EQNFOLDER", 0, 0, 0, False, 0, Nothing, 0)
Dim swEquationMgr As SldWorks.EquationMgr
Set swEquationMgr = Part.GetEquationMgr()
swEquationMgr.Add -1, """D3@Boss-Extrude10"" = Atn("Rotated Riser Sleeve ID" / "Rotated Riser Neck Height" / 2 - "Rotated Riser Contact OD" / "Rotated Riser Neck Height" / 2)"
End Sub

Outcomes