Hi, I’m making a script to produce these objects inside a closed curve boundary. It keeps giving me error
Message : Parameter must be a Guid or string representing a Guid.
import rhinoscriptsyntax as rs
import math
from math import*
from scriptcontext import escape_test
import random
from random import randrange
###############################################
# SCRIPT TO CREATE NETWORKED HOUSING COMPLEX FROM ANY SITE
def move_start_point_angle( start_point , angle , distance ):
start_x , start_y = start_point[0], start_point[1]
new_x = cos(radians(angle))*distance + start_x
new_y = sin(radians(angle))*distance + start_y
return (new_x, new_y)
def explode_point(Start_Point,Distance,Number,Site):
Count = 0
Lines = [ ]
P_end = [ ]
while Count <= Number:
Count += 1
A = random.uniform(-Distance,Distance)
B = random.uniform(-Distance,Distance)
C = random.uniform(-Distance,Distance)
P2 = ( Start_Point[0] + A , Start_Point[1] + B , Start_Point [2] + C )
P2_point = rs.AddPoint(P2)
if rs.PointInPlanarClosedCurve(P2_point,Site) == 1 :
P_end.append(P2)
if rs.PointInPlanarClosedCurve(P2_point,Site) == 0 :
rs.DeleteObject(P2_point)
Line = rs.AddLine(Start_Point , P2)
Lines.append(Line)
return (P_end)
def make_building ( start_point , point_b , point_c , Max_Height , Thickness ):
mid_point = ( ( (start_point[0]+point_b[0]+point_c[0]) / 3) , ( (start_point[1]+point_b[1]+point_c[1]) / 3) )
points = start_point , point_b , point_c , mid_point
for i in points:
rs.AddPoint(i)
line_1 = rs.AddLine( start_point , mid_point)
line_2 = rs.AddLine( point_b , mid_point)
line_3 = rs.AddLine( point_c , mid_point)
vector = rs.AddLine( (0,0,0) , (0,0,Max_Height) )
surface_1 = rs.ExtrudeCurve( line_1 , vector)
surface_2 = rs.ExtrudeCurve( line_2 , vector)
surface_3 = rs.ExtrudeCurve( line_3 , vector)
rs.OffsetSurface( surface_1 , Thickness , tolerance = None, both_sides = True , create_solid = True)
rs.OffsetSurface( surface_2 , Thickness , tolerance = None, both_sides = True , create_solid = True)
rs.OffsetSurface( surface_3 , Thickness , tolerance = None, both_sides = True , create_solid = True)
def branch( start_point, end_point , angle_add , max_length , min_length):
unit_block = []
### list points
start_x , start_y = start_point[0], start_point[1]
end_x , end_y = end_point[0] , end_point[1]
### gett angle of line_a
line_a = rs.AddLine ( start_point , end_point )
tangent_a = ( ( end_y - start_y ) / ( end_x - start_x ) )
angle_a = degrees( math.atan ( tangent_a ) )
### add random angle to angle_a
angle_addition = random.uniform(10,angle_add)
angle_b = angle_a + angle_addition
angle_c = angle_a - angle_addition
### get end points
point_b = move_start_point_angle(end_point, angle_b, max_length)
if rs.PointInPlanarClosedCurve(point_b,Site) == 0 :
rs.DeleteObject(point_b)
point_c = move_start_point_angle(end_point, angle_c, max_length)
if rs.PointInPlanarClosedCurve(point_c,Site) == 0 :
rs.DeleteObject(point_c)
Max_Height = 10
Thickness = 10
make_building(start_point,point_b,point_c,Max_Height,Thickness)
### looping
distance = ( rs.Distance(start_point, point_b) + rs.Distance(start_point, point_c) ) / 2
if distance > min_length:
escape_test(True)
angle_addition = random.uniform(10,angle_add)
angle_b2 = angle_b + angle_addition
angle_c2 = angle_c - angle_addition
if rs.IsPoint(point_b):
end_b = move_start_point_angle(point_b, angle_b2, max_length*.7)
if rs.PointInPlanarClosedCurve(point_b,Site) == 1 :
branch(point_b,end_b,angle_add, max_length*.7, min_length)
if rs.IsPoint(point_c):
end_c = move_start_point_angle(point_c, angle_c2, max_length*.7)
if rs.PointInPlanarClosedCurve(point_c,Site) == 1 :
branch(point_c,end_c,angle_add, max_length*.7, min_length)
return(unit_block)
def object_color(objects):
C = 0
Inc = 255 / ( len( objects ) )
for i in objects:
A = random.randint(1,255)
B = random.randint(1,255)
C += Inc
Color = rs.CreateColor((C,50,120))
rs.AddMaterialToObject(i)
rs.ObjectColor(i,Color)
Index = rs.ObjectMaterialIndex(i)
rs.MaterialColor(Index,Color)
###############################################
startpoints = rs.GetPoints()
Site = rs.GetObject('Site')
for i in startpoints:
P2 = explode_point(i, 100 , 5 , Site)
for j in P2 :
branch(i,j,20,100,60)