I’ve been trying to figure out a way to speed up the process of assigning room floors to a layer but I can’t wrap my head around it/too new to grasshopper to get a grasp.
My goal is to with a click of a button assign rooms to layers with the same name as the text object which is on the surface of the room floor. I have already managed to make a grasshopper script which takes all the text files and creates layers according to the text inside the text object. However I can’t find a way for the room floor surface to find the nearest text object, read its contents and then bake the object into the already created layers with the same name as that text object.
Such as: Surface finds nearest text–>Collects text name–>Bakes surface object into already existing layer with the same name as the text object
The second half of the task I should quite easily be able to do but I haven’t found any functions/plugins which find the nearest text object from a surface? I’ve seen nearest point functions but If possible I would not want to use that as I want to make this scalable and placing 150 points would make this slower than doing what im trying to speed up…
I’ve added a screenshot below which hopefully makes my bad attempt at explaining what im attempting to do a little easier to understand
Hi Simon - one way is to get the text bounding box, and find the surface where ClosestPoint distance of one corner or the center to the surface < tolerance. Or the text insertion point, or plane origin… anything that gets you a point related to the text.
for example, in python:
import Rhino
import scriptcontext as sc
import rhinoscriptsyntax as rs
def test():
tol = sc.doc.ModelAbsoluteTolerance
srfIds = rs.ObjectsByType(8, False, 1)
if not srfIds: return
textIds = rs.ObjectsByType(512, False, 1)
if not textIds: return
textIds = [id for id in textIds if rs.IsText(id)]
if len(textIds) == 0:
return
textGeos = [rs.coercegeometry(id) for id in textIds]
tPts = [geo.GetBoundingBox(True).Center for geo in textGeos]
srfGeos = [rs.coercesurface(id) for id in srfIds]
while len(tPts) > 0:
found = False
pt = tPts.pop()
textId = textIds.pop()
textGeo = textGeos.pop()
text = textGeo.Text
for j in range(len(srfGeos)):
srf = srfGeos[j]
rc, parU, parV = srf.ClosestPoint(pt)
if rc:
if srf.PointAt(parU, parV).DistanceTo(pt) < tol:
srfId = srfIds.pop(j)
srfGeos.pop(j)
if not rs.IsLayer(text):
rs.AddLayer(text)
rs.ObjectLayer([srfId, textId], text)
break
test()
@pascal Hi Pascal, thank you very much for the help,
I have python experience and understand what you have written but how would I go about making it useable in the GHpython script component within grasshopper?
For others who come across this query and are curious you have to add
sc.doc = Rhino.RhinoDoc.ActiveDoc
before tolerance variable ‘tol’ calls it. This allows grasshopper to call anything in your active rhino document.