Hi all
How to transcribe a Solidworks equation of this type:
"hauteur@Esquisse1" = "largeur@Esquisse1" * 2
with a macros under VBA? the code it forms to?
The goal is to set up a part using only VBA.
Thank you in advance.
Hi all
How to transcribe a Solidworks equation of this type:
"hauteur@Esquisse1" = "largeur@Esquisse1" * 2
with a macros under VBA? the code it forms to?
The goal is to set up a part using only VBA.
Thank you in advance.
Hello
SW Online Help is a wealth of information. For APIs, here's the link: http://help.solidworks.com/2015/english/api/sldworksapiprogguide/Welcome.htm
You will find an example of adding equations in a room with several configurations : http://help.solidworks.com/2015/english/api/sldworksapi/Add_Equations_Example_VB.htm
See you.
At worst if you don't find what you're looking for, maybe you can try to record a macro by doing your equation, get into the code and see what the software does?
Hello
First of all, thank you for your answers.
I've already looked at the SW help but the examples offered are with conditions, in my case I don't need them.
Not having much knowledge in development I tried to tinker with the code but in vain nothing works:(
With the macro recorder it doesn't work, it doesn't take into account the equation written in solidworks.
Thank you in advance.
So in this case it had to be said right away.
Because to develop a functional macro for you, we need much more information about the purpose and the use you want to make of it.
And it takes a lot of time.
What I need is a macro capable of executing this type of equation:
"hauteur@Esquisse1" = "largeur@Esquisse1" * 2
If that's just why, why not do equations every time?
Because then, you'll have to give the right name to the right rating so that he knows how to go for it. I'm not very convinced of the time saved :s
I created a form with VBA to set up a 3D model.
This form allows me to change the length, width, height of the template.
There are also cases to check to delete or undo a component deletion (depending on the options chosen).
If I create equations on my components within my assembly, when I delete them (with the checkcases) solidworks tells me errors on my equations. That's why I want to proscribe SW equations in my model
Oh yes, of course.
Well otherwise to answer you on an equation in VBA, I do it like this
Cells(i, "I"). Value = Sheet3.Cells(a, "E"). Value * Cells(i, "C"). Value
So, for you it would be
largeur@esquisse1" = Cells(i, "C"). Value* 2
where Cells(i, "C") would correspond to the excel box for setting the value "hauteur@esquisse1"
On the other hand, I don't know at all how to create the link between excel and the value of a dimension (but I guess you know how to do that?). So I'll let you integrate it as you see fit.
That said, it can be nice to put your code snippet in response for the next readers who will be looking for the same type of answer;)
I don't work with Excel but with the VBA module of Solidworks.
Below is a code I have to modify my values whether it is length, width or a number of repetitions.
I'm looking for the same type of code but to create relationships between certain parts
Set SwApp = CreateObject("SldWorks.Application") ' @Corps CamVane 100.sldasm
Set Part = SwApp.ActiveDoc
Part.Parameter("D1@Lg traverse@Traverse lower CamVane.part"). SystemValue = (dimension.width.value - 3) / 1000
Part.ClearSelection
Part.ForceRebuild
Part.Parameter("D1@Distance2@Corps CamVane 100.sldasm"). SystemValue = dimension. Height.value / 1000
Part.ClearSelection
Part.ForceRebuild
Part.Parameter("D5@Lg traverse@Traverse lower CamVane.part"). SystemValue = dimension.thickness.value / 1000
Part.ClearSelection
Part.ForceRebuild
Part.Parameter("linear D1@Répétition locale1@Corps CamVane 100.sldasm"). SystemValue = UserForm1.TextBox1.value
Part.ClearSelection
Part.ForceRebuild
Part.ViewZoomtofit2
Part.ForceRebuild
boolstatus = Part.EditRebuild3()
Still not able to solve my problem:(
Hello
I have found the answer to my question.
For what I'm interested in, I put the code below.
Sub main()
Set swApp = CreateObject("SldWorks.Application")
Set Part = swApp.ActiveDoc
Part.Parameter("hauteur@Esquisse1"). SystemValue = Part.Parameter("largeur@Esquisse1"). SystemValue *2
Part.ClearSelection
Part.ForceRebuild
Part.ViewZoomtofit2
Part.ForceRebuild
boolstatus = Part.EditRebuild3()
End Sub
Hello
I have found the answer to my question.
For what I'm interested in, I put the code below.
Sub main()
Set swApp = CreateObject("SldWorks.Application")
Set Part = swApp.ActiveDoc
Part.Parameter("hauteur@Esquisse1"). SystemValue = Part.Parameter("largeur@Esquisse1"). SystemValue *2
Part.ClearSelection
Part.ForceRebuild
Part.ViewZoomtofit2
Part.ForceRebuild
boolstatus = Part.EditRebuild3()
End Sub