-
Re: Macro change global variable
Paul Churm Jan 7, 2016 11:26 AM (in response to Willem Van Opstal)Hi Willem,
You can use an example like this to itterate over all the Global Variables you have.
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swEqnMgr As SldWorks.EquationMgr
Dim i As Long
Dim nCount As Long
Dim bRet As Boolean
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swEqnMgr = swModel.GetEquationMgr
Debug.Print "File = " & swModel.GetPathName
Debug.Print " Status = " & swEqnMgr.Status
nCount = swEqnMgr.GetCount
For i = 0 To nCount - 1
Debug.Print " Eqn(" & i & ") = " & swEqnMgr.Equation(i)
Debug.Print " Value = " & swEqnMgr.Value(i)
Debug.Print " Supp = " & swEqnMgr.Suppression(i)
Next i
End Sub
Hope this helps to get you started.
Paul
-
Re: Macro change global variable
Deepak Gupta Jan 7, 2016 12:04 PM (in response to Willem Van Opstal)Try these codes
Option Explicit
Sub main()
Dim SwApp As SldWorks.SldWorks
Dim Part As SldWorks.ModelDoc2
Dim swEquationMgr As SldWorks.EquationMgr
Set SwApp = Application.SldWorks
Set Part = SwApp.ActiveDoc
Set swEquationMgr = Part.GetEquationMgr
'swEquationMgr.SetEquationAndConfigurationOption 0, """Global Variable Name here"" = Required value", swAllConfiguration, Empty
swEquationMgr.SetEquationAndConfigurationOption 0, """A"" = 5", swAllConfiguration, Empty
End Sub
-
Re: Macro change global variable
Willem Van Opstal Jan 7, 2016 12:54 PM (in response to Deepak Gupta)Seems to work, thanks!
But... It won't accept my variable as an input instead of the '5'. The variable comes from an inputform (check my other problem )
-
Re: Macro change global variable
Scott Stuart Jan 7, 2016 4:31 PM (in response to Willem Van Opstal)The return from the inputform will be a string. You probably need to cast that to a double with something like
dblVariable = Cdbl(input)
-
-
Re: Macro change global variable
Willem Van Opstal Jan 7, 2016 1:32 PM (in response to Deepak Gupta)OK, I'm sorry for the last reply.
It seems not to work as I like.... First time I run the macro at a freshly opened model, it generates a NEW global variable. Second time I'll run the macro, It deletes the created one. Third and all times after that, it does nothing...
This is with a fixed number for the value...
-
Re: Macro change global variable
Deepak Gupta Jan 7, 2016 1:49 PM (in response to Willem Van Opstal)The codes I've posted above assume that you already have a global variable.
For e.g. add a variable A with any value and then run the codes. The value should change to 5.
Option Explicit
Sub main()
Dim SwApp As SldWorks.SldWorks
Dim Part As SldWorks.ModelDoc2
Dim swEquationMgr As SldWorks.EquationMgr
Set SwApp = Application.SldWorks
Set Part = SwApp.ActiveDoc
Set swEquationMgr = Part.GetEquationMgr
swEquationMgr.SetEquationAndConfigurationOption 0, """A"" = 5", swAllConfiguration, Empty
End Sub
-
Re: Macro change global variable
Willem Van Opstal Jan 7, 2016 2:30 PM (in response to Deepak Gupta)Did this for an existing variable, but it just creates another one (with exactly the same name!).
I can't figure out why, because when I'd like to add a new global variable with exactly the same name by hand, SW gives me a warning that the new one would override the existing...
I'll try and try, thanks for the help!
btw, I store my variable as 'dblRatio' using the CDbl(textfield) commands.
-
Re: Macro change global variable
Deepak Gupta Jan 8, 2016 6:46 AM (in response to Willem Van Opstal)It was working fine for me last night when I posted it up and now it is not working for me also
-
Re: Macro change global variable
Willem Van Opstal Jan 8, 2016 7:31 AM (in response to Deepak Gupta)Thanks for all the help, I worked a bit around it. It's working fine when I let it create a new variable and modify that one.
Only thing isn't working yet is the variable from the inputform.. With fixed numbers it's working fine.
On button click;
dblRatio = CDbl(txtRatio.Text / 100)
swEquationMgr.SetEquationAndConfigurationOption 4, """Ratio"" = dblRatio", swAllConfiguration, Empty
-
-
-
Re: Macro change global variable
Willem Van Opstal Jan 8, 2016 7:31 AM (in response to Deepak Gupta)Experimented some with the given macro. It works fine when I create a new global variable, when I change the value the globalvariable changes also.
But when I use the name of an existing variable, it creates another one, deletes it, and does nothing after that.
Any suggestions?
-
-
-