Equations (Global Variables) Macro

Is it possible to automatically insert equations (global variables) into the model using a macro? Are there any example codes for this? I just want to have a macro that, when clicked, inserts a few equations like "XYZ = Thickness * 5"

Jest możliwość w ogóle żeby makrem automatycznie wstawiać równania (zmienne) globalne do modelu? Są jakies przykładowe kody do tego? Chciałbym po prostu mieć makro, które po kliknięciu wstawi mi kilka równań np. POLE = Grubość * 5

 

Answers 1
TH
TH 2025-06-11

Im using VBA and hope this might be helpful: Sub AddGlobalVariable()
   Dim swApp As SldWorks.SldWorks
   Dim swModel As SldWorks.ModelDoc2
   Dim swEqMgr As SldWorks.EquationMgr
   Dim eqIndex As Long

   Set swApp = Application.SldWorks
   Set swModel = swApp.ActiveDoc
   Set swEqMgr = swModel.GetEquationMgr

   ' Add global variable "Thickness" if not already defined
   eqIndex = swEqMgr.Add3(0, """Thickness"" = 2", True, swAllConfiguration, Empty)

   ' Add equation using the global variable
   eqIndex = swEqMgr.Add3(1, """XYZ"" = ""Thickness"" * 5", True, swAllConfiguration, Empty)
End Sub