algorithmic modeling for Rhino
Hello All,
I am working on a script to show students how to use python in grasshopper. As usual, python never adapts. I have troubleshooted this problem enough to know that there is no quick solution to my python component returning null despite running fine in the standalone python editor (i.e.: not through grasshopper).
The original python script is as follows:
import random
import rhinoscriptsyntax as rs
rs.EnableRedraw(False)def placeBuildings(curve, distance):
pts=rs.DivideCurveLength(curve,5)
counter=0
for myPoint in pts:
counter=counter+1
#get the parmeter f current positision
param=rs.CurveClosestPoint(curve,myPoint)
#get teh tangent of this parameter
tangent=rs.CurveTangent(curve,param)
#calculate the angle of the tangent
angle=rs.Angle((0,0,0),tangent)
randomNumber=random.uniform(1,5)
heightOfBuilding=random.uniform(4,40)
rect=rs.AddRectangle(rs.WorldXYPlane(),randomNumber,2)
rs.MoveObject(rect,(0,randomNumber,0))
hull=rs.ExtrudeCurveStraight(rect,(0,0,0),(0,0,heightOfBuilding))
rs.RotateObject(hull,(0,0,0),angle[0])
rs.MoveObject(hull,myPoint)
#if counter%4:
#rs.AddCircle(myPoint,3)
#selection of curve
#curveParameter=rs.GetCurveObject("sel curve")
#curve=curveParameter[0]
curves=rs.GetCurveObject("select streets",4)
distance=rs.GetInteger("distance?",4)
for curve in curves:
placeBuildings(curve,distance)
rs.ReverseCurve(curve)
placeBuildings(curve,distance)
When placed in grasshopper it is the following:
import random
import rhinoscriptsyntax as rs#randomNumber=random.uniform(1,5)
#rs.AddCircle((0,randomNumber,0), 2)def placeBuildings(curve, distance):
pts=rs.DivideCurveLength(curve, 5)
counter=0
for myPoint in pts:
counter=counter+1
#get the parmeter f current positision
param=rs.CurveClosestPoint(curve,myPoint)
#get teh tangent of this parameter
tangent=rs.CurveTangent(curve,param)
#calculate the angle of the tangent
angle=rs.Angle((0,0,0),tangent)
randomNumber=random.uniform(1,5)
heightOfBuilding=random.uniform(4,40)
rect=rs.AddRectangle(rs.WorldXYPlane(),randomNumber,2)
rs.MoveObject(rect,(0,randomNumber,0))
hull=rs.ExtrudeCurveStraight(rect,(0,0,0),(0,0,heightOfBuilding))
rs.RotateObject(hull,(0,0,0),angle[0])
rs.MoveObject(hull,myPoint)#selection of curve
#curveParameter=rs.GetCurveObject("sel curve")
#curve=curveParameter[0]curves=x
distance=yfor curve in curves:
placeBuildings(curve,distance)
rs.ReverseCurve(curve)
placeBuildings(curve,distance)
I am unsure why there is no error being returned yet I cannot achieve any result other than null. Maybe someone could look at the script and tell me what is going wrong? I'm hoping to solve this before next Thursday so I might be asking for too much.
Much Appreciated.
-A
Tags:
See Djordje's answer here. It should explain the difference between targeting the Rhino document and the Grasshopper document when writing Python scripts. I'm not sure what you are referring to about "As usual, python never adapts". The only issue is about the logic and the implementation of this in the script. In this case I'm afraid I can't quite decipher what the script is supposed to be doing. I did have a quick go though, see attached file..
You are amazing! That is literally what I required!
Good work!
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by