Operadores y funciones
Operators and functions
definition: arithmetic operators, concatenation operators, comparison, logical and bitwise operators.
caution: predecease, position matter.
logical operators: boolean 2 values, True or False wrote by George Boole 18th century. Although defined 6 boolean Nor (both False), And (both true), Or (only need one true).
person = GetPersonOverThere()
colHair = GetHairColour(person)
if((IsGirl(person)) and (colHair == Blond or colHair == Brunette) and (Age(person) >= 18)):
neighbour = GetAdjacentPerson(person)
if(not IsGuy(neighbour) or not LooksStrong(neighbour)):
print("Hey baby, you like Heineken?")
else:
RotateAngleOfVision 5.0
functions and procedures: encapsulation functions wrap up nasty bits of code so we dont have to bother with it (math.sin()). How do functions/procedures/methods behave? encapsulate and blend seamlessly into written code. Must be able to receive and return variables.
import rhinoscriptsyntax as rs
import time
#This script will rename an object using the current system time
strObjectID = rs.GetObject("Select an object to rename",0,False,True)
if strObjectID: # check if is none
strNewName = "Time: " + str(time.localtime())
rs.ObjectName(strObjectID, strNewName)
advance function syntax: by default every function return None if do not specify it. Return value to the function. Arguments function declaration.
def lockcurves_nofail():
curves = rs.ObjectsByType(rs.filter.curve)
if not curves: return False # condition for avoid failure, abort operation if not provide the correct data
rs.LockObjects(curves)
return True
mutability: Variables and tuples are considered immutable unless you create a new variable or copy over top of the old variable. List and dictionaries are consider mutable can be modified once they have been created, add, remove, slice values.
Última actualización
¿Te fue útil?