Kaust rhino workshop 2011

Post on 12-May-2015

144 views 0 download

Tags:

description

A presentation about Scripting in Rhino 3D Software. It was designed, developed and delivered in King Abdullah University of Science and Technology on April, 2011

transcript

SCRIPTINGINRHINOKAUST‐ April,2011

Geometric Modeling and Scientific Visualization CenterGeometricModelingandScientificVisualizationCenter

KhaledMohamedAhmedAbdElGawadwww.khaledarch.comwww.khaledarch.com

Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Outline Introduction VBScript Essentials Operators and functionsp

Conditional Execution/Branching Arrays Surface and Polysurface MethodsSurface and Polysurface Methods

Show Cases Grasshopper Overview Useful Resources

Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Useful Resources

Introduction

Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

WhatWeCanDoUsingRhinoScript?

Computational Design Solution ‐ IAP Coursehttp://www.kaschaandjohn.com/rhinoscripting/

Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

WhatWeCanDoUsingRhinoScript?

Khaled Abd El Gawad – All rights reserved – www.khaledarch.comComputational Design Solution ‐ IAP Course http://www.kaschaandjohn.com/rhinoscripting/

WhatWeCanDoUsingRhinoScript?

Computational Design Solution ‐ IAP Coursehttp://www.kaschaandjohn.com/rhinoscripting/

Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

WhatWeCanDoUsingRhinoScript?

http://www.rhinoscript.org/gallery/2

Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Scriptingvs.ProgrammingLanguages. These days, the line between a scripting language and 

i l i bl da programming language is blurred. 

Scripting Languages: Run Inside other programsRun Inside other programs Are not compiled. A t d t it Are easy to use and easy to write. Scripting languages are used to build complex software. Scripting languages are so efficient

Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

p g g g

Macros Rhinoceros is based on

a command linea command‐line interface.

A macro is a prerecorded list of orders for Rhino to executeexecute.

Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Macros Example:

A (0, 0, 0)

B(10, 0, 0)

Open100 Add line Save FilesRhino Files

Macros allow you to automate tasks you would normally do by hand but not by brain. 

Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Scripts Scripts are text files which are interpreted one line at 

ia time.

Scripts have control over which line is executed next.

We must familiarize ourselves with the language rules f VBS ript b f fl t lof VBScript before we can use flow control.

Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

HowtoRunaScript? We could store scripts as external text files and have Rhino load them whenever we want to run themRhino load them whenever we want to run them

We could also use Rhino's in‐build script editor. _EditScript Command line_ p Tools  Rhinoscript Edit

Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

HowtoRunaScript?The Script Window will show upshow up

Then we can write i t i t thour script into the 

Script Editor window th li k tthen click execute

Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

HowtoRunaScript? Or we can embed scripts in toolbar buttons, which makes it very hard to edit them but much easier tomakes it very hard to edit them, but much easier to distribute them.

Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

VBScriptEssentials

Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Languageorigin VBScript is a member of the BASIC language family.

The language was designed to be easy for humans to understand.

BASIC stands for Beginner’s All‐purpose Symbolic Instruction Code.Instruction Code.

Rhino Scripting syntax rules are basically the same as Rhino Scripting syntax rules are basically the same as Visual BASIC.

3/12/2014 16Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

FlowControl We use it to skip certain lines of code or 

To execute others more than once. 

To jump to different lines in our script and back again.To jump to different lines in our script and back again.

You can add conditional statements to your code You can add conditional statements to your code which allow you to shield off certain portion

3/12/2014 17Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Variable Data From a programmer's point of view, a variable is a location in your computer's memory in which you canlocation in your computer s memory in which you can store a value and from which you can later retrieve that valuethat value.

A visual representation of memory3/12/2014 18Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

A visual representation of memory

Variable Data Whenever we need to store data or perform calculations or logic operations we need variables tocalculations or logic operations we need variables to remember the results.

33 33..44 datadata

X Y Variable name3/12/2014 19Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

X Y Variable name

Variable Data There are different data types: Integers, doubles, Booleans strings and Null variableBooleans, strings, and Null variable.

D blInteger

Double Boolean

NullSt i datadataString datadata

Variable name

3/12/2014 20Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Variable Data: Integers and Doubles Doubles are numeric variables which can store numbers with decimalsnumbers with decimals. 

3/12/2014 21Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Variable Data: Booleans Boolean variables can only store two values mostly referred to as Yes or No True or Falsereferred to as Yes or No, True or False.

In VBScript we never write "0" or "1" or "Yes" or "No”

We always use "True" or "False".

3/12/2014 22Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Variable Data: Strings Strings are used to store text. 

Whenever you add quotes around stuff in VBScript, it automatically becomes a String. 

So if we encapsulate a number in quotes, it will become textbecome text

3/12/2014 23Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Variable Data: Strings String Assignment and Concatenation

3/12/2014 24Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Variable Data: Strings When using  & you can treat numeric variables as StringsStrings

3/12/2014 25Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Variable Data: Null Variable When a variable has no value, it considered to be null.

Having a null value is different than having a value of 0, since 0 is an actual value.

Whenever we ask Rhino a question which might not have an answer, we need a way for Rhino to say "I don't know"

3/12/2014 26Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Using Variables Variable Declaration: W ll d l i bl i h Di We normally declare a variable using the Dimkeyword.

We can declare multiple variables using a singleWe can declare multiple variables using a single Dim keyword if we comma‐separate them.

3/12/2014 27Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Using Variables Variable Names: I i d d fi It is recommended to use prefixes. Use a 3 character prefix which indicates the type of variable

V i bl t P fi E lVariable type Prefix ExampleBoolean bln blnSuccessInteger int intXDouble dbl dblYDouble dbl dblYString str strfood

3/12/2014 28Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Using Variables Variable Assignment: B f f i bl Before you can use any of your variables, you must first assign them a value.

3/12/2014 29Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

OperatorsandFunctions

Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Operators and Functions

Th i fi t i th f ll i The previous figure contains the followings: Numbers (15, 26, 2.33 and 55) Variables (x, y, and z) Operators ( =, +, * and /)p ( , , /) Functions (Sin, Sqr, Tan and Log)

3/12/2014 31Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Operators in RhinoScript Arithmetic Operators C i O Concatenation Operators Comparison Operators Logical and bitwise Operators

3/12/2014 32Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Operators in RhinoScript Arithmetic Operators C i O Concatenation Operators Comparison Operators Logical and bitwise Operators

3/12/2014 33Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Operators in RhinoScript Operator Precedence

The acronym PEMDAS or "Please Excuse My Dear  Aunt Sally" is common. 

It stands for Parentheses, Exponents, Multiplication, Division, Addition, Subtraction.Multiplication, ivision, Addition, Subtraction.

3/12/2014 34Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Operators in RhinoScript Operator Precedence B d i i f h ld d h Based on previous info how could we code the following?

PEMDAS

3/12/2014 35Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Operators in RhinoScript Operator Precedence B d i i f h ld d h Based on previous info how could we code the following?

PEMDAS

Solution:

y = Sqr(x ^ 2 + (x ‐ 1)) / (x ‐ 3) ) + Abs( (2 * x) / (x ^ (0.5 * x)) 

Solution:

3/12/2014 36Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Operators in RhinoScript Operator Precedence T i lif h i d i To simplify the equation we can spread it out over multiple lines of code

y = Sqr(x ^ 2 + (x ‐ 1)) / (x ‐ 3) ) + Abs( (2 * x) / (x ^ (0.5 * x)) 

3/12/2014 37Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Operators in RhinoScript Arithmetic Operators C i O Concatenation Operators Comparison Operators Logical and bitwise Operators

3/12/2014 38Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Operators in RhinoScript Arithmetic Operators C i O Concatenation Operators Comparison Operators Logical and bitwise Operators

3/12/2014 39Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Operators in RhinoScript Arithmetic Operators C i O Concatenation Operators Comparison Operators Logical and bitwise Operators

3/12/2014 40Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Operators in RhinoScript: Logical Operators

Logical operators mostly work on Booleans.

Boolean mathematics were developed by George Boole (1815‐1864) and today they are at the very core of the entire digital industry.

Boolean algebra provides us with tools to analyze, compare and describe sets of data.

M f h B l O N A d Most famous three Boolean Operators are: Not, And, and Or.

3/12/2014 41Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Operators in RhinoScript: Logical Operators

A good way to exercise your own Boolean logic is to use Venn‐diagrams. 

A Venn diagram is a graphical representation of Boolean sets where every region contains a (sub) setBoolean sets, where every region contains a (sub) set of values that share a common property.

3/12/2014 42Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Operators in RhinoScript: Logical Operators

3/12/2014 43Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Operators in RhinoScript: Logical Operators

3/12/2014 44Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Operators in RhinoScript: Logical Operators

3/12/2014 45Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Operators in RhinoScript: Logical Operators Venn diagrams are useful for simple problems, but once you start dealing with more than three regions itonce you start dealing with more than three regions it becomes a bit opaque.  6 i l V di P tt b t t ti l 6‐regional Venn diagram. Pretty, but not very practical

3/12/2014 46Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Functions in RhinoScript Microsoft VBScript has 89 built in functions:

Sin(n) Sine of a number

Cos(n) Cosine of a numberCos(n) Cosine of a number

Atn(n) ArcTangent of a number

Log(n) Natural logarithm of a number larger than 0

Sqr(n) Square root of any positive numberSqr(n) Square root of any positive number

Abs(n) Absoluter (positive) value of any number

3/12/2014 47Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Functions in RhinoScript Rhino adds over 200 functions called methods:

Rhino.command (“_Move 0, 0, 0 2, 0, 1”)

Rhino.UnselectAllobjects()Rhino.UnselectAllobjects()

Rhino.Selectobject (strCurveID) Rhino.Copyobject (strCurveID) Rhino.GetObject (“Select an object”)Rhino.GetObject ( Select an object )

3/12/2014 48Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

What is a Function? A function is a closed body of code that executes a specific taskspecific task.

A function is like a black box.  It takes in input,  does something with it does something with it, 

and then spits out an answer. A function may not take any inputs at all or it may not return anything at all.return anything at all.

3/12/2014 49Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Function Example

3/12/2014 50Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Why Would We Need Functions? we can write it as a single function and access the same function again and again as many times as it issame function again and again as many times as it is required.

We can avoid writing redundant code of some instructions again and again.

Programs with using functions are compact & easy to understand.understand.

Testing and correcting errors is much easier.

3/12/2014 51Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Why Would We Need Functions? We can understand the flow of program, and its code easily since the readability is enhanced while using theeasily since the readability is enhanced while using the functions.

A single function written in a program can also be used in other programs also.

3/12/2014 52Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Script File Structure Every script must implement a certain structure which tells the interpreter what's whattells the interpreter what s what.

3/12/2014 53Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Script File Structure Every script must implement a certain structure which tells the interpreter what's whattells the interpreter what s what.

3/12/2014 54Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Script File Structure Option Explicit: It is optional, but it is highly recommended.

If you use it, you have to define all your variables before you can useyour variables before you can use them. 

If you don’t use it your variables If you don t use it, your variables will be declared for you by the compilercompiler. 

3/12/2014 55Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Script File Structure Option Explicit: It may also contains a set of comments. 

Comments are blocks of text in the script which are ignored by thescript which are ignored by the compiler and the interpreter. 

comments are used to add comments are used to add explanations to a file, or to disable certain lines of codecertain lines of code. 

Comments are always preceded by 

3/12/2014 56Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

an apostrophe. 

Script File Structure Global Variables: They are optional. Typically you do not need globalTypically you do not need global variables and you're usually better off without them.off without them.

3/12/2014 57Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Script File Structure The Main Function

Every script requires at least one function contains the main code of the script. 

it can place calls to any number ofit can place calls to any number of other functions 

It delineates the extents of the It delineates the extents of the script. 

The script starts running as soon as this function is called and it stops 

3/12/2014 58Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

when the function completes. 

A Simple Function Example

3/12/2014 59Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

A Simple Function Example

3/12/2014 60Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

ConditionalExecution/Branching

Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Conditional execution or Branching IF….Then Statement

Select case LoopingLooping

Conditional loops Incremental loops

Nested LoopsNested Loops

3/12/2014 62Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

IF….Then Statement  If we have three different situations:

1. If the object is a curve, delete it.

2. If the object is a short curve, delete it.2. If the object is a short curve, delete it.

3. If the object is a short curve, delete it, otherwise it t th “ ” lmove it to the “curves” layer.

How would this be implemented using RhinoScript?

3/12/2014 63Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

IF….Then Statement  If we have three different situations:

1. If the object is a curve, delete it.

2. If the object is a short curve, delete it.2. If the object is a short curve, delete it.

3. If the object is a short curve, delete it, otherwise it t th “ ” lmove it to the “curves” layer.

How would this be implemented using RhinoScript?

This is so easy. We just need to learn how conditional syntax works.

3/12/2014 64Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

y

IF….Then Statement 1. If the object is a curve, delete it.

2. If the object is a short curve, delete it.

3/12/2014 65Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

IF….Then Statement 3. If the object is a short curve, delete it, otherwise 

move it to the “curves” layermove it to the  curves  layer.

3/12/2014 66Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Select … Case We use Select…Case when we want to check the  

equalityequality.

3/12/2014 67Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Select … Case (Sort objects based on type)

An Integer to store the An Integer to store the Rhi ObjRhi Obj T dT dRhino ObjectRhino Object‐‐Type codeType code

3/12/2014 68Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Select … Case (Sort objects based on type)

This means the object This means the object does not exist; abortdoes not exist; abort

3/12/2014 69Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Select … Case (Sort objects based on type)

A String to store a layer A String to store a layer namename

3/12/2014 70Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Select … Case (Sort objects based on type)

Compare the actual Compare the actual d h hd h htype code with the type code with the 

preset onespreset ones

3/12/2014 71Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Select … Case (Sort objects based on type)

Points andPoints and PointCloudPointCloudPoints and Points and PointCloudPointCloudobjectsobjects

3/12/2014 72Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Select … Case (Sort objects based on type)

CurvesCurves

3/12/2014 73Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Select … Case (Sort objects based on type)

Surfaces and Surfaces and PolySurfacesPolySurfacesPolySurfacesPolySurfaces

3/12/2014 74Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Select … Case (Sort objects based on type)

MeshesMeshes

3/12/2014 75Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Select … Case (Sort objects based on type)

LightsLights

3/12/2014 76Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Select … Case (Sort objects based on type)

Annotations and Annotations and TextDotsTextDots

3/12/2014 77Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Select … Case (Sort objects based on type)

BlocksBlocks

3/12/2014 78Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Select … Case (Sort objects based on type)

Any other objects; Any other objects; AbortAbort

3/12/2014 79Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Select … Case (Sort objects based on type)

If h lIf h lIf the layer we are If the layer we are about to assign does about to assign does 

not yet existnot yet existnot yet exist…not yet exist…

3/12/2014 80Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Select … Case (Sort objects based on type)

Create itCreate it

3/12/2014 81Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Select … Case (Sort objects based on type)

Assign the object to the Assign the object to the layerlayer

3/12/2014 82Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Looping Executing certain lines of code more than once is 

called looping in programming slangcalled looping in programming slang.

The two most important syntax for loops:

Conditional Loops (Do loop Do While loop Conditional Loops  (Do…loop,   Do While…loop,  Do Until…loop)

Incremental loops (For...Next)

3/12/2014 83Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Conditional loops We use it when we do not know how many iterations 

we will need in advancewe will need in advance. 

This type is called a Do…Loop.

3/12/2014 84Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Conditional loops: Do…Loop This example script contains an endless Do…Loop

which can only be cancelled by the user pressingwhich can only be cancelled by the user pressing (and holding) escape.

3/12/2014 85Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Conditional loops: Do…Loop

1 & 2: Option Explicit declaration and comments about who's who and what's whatabout who s who and what s what

4: Main Function call

3/12/2014 86Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Conditional loops: Do…Loop

5:Main function declaration

6 W d l i bl hi h i bl f t i 6:We declare a variable which is capable of storing a Rhino object ID

3/12/2014 87Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Conditional loops: Do…Loop

7:We create a new Rhino Text object

Rhi AddT t ( t T t P i t [ dblH i ht [ t F t [Rhino.AddText (strText, arrPoint [, dblHeight [, strFont [, intStyle]]])

3/12/2014 88Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Conditional loops: Do…Loop

8: Just in case the text object hasn't been created we need to abort the subroutine in order to prevent anneed to abort the subroutine in order to prevent an error later on.

3/12/2014 89Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Conditional loops: Do…Loop

10: Starting the loop

11 W d t h th t t d 11: We need to change the text once every second. The Rhino.Sleep() method will pause Rhino for the specified amo nt of milliseconds

3/12/2014 90Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

specified amount of milliseconds.

Conditional loops: Do…Loop

12: Here we replace the text in the object with a new String representing the current system time.String representing the current system time.

3/12/2014 91Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Conditional loops: Do While…Loop

This kind of loop syntax will abort the loop when S C di i i lSomeCondition is False.

3/12/2014 92Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Conditional loops: Do Until…Loop

If we want the loop to terminate when a condition b i d f l h U ilbecomes True instead of False, we can use the Until keyword instead of the While keyword

3/12/2014 93Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Conditional loops: Do…Loop While

You can be guaranteed that DoSomething will be ll d l b i h f ll icalled at least once by using the following syntax:

3/12/2014 94Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Incremental loops

We use it when the number of iterations is known in dadvance.

The variable i starts out by being equal to A and it is incremented by N until it becomes larger than Bincremented by N until it becomes larger than B.

Once i > B the loop will terminate. 

3/12/2014 95Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Incremental loops

Example

3/12/2014 96Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Nested Loops

The following example shows how nested For…Next b d di ib istructures can be used to compute distributions:

3/12/2014 97Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Arrays

Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Arrays An array is a list of variables.

Arrays start counting at zero.

The first element of an array is the element withThe first element of an array is the element with index 0.

Arrays are just like other variables in VBScript with Arrays are just like other variables in VBScript with the exception that we have to use parenthesis to set and retrieve valuesand retrieve values.

3/12/2014 99Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Arrays

3/12/2014 100Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Arrays

you can also use a shorthand notation in which case h h h h blyou have to omit the parenthesis in the variable 

declaration:

The Array() function in VBScript takes any number of The Array() function in VBScript takes any number of variables and turns them into an array.

You can add as many arguments as you like

3/12/2014 101Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Arrays

In RhinoScript, coordinates are defined as arrays of h b l d hthree numbers. Element 0 corresponds with x, element 1 with y and element 2 with z.

3/12/2014 102Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Plane

3/12/2014 103Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

SurfaceandPolysurface Methods

Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Basic 3D Geometry: Static Creation

Add Sphere 

Add Box

Add Cylinder Add Cylinder

Add Cone

Add Torus 

3/12/2014 105Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Basic 3D Geometry: Dynamic Creation

Add Sphere Exercise

Add Box

Add CylinderPlease write a script 

b

Exercise

Add Cylinder

Add Coneto create a Box by getting the length, width and the height

Add Torus width and the height from the user.

Please do the samePlease do the same for Cylinder, cone and Torus

3/12/2014 106Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

ShowCases

Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Example 1: Tree Example

3/12/2014 108Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Example 1: Tree Example

3/12/2014 109Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Example 1: Tree Example

3/12/2014 110Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Example 2: Mesh Generation

3/12/2014 111Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Example 2: Mesh Generation

3/12/2014 112Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Example 2: Mesh Generation

3/12/2014 113Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

GrasshopperOverview

Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

UsefulResources

Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Useful Resources http://wiki.mcneel.com/developer/rhinoscript

Everything about RhinoScript

http://www.rhino3d.com/developer.htm#vbs

Useful Resources about rhino scripting and Grasshopper

htt // hi i t / t t http://www.rhinoscript.org/start

Important community for RhinoScripting and 

3/12/2014 116Khaled Abd El Gawad – All rights reserved – www.khaledarch.com

Grasshopper

Ihopeyouhaveenjoyedit!

Khaled Abd El GawadKhaledAbdElGawadwww.khaledarch.com

Khaled Abd El Gawad – All rights reserved – www.khaledarch.com