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!
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
No comments:
Post a Comment