Hello All,
I was able to get this script to read a point coordinate and generate a dot object that reports the. z value of this coordinate. Before compiling it to a rhp plugin. I’m wondering I it is possible to keep the dot “Alive” so every time I move the point it will automatically report the z.value. unless the idea of developing a plugin from a script is too linear and limited.
Is there a method that tracks (or listens) to the change to object properties (in this case position), and reevaluate the function?
I replicated my intended function in Grasshopper, like the below:
Below is my starting point
import Rhino
import scriptcontext
import System
def AddDot():
# Get the point from the user
rc, point = Rhino.Input.RhinoGet.GetPoint("Pick a point location", False)
if rc != Rhino.Commands.Result.Success:
return rc
# Get the active view's construction plane
view = scriptcontext.doc.Views.ActiveView
if view:
cplane = view.ActiveViewport.ConstructionPlane()
# Calculate the distance from the point to the construction plane
z_value = 12 * cplane.DistanceTo(point)
# Convert to feet and fractional inches
feet, inches = divmod(z_value, 12)
inches, fraction = divmod(inches, 1)
fraction = round(fraction * 16) / 16
if fraction.is_integer():
inches += int(fraction)
fraction = 0
# Format the output
if fraction > 0:
output = "{}' {} {}/16\"".format(int(feet), int(inches), int(fraction * 16))
else:
output = "{}' {}\"".format(int(feet), int(inches))
# Add a dot with the formatted output
dot = Rhino.Geometry.TextDot(output, point)
# Find or create the layer called "+WorkArea::Elev"
layer = scriptcontext.doc.Layers.FindName("+WorkArea::Elev")
if not layer:
layer_index = scriptcontext.doc.Layers.Add("+WorkArea::Elev", System.Drawing.Color.Black)
layer = Rhino.DocObjects.Layer()
layer.Index = layer_index
# Add the dot to the layer
attributes = Rhino.DocObjects.ObjectAttributes()
attributes.LayerIndex = layer.Index
scriptcontext.doc.Objects.AddTextDot(dot, attributes)
scriptcontext.doc.Views.Redraw()
return Rhino.Commands.Result.Success
if __name__ == "__main__":
AddDot()
5 posts - 4 participants