Random (rhino/python)

hello everyone,

we have a problem. we want to place objects randomly on a city we imported from open street map (osm). the thing is, we have no idea how to do this. we already have extruded our buildings and created a cylinder which should be placed on the objects (buildings). we thought we could place the cylinders on top of the buildings, which have the hight of 40 (our buildings extrude randomly between the hight of 30 to 50) any suggestions??? :slight_smile:

hereā€™s what we have for now
import rhinoscriptsyntax as rs
import random as ran
import math

#staedteimport

#Gebaeude extrudieren, cappen und Pfade loeschen
buildings = rs.ObjectsByLayer(ā€œbuildingsā€, True)
for i in range (0,len(buildings)):
hgt = ran.uniform(30,50)
points = [(0,0,0), (0,0,hgt)]
mypath = rs.AddCurve(points,1)
rs.SelectObject(buildings[i])
obj = rs.ExtrudeCurve(buildings[i],mypath)
rs.CapPlanarHoles(obj)
rs.DeleteObject(mypath)

rs.UnselectAllObjects ()
rs.EnableRedraw(False)

#layer ausschalten bis aufā€¦
if 1:
layer_names = rs.LayerNames ()
rs.CurrentLayer (ā€œDefaultā€)
for i in range (0,len(layer_names)):
if layer_names[i] != ā€œbuildingsā€:
rs.LayerVisible (layer_names [i], False)

First, if you want your code to appear formatted correctly in a Discourse post, do the following

Enclose the code in two sets of three ā€˜backticksā€™, you can put in ā€˜pythonā€™ after the first 3 for python-specific formatting

```python
<paste your entire code in here>
```

Now as to your script -

Thereā€™s nothing there yet for the creation/placement of your ā€œcylindersā€. In a loop, you would need to do something like get the bounding box of each object, get the top face of the bounding box and some point on that top face, then place or create the cylinder there. The tricky part of this is making sure the cylinder actually is inside the top building face border, as using something like the bounding box center cannot guarantee this.

As you have the building footprint curve already, perhaps first get itā€™s area centroid, raise that point to the building height and use that to place your cylinder. It still wonā€™t guarantee the cylinder will lie 100% within the building roof border, but it might be closerā€¦

thanks! i didnā€™t know that, it was my first postā€¦
thank you for your fast answere! we try to work on your points!
best wishes