

RHINOCEROS 5 BREAK OBJECT APART CODE
5.2 LoopingĮxecuting certain lines of code more than once is called looping in programming slang.

The above snippet could have been written as a nested If…Then structure, but then it would not resemble the way we think about the problem. In Python you can say the same thing in many different ways. If (dblCurveLength < rs.UnitAbsoluteTolerance()):Įlif (dblCurveLength < (10 * rs.UnitAbsoluteTolerance())): The conditional bit of the algorithm looks like this: dblCurveLength = rs.CurveLength(strObjectID) We won’t discuss the iteration part here. The user can then decide for himself whether those segments deserve to be deleted or retained. That way you can blame them when things go wrong.Ī good way of solving this would be to iterate through a predefined set of curves, delete those which are definitely short, and select those which are ambiguous. We could write a script which deletes these segments automatically, but where would we draw the line between ‘short’ and ‘long’? We could be reasonably sure that anything which is shorter than the document absolute tolerance value can be removed safely, but what about curves which are slightly longer? Rule #1 in programming: When in doubt, make the user decide. When you feel you need to split up the code stream into more than two flows and you don’t want to use nested structures, you can instead switch to something which goes by the name of the If…Elif…Else statement.Īs you may or may not know, the Make2D command in Rhino has a habit of creating some very tiny curve segments. The following example uses four nested If…Then structures to delete short, closed curves. You can nest If…Then structures as deep as you like, though code readability will suffer from too much indenting. So in the case of If…Else, one -and only one- of the two blocks of code is put to work. However, if SomethingOrOther is False, then the code after else is executed. This block can be as long as you like of course. If SomethingOrOther turns out to be True, then the bit of code between lines 1 and 3 are executed. Whenever you need an If…Then…Else structure, you can use the following syntax: if (SomethingOrOther): The shorthand for If…Then looks like: if (SomethingOrOther): DoSomething() In case of very simple If…Then structures, such as the first example, it is possible to use a shorthand notation which only takes up a single line instead of three. If SomethingOrOther turns out to be False, lines 2 and 3 are skipped and the script goes on with whatever comes after line 3. The bit of code that is indented after the if(): is evaluated and when it turns out to be True, the block of code between the first and last line will be executed. It always follows the same format: if (SomethingOrOther): The simplest If…Then structure can be used to shield certain lines of code. If…Then allows you to bifurcate the flow of a program. The most common conditional evaluation is the If…Then statement. We just need to learn how conditional syntax works.

The translation from English into Python is not very difficult. The third conditional is identical to the second one, except it defines more behavioral patterns depending on the outcome of the evaluation. We need to come up with a boolean way of talking about ‘short’ before we can evaluate it. Curves don’t become short all of a sudden any more than people grow tall all of a sudden. The second conditional must also evaluate the constraint ‘short’. The first conditional statement evaluates a single boolean value an object is either is a curve or it is not. If the object is a short curve, delete it, otherwise move it to the “curves” layer.If the object is a short curve, delete it.Let’s take a look at three conditionals of varying complexity: In any case, there’s always a lot of conditional evaluation going on, a lot of ‘what if’ questions. Other times we design our code to deal with more than one situation. A piece of code does not always behave in a straightforward manner and we need to catch these aberrations before they propagate too far. As a programmer, you need to take abstract thought to the next level the very-very-conscious level.Ī major part of programming is recovering from screw-ups.
RHINOCEROS 5 BREAK OBJECT APART SKIN
What if I were to fling this rock at that bear? What if I were to alleviate that moose from its skin and wear it myself instead? It’s questions like these that signify abstract thought, perhaps the most stunning of all human traits.
