Can you run a python loop in GD?
Here’s a dyno script >>
The node skilfully circled in red is a python node which contains this code:
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import random
import collections
rect = UnwrapElement(IN[0])
site = UnwrapElement(IN[1])
#always need a moose
moose = 0
count = 0
while moose < 500:
#pick random side of the rectangle
side = random.randrange(0,4,1)
Line1 = rect[side]
st1 = round(random.random(),2)
st2 = round(random.random(),2)
if st1 > st2:
st1, st2 = st2, st1
#Get the distance between the two startpoints on the baseline
L1len = (Curve.SegmentLengthBetweenParameters (Line1, st1, st2)/1000)
L1len = round(L1len,2)
#Force the width (in metres)
while L1len <10 or L1len >20:
st1 = round(random.random(),2)
st2 = round(random.random(),2)
#Make sure the points are right way round
if st1 > st2:
st1, st2 = st2, st1
L1len = (Curve.SegmentLengthBetweenParameters (Line1, st1, st2)/1000)
#Create two points along chosen baseline
pt1r = Curve.PointAtParameter(rect[side], st1)
pt2r = Curve.PointAtParameter(rect[side], st2)
#Create the other two corners of the yard by offsetting either X or Y
if side ==3 :
pt3r = Geometry.Translate(pt2r,25000,0,0)
pt4r = Geometry.Translate(pt1r,25000,0,0)
elif side ==0:
pt3r = Geometry.Translate(pt2r,0,25000,0)
pt4r = Geometry.Translate(pt1r,0,25000,0)
elif side ==1 :
pt3r = Geometry.Translate(pt2r,-25000,0,0)
pt4r = Geometry.Translate(pt1r,-25000,0,0)
elif side ==2:
pt3r = Geometry.Translate(pt2r,0,-25000,0)
pt4r = Geometry.Translate(pt1r,0,-25000,0)
yard = Rectangle.ByCornerPoints(pt1r, pt2r, pt3r, pt4r)
good = []
for lines in site:
intersec = Geometry.DoesIntersect (lines, yard)
good.append(intersec)
if sum(good) == 0:
moose += 500
moose +=1
count +=1
cheese = 21
OUT = pt1r, pt2r, pt3r, pt4r, sum(good), count, cheese, yard
All this works fine in dynamo but when I export to the GD engine…