I’d always told myself I didn’t have to learn grasshopper but it seems as though the inevitable moment has arrived finally.
I had received a set of dwgs that supposedly carried topography data represented in points and lines with real-life height values. but when I opened them, I found out that the data were all texts in numbers sitting on the xy plane with no z values.
Is there a way to somehow extract points from each texts and move each points up by their corresponding values? I hope this question makes any sense.
I’ve been googling my way through but have been unlucky.
below is the screen shot of the texts from the top view. And I would like to thank you all in advance for your help and guidance!
import rhinoscriptsyntax as rs
def convert_texts_to_points():
# Get all text objects in the document
objects = rs.AllObjects()
text_objects = [obj for obj in objects if rs.IsText(obj)]
if not text_objects:
print("No text objects found.")
return
for text_obj in text_objects:
# Get the text string and insert point
text_string = rs.TextObjectText(text_obj)
insert_point = rs.TextObjectPlane(text_obj).Origin
# Convert the text to a number
try:
height = float(text_string)
except ValueError:
# print(f"The text '{text_string}' does not contain a valid number. Skipping...")
continue
# Create a point object at the insert point with Z equal to the height
point_location = (insert_point[0], insert_point[1], height)
point_obj = rs.AddPoint(point_location)
convert_texts_to_points()
import rhinoscriptsyntax as rs
warstwa = "MODEL::TEREN::TEREN-PUNKTY"
if __name__=="__main__":
if rs.IsLayer(warstwa):
rs.CurrentLayer(warstwa)
else:
rs.AddLayer(warstwa)
rs.CurrentLayer(warstwa)
tekst = rs.GetObject("click on a Z coordinate:", filter=512)
if tekst:
tekstZ = rs.DimensionText(tekst)
if tekstZ:
rzednaZ = float(tekstZ)
punkt = rs.GetPoint("where to insert a point:")
if punkt:
rzednaX = punkt.X
rzednaY = punkt.Y
punkt = rs.AddPoint(rzednaX, rzednaY, rzednaZ)
rs.HideObject(tekst)
rs.ObjectLayer(punkt, warstwa)
else:
exit()
else:
exit()
Variables in polish, but I think these are quite easy. I prefer clicking on texts as they can have quite various applications.
Finally I have pinned the script to a button, of course.
Cheers, Jaro