Fun With SolidWorks Equations

March 26, 2008

SolidWorks Equations Are Cool

Disclaimer:  This post isn’t directly API-related but using logic statements in SolidWorks equations is so useful that I decided to post it.  Also, the syntax is in a kind of “techno-weenie-ese” so I thought I would help folks with the syntax. 

 The SolidWorks equation editor is a very useful, powerful and yet easy to use tool for building design intent into your SolidWorks model.  However, most people don’t take full advantage of its power.  In addition to support for constants, which are nice, the equation editor allows If…Then type logic statements.  The idea is that you can set a dimension’s value to one of two values depending on the veracity of a logic statement pertaining to another/other dimension(s).  Say what?….

 Time for an example…

 Let’s say I have dimensions A, B and C.  I want to set C = 4 if A+B<5.  If however, A+B>=5 then I want to set C=8.  This is relatively easy to do using the the IIF statement (if statement to lay people).  The syntax is like this:  IIF([test statement],[value if true],[value if false]).  In our example above, the statement would look like this:  IIF(A+B<5, 4, 8).  Pretty simple, right?  I thought so.  In SolidWorks, it would look like this:  d2@extrude1=IIF(”d1@sketch4″+”d2@sketch4″<5, 4, 8). 

 As the example video below shows, IIF statements can be extremely powerful in conjunction with the Instant3D functionality that was added in SolidWorks 2008.  Notice how the hub diameter and number of spokes is updated real-time as I drag the ID  accross the 3.00in threshhold.

You may download the example file show from here.

If you enjoyed this post, make sure you subscribe to my RSS feed!

Comments

10 Responses to “Fun With SolidWorks Equations”

  1. Tina Russell on March 26th, 2008 11:32 am

    I finally decided to write a comment on your blog. I just wanted to say good job. I really enjoy reading your posts.

    Tina Russell

  2. Knox on March 26th, 2008 4:15 pm

    I see you double click the cylinder to show the sketch/dimensions, but how are you able to drag it larger in real time? I have Instant3D turned on, yet everything acts fully constrained, even if I make the I.D. dimension driven…

  3. Jeff on March 26th, 2008 9:58 pm

    Knox,

    The dimensions that may be dragged real-time will show little blue balls when the dimensions are shown. It is those blue balls that you drag. Does that help?

    Thanks for reading.

    Jeff

  4. Knox on March 27th, 2008 1:57 pm

    Thanks Jeff, it works perfectly. Great site by the way!

  5. solidworm on March 31st, 2008 11:17 pm

    I love Navier-Stokes!

  6. solidworm on March 31st, 2008 11:18 pm

    an i love solidworks too !

  7. Daniel Rohats on April 22nd, 2008 2:40 pm

    Thanks again for a great article with an actual example that can easily be modified to suite other needs and conditions. As always a great read, informative AND entertaining.

    Thanks again,

    Daniel

  8. Joel on July 3rd, 2008 2:48 pm

    Hey there, Good post, thanks!
    Any advice on making a more complex IFF statement. I’m trying to embed a length equation into the IFF for spacing cross members in conveyor. For instance, I need 4 braces if the total conveyor length is greater than 96in but I only need three braces if the conveyor is shorter than that. The issue comes with evenly spacing the three braces that are left. Or, maybe there’s another way around it?
    Thanks,
    Joel

  9. Jeff Cope on July 4th, 2008 1:47 am

    Hi Joel,

    Thanks for reading. You can nest IFF statements. Just put your second IIF statement inside the False condition portion of the first IFF statement. I don’t know if there is a limit to how many you may nest but I have not run into it in Excel or Access. I think SolidWorks should be the same with regard to that.

    Also, I haven’t tried it yet but there is something called a Switch statement (and another lesser used function called Choose) that sounds similar to what you are looking for. Excel and Access both support it so I was wondering if SolidWorks does as well. I haven’t tried it yet but if you try it, then please post the results here.

    You can read up on them here:
    http://www.dailydoseofexcel.com/archives/2005/02/21/the-switch-function/

    Thanks,
    Jeff

  10. Joel on July 8th, 2008 11:18 am

    Ahh thanks, got it. Just took a bit more work. I’ll probably be trying out the switch statment soon. I’ll try to let you know how it goes.

Got something to say?