Grasshopper

algorithmic modeling for Rhino

Python in Grasshopper: Mapping Buildings onto grasshopper built topography #urgent

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=y

for 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

Views: 606

Attachments:

Replies to This Discussion

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..

Attachments:

You are amazing! That is literally what I required! 
Good work!

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service