Hello everyone
I’m trying to develop a simple python plugin which draws a sort of “halo” around the bottom surface of a polysurface ( I’ll use that to avoid nesting objects too close to each other )
import Rhino
import scriptcontext
import rhinoscriptsyntax as rs
def Halo():
OBJ = rs.GetObjects("Select objects to nest:", 16, False, True, True, True)
if not OBJ: return
for ObjId in OBJ:
Surfaces = rs.ExtractSurface(ObjId, 0, True)
for SrfId in Surfaces:
Edges = rs.DuplicateEdgeCurves(SrfId)
rs.DeleteObject(SrfId)
JoinedEdges = rs.JoinCurves(Edges)
rs.DeleteObjects(Edges)
for EdgeId in JoinedEdges:
col = rs.CreateColor(255,0,0)
Direction = (1000,1000,1000)
OffsetEdges = rs.OffsetCurve(EdgeId, Direction, 20)
rs.DeleteObjects(EdgeId)
for OEId in OffsetEdges:
rs.ObjectColor(OEId, col)
Grp = rs.AddGroup()
rs.AddObjectsToGroup([ObjId, OEId], Grp)
if __name__=="__main__":
DoHalo()
This won’t work because the surface “0” is not always the bottom one, as I could have rotated the objects. Question is :
How can I select the surfaces facing down or, at lest, the surfaces laying on the C plane ?
Or even better, is there a way to select the largest one between the top and bottom surface ?
emm…About “I’ll use that to avoid nesting objects too close to each other”, I don’t see a code related to transform,about finding the collision range of Breps ,I will try this way:
Thanks everyone for the help, I ended up using the Meshoutline method with the top view selected.
For some reason it don’t accept polysurfaces as input in a script, so I had to work around it using the Command function and selecting\deselecting things through the loop.
Seems to work pretty well tho
import Rhino
import scriptcontext
import rhinoscriptsyntax as rs
import System.Guid
def Halo():
rs.EnableRedraw = False
SelObjects = rs.GetObjects("Seleziona le polisuperfici:", rs.filter.polysurface, False, True, True, True)
HaloOffset = rs.GetInteger("Valore dell'offset per l'halo:", 10, 0, None)
if not SelObjects: return
if not HaloOffset: return
rs.UnselectAllObjects()
scriptcontext.doc.Layers.Add("Halo", System.Drawing.Color.Red)
direzione = (10000, 10000, 10000)
if rs.MessageBox("Vuoi spostare tutto sul piano C?", 4 | 32)==6:
#Moves everything on C plane, if needed
for Obj in SelObjects:
bb=rs.BoundingBox(Obj)
if bb: rs.MoveObject(Obj,rs.coerce3dvector([0,0,-bb[0][2]]))
rs.CurrentView('Superiore')
# Switch view to top
for Obj in SelObjects:
rs.SelectObject(Obj)
rc = rs.Command("_MeshOutline", False)
if not rc: return
Crv = rs.FirstObject(True)
Halo = rs.OffsetCurve(Crv, direzione, HaloOffset, None, 2)
rs.DeleteObject(Crv)
rs.ObjectLayer(Halo, "Halo")
Group = rs.AddGroup()
rs.AddObjectsToGroup([Obj, Halo], Group)
rs.UnselectAllObjects()
rs.EnableRedraw = True
Halo()