sketchucation logo sketchucation
    • Login
    🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    If statement issue with # divided by -0

    Scheduled Pinned Locked Moved Dynamic Components
    sketchup
    9 Posts 5 Posters 2.1k Views 5 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • DavidBoulderD Offline
      DavidBoulder
      last edited by

      I have a stretchable surface that I'm dividing in the x and y direction through two user inputs.

      If the user enters "5" then I draw file dividing lines (including the two edges) so I end up with four gaps. So to get the correct measurement I take LenX/(n-1). This works great unless the user's original number was 1. The desired result if the user enters "1" is to just have a line at one edge.

      Of course if I leave things as they are I get an error because I'm dividing by 0. So I created an If statment something like this

      if(n=1,do this,LenX/(n-1)). So what is odd, is that when I have a value of 1 and should just "do this" I still get an error about the Div/0. I'm not sure why. Has anyone else run across this.

      --

      David Goldwasser
      OpenStudio Developer
      National Renewable Energy Laboratory

      1 Reply Last reply Reply Quote 0
      • S Offline
        steel.monkee
        last edited by

        i'm not sure i get your point or question. if my memory serves me right any number divided by zero is infinite. try running that into your calculator or excel and you will get an error.

        Kapag maiksi ang kumot, matutong mamaluktot.

        1 Reply Last reply Reply Quote 0
        • R Offline
          remus
          last edited by

          I think David's problem is that it still divides by zero even after he's created an if() statement to try and get around the issue.

          http://remusrendering.wordpress.com/

          1 Reply Last reply Reply Quote 0
          • chrisglasierC Offline
            chrisglasier
            last edited by

            if(n=** **=****1,do this,LenX/(n-1)) ?

            With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.

            1 Reply Last reply Reply Quote 0
            • DavidBoulderD Offline
              DavidBoulder
              last edited by

              @unknownuser said:

              if(n==1,do this,LenX/(n-1)) ?

              what is the double equals for? SketchUp doesn't seem to like "==" in that formula.

              --

              David Goldwasser
              OpenStudio Developer
              National Renewable Energy Laboratory

              1 Reply Last reply Reply Quote 0
              • R Offline
                remus
                last edited by

                == is the 'comparison' symbol in ruby, so i guess chris was thinking that DCs might prefer this operator to '='.

                As fa as i know, DCs are designed to behave like a spreadsheet in terms of notaion, so i think the '=' is correct. Dont know whats causing the problem though.

                http://remusrendering.wordpress.com/

                1 Reply Last reply Reply Quote 0
                • chrisglasierC Offline
                  chrisglasier
                  last edited by

                  Yes that's why I put a ? Seems odd that DC's should use different operators than ruby and javascript (= is used to assign a value to a variable; == or === to test true or false) ... but definitely the if part is being ignored unless I'm really getting senile.

                  With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.

                  1 Reply Last reply Reply Quote 0
                  • DavidBoulderD Offline
                    DavidBoulder
                    last edited by

                    FYI - I just added a file to this. It is a sample version of Sang with three Dynamic Attributes.
                    TestFormula = =if(usernumber=1,"you are 1",usernumber/(usernumber-1))
                    anotherformula = =if(usernumber=1,"you are 1","you are not 1")
                    usernumber = (user input)

                    Each formula has the same formula except for the "false" case which is where the div0 is in the "Test Formula). Why does it care what is in that until it fails the "usernumber!=1" test.

                    So the IF isn't being ignored unless I happen to have a value that makes a Div0. It is as if it checks for that before it bothers reading the formula. If there aren't any Div0's then it correctly uses the If statement like it should.


                    Sang-div0 test.skp

                    --

                    David Goldwasser
                    OpenStudio Developer
                    National Renewable Energy Laboratory

                    1 Reply Last reply Reply Quote 0
                    • D Offline
                      danbig
                      last edited by

                      Hi David -

                      I've noticed that sometimes, if the very first time a formula is assessed, the result is zero, I get an error. I don't know if this could be the issue here.

                      If n=1, does the formula return zero?

                      My work around is to write a formula that never returns zero, and then let the DC evaluate it. Once it has accepted a non-zero value, I can edit the formula to allow a zero value, and it seems to work fine. (An example of when this comes up is a RotX, RotY, or RotZ value that is set by a user input box; I initially get an error if the value in the box is zero, but if I start with a non-zero value in the user input box when I create the formula in the RotY attribute, it works fine, even if I set it back to zero.)

                      I don't know if this is related to what you're doing here, but it may be worth a shot if you have the result of the formula set to zero when n=1.

                      1 Reply Last reply Reply Quote 0
                      • 1 / 1
                      • First post
                        Last post
                      Buy SketchPlus
                      Buy SUbD
                      Buy WrapR
                      Buy eBook
                      Buy Modelur
                      Buy Vertex Tools
                      Buy SketchCuisine
                      Buy FormFonts

                      Advertisement