Tuesday, March 13, 2012

More Practice

Easy exercise.

The objective is to draw a circle of variable radius (ie.you can change the radius at a single point in your code without having to change everything!), at points drawn manually in the Rhino workspace.



(Far too easy!) But now we're going to add other secondary circles, again of variable radius, around all of these main circles, so that each of these secondary circles touches the main one at A SINGLE POINT in their circumferences (ie. the main circle and each secondary circle touch but do not intersect). The number of these secondary circles is again variable, but they have to surround the main circle as shown (- we do not care if the secondary circles intersect each other, if they have to).





All of the above patterns were obtained using the same code, but by varying the 3 input parameters: radius1, radius2, number of secondary circles around main circles. No more than 20 lines of code!

Thursday, March 08, 2012

Your tests

Publish your tests guys!!!!
Do it commenting this post!
V.

Tuesday, March 06, 2012

some clarifications

This should be already well known but I want it to be REALLY clear.

Every command or operation in python needs something to act on: a string, a number, a vector, a list, a GUID, etc..

for example the command


rhinoscriptsyntax.AddCurve(points, degree=3) 


needs compulsorily a list of 3-D points, and a number (integer) which will be the degree of the curve. You can omit the number which will be set by default as 3.

WHERE DO YOU FIND THESE INFORMATION?
Double clicking on the command list of rhinoscriptsyntax on the left of the python windows




Under PARAMETERS  you can see what is needed to the command (referenced to the syntax just above), if it is REQUIRED (meaning the command will not work without that entry) or OPTIONAL (where you will have a default value if you don't specify anything). If you want to skip a parameter which is optional to assign another one after that just leave a space between commas.

Under RETURNS you can see what the function returns. If you store this in a variable ex Curve01 = rs.AddCurve(....) and then you call the command print

print Curve01

you can see what you have stored.

PRINTING YOUR VARIABLES IS EXTREMELY USEFUL IF YOU WANT TO CHECK FOR ERRORS, SOMETIMES VARIABLES ARE STORING STUFF YOU DIFFERENT FROM WHAT YOU EXPECT

In this case the help is telling that you will end up storing a Guid if everything was ok or None (means nothing, but it will print really as None) if the operation was not successful.

So WHAT IS A GUID?????

A  GUID is a "globally unique identifier" which means a STRING identifying ONE OBJECT in rhino.

WHAT IS AN OBJECT????

Anything you can draw and see in rhino! If it is drawn it will be an object and you will be able to select it just by calling its GUID!


As you can see a GUID is a long string of letters and numbers which makes not a lot of sense, and all the objects drawn have one!

So if I want to select the surface I can just call its GUID


As the GUID is a string DO NOT FORGET TO PUT " " to tell the script you are passing a string variable!!!!!!!

Lastly, once you have one GUID you can take all the information regarding that object with other commands which inputs a GUID.
Let's try taking a point and using printing its coordinates (which usually REALLY matter).


#################################################################

import rhinoscriptsyntax as rs

point = rs.GetObject("select one point",1) 
# putting 1 after the comma means we allow only points to be selected
# so, even if you try you cannot select a surface or a curve 
# or something else

# check for the command getObject to see how to limit
# the selection to surfaces or curves or clouds

# if you want for example curves AND points 
# you can write 1 + 4

print point

coordinates = rs.PointCoordinates(point)

print coordinates

rs.AddLine([0,0,0],coordinates)


##############################################################################

In this case I input the coordinates of my point (and not its Guid) into the command Addline.
If you check the Addline command you will find out that I could have input the Guid as well, but this is not always possible, it depends.

Just remember that if you just deals with coordinates and you are not actually drawing points (starting this way to have Guids all around) everything will go much faster. So, and this will lead to our next lesson remember that:

YOU CAN DEAL WITH POINTS JUST USING THEIR COORDINATES AVOIDING TO DRAW THEM, AND COORDINATES CAN ALSO BE SEEN AS VECTORS SPANNING FROM [0,0,0] TO THE POINT WE WANT TO DEAL WITH.


Hope this was clear enough, if you have doubts just comment!!!
goodnight
Vince

Monday, March 05, 2012

Homework 5 march

Here is a new one. I want you to make a script which, given one point builds around it a triangle with the dimensions you see in the first image. If you manage to do it you should also draw for each point you select, rotated copy of the triangle one every 10 degrees (36 in total).
All of this WITHOUT drawing any points, except from the input ones.

Enjoy
Vincenzo