Hello,
I have this pretty simple script that prompts the user to draw a line via RhinoScriptSyntax (rs.GetLine) in Rhino and then uses that to Scale a Grasshopper object but when I complete the rhino input portion it sometimes locks the gh interface in a weird way where I can’t click on my canvas components.
I figure this is probably an issue with script context switching, component expiration, or some kind of “rhino command is complete” value being returned but I’m stuck and cannot figure out how to get it to prevent the canvas clicking from bugging out.
Graph Space:
Python Code:
#! python 3
__author__ = "Michael Vollrath"
__version__ = "2024.07.14"
# Made With ♥ In Dallas, TX
ghenv.Component.Description = "Given a user-drawn line, scales an object to the user-specified dimension."
ghenv.Component.Name = "Scale Line"
ghenv.Component.NickName = "SL"
ghenv.Component.Params.Input[0].Name = "Object"
ghenv.Component.Params.Input[0].NickName = "O"
ghenv.Component.Params.Input[0].Description = "Object To Scale"
ghenv.Component.Params.Output[0].Name = "Object Scaled"
ghenv.Component.Params.Output[0].NickName = "OS"
ghenv.Component.Params.Output[0].Description = "Object Scale Result"
import Rhino
import rhinoscriptsyntax as rs
import scriptcontext as sc
def scale_object():
# Prompt the user to select the object to scale
obj = O
if not obj:
return
# Prompt the user to draw a line
line = rs.GetLine()
if not line:
return
pt1, pt2 = line[0], line[1]
if not pt1 or not pt2:
print("Invalid line drawn. Please draw a valid line.")
return
# Calculate the current distance between the two points
current_distance = rs.Distance(pt1, pt2)
if current_distance == 0:
print("The distance between the points is zero. Please draw a valid line.")
return
# Prompt the user for the desired dimension
desired_dimension_str = rs.GetString("Enter the desired dimension between the two points")
try:
desired_dimension = float(desired_dimension_str)
except ValueError:
print("Invalid input for the desired dimension. Please enter a valid number.")
return
# Calculate the scale factor
scale_factor = desired_dimension / current_distance
# Perform the scaling operation
scaled_obj = rs.ScaleObject(obj, pt1, (scale_factor, scale_factor, scale_factor))
if not scaled_obj:
print("Scale Failed.")
return
if "scaled_obj" not in sc.sticky:
sc.sticky["scaled_obj"] = scaled_obj
res = sc.sticky["scaled_obj"]
print("Object scaled successfully.")
return res
# Execute the function
if __name__ == "__main__":
if E:
OS = scale_object()
elif "scaled_obj" in sc.sticky:
OS = sc.sticky["scaled_obj"]
else:
OS = None
# OS = scale_object()
sc.doc = ghdoc
System Info
Rhino 8 SR9 2024-7-8 (Rhino 8, 8.9.24190.17001, Git hash:master @ c9e437cfdf6e9fc57bba3cd084318a04f8b7e355)
License type: Commercial, build 2024-07-08
License details: Cloud Zoo
Windows 11 (10.0.22631 SR0.0) or greater (Physical RAM: 64GB)
.NET 7.0.17
Computer platform: LAPTOP - Plugged in [97% battery remaining]
Standard graphics configuration.
Primary display: DisplayLink USB Device (DisplayLink) Memory: 0MB, Driver date: 2-9-2024 (M-D-Y).
> External USB display device with 4 adapter port(s)
- Windows Main Display attached to adapter port 0
- Secondary monitor attached to adapter port 1
Primary OpenGL: NVIDIA GeForce RTX 3080 Ti Laptop GPU (NVidia) Memory: 16GB, Driver date: 1-15-2023 (M-D-Y). OpenGL Ver: 4.6.0 NVIDIA 528.24
> Integrated accelerated graphics device with 4 adapter port(s)
- Video pass-through to primary display device
Secondary graphics devices.
Intel(R) Iris(R) Xe Graphics (Intel) Memory: 1GB, Driver date: 10-26-2022 (M-D-Y).
> Integrated graphics device with 4 adapter port(s)
- There are no monitors attached to this device. Laptop lid is probably closed
DisplayLink USB Device (DisplayLink) Memory: 0MB, Driver date: 2-9-2024 (M-D-Y).
> External USB display device with 0 adapter port(s)
- There are no monitors attached to this device. Laptop lid is probably closed
OpenGL Settings
Safe mode: Off
Use accelerated hardware modes: On
Redraw scene when viewports are exposed: On
Graphics level being used: OpenGL 4.6 (primary GPU’s maximum)
Anti-alias mode: 4x
Mip Map Filtering: Linear
Anisotropic Filtering Mode: High
Vendor Name: NVIDIA Corporation
Render version: 4.6
Shading Language: 4.60 NVIDIA
Driver Date: 1-15-2023
Driver Version: 31.0.15.2824
Maximum Texture size: 32768 x 32768
Z-Buffer depth: 24 bits
Maximum Viewport size: 32768 x 32768
Total Video Memory: 16 GB
Rhino plugins that do not ship with Rhino
C:\Program Files\Enscape\Enscape.Rhino.Plugin-net48\Enscape.Rhino8.Plugin.dll “Enscape.Rhino8.Plugin” 0.0.24138.1238
C:\Users\micha\AppData\Roaming\McNeel\Rhinoceros\packages\8.0\Crash\1.4.2-beta\Crash.rhp “Crash” 1.4.0.0
C:\ProgramData\McNeel\Rhinoceros\7.0\Plug-ins\Datasmith Rhino Exporter (d1fdc795-b334-4933-b680-088119cdc6bb)\DatasmithRhino7.rhp “Datasmith Exporter” 5.1.0.0
C:\Users\micha\AppData\Roaming\McNeel\Rhinoceros\8.0\Plug-ins\D5LiveSync (e0d5e210-02f6-4ee9-a2b0-1675e225d958)\D5Conv.rhp “D5 Live Sync for Rhino”
Rhino plugins that ship with Rhino
C:\Program Files\Rhino 8\Plug-ins\Commands.rhp “Commands” 8.9.24190.17001
C:\Program Files\Rhino 8\Plug-ins\rdk.rhp “Renderer Development Kit”
C:\Program Files\Rhino 8\Plug-ins\RhinoRenderCycles.rhp “Rhino Render” 8.9.24190.17001
C:\Program Files\Rhino 8\Plug-ins\rdk_etoui.rhp “RDK_EtoUI” 8.9.24190.17001
C:\Program Files\Rhino 8\Plug-ins\NamedSnapshots.rhp “Snapshots”
C:\Program Files\Rhino 8\Plug-ins\MeshCommands.rhp “MeshCommands” 8.9.24190.17001
C:\Program Files\Rhino 8\Plug-ins\IronPython\RhinoDLR_Python.rhp “IronPython” 8.9.24190.17001
C:\Program Files\Rhino 8\Plug-ins\RhinoCycles.rhp “RhinoCycles” 8.9.24190.17001
C:\Program Files\Rhino 8\Plug-ins\Grasshopper\GrasshopperPlugin.rhp “Grasshopper” 8.9.24190.17001
C:\Program Files\Rhino 8\Plug-ins\Toolbars\Toolbars.rhp “Toolbars” 8.9.24190.17001
C:\Program Files\Rhino 8\Plug-ins\3dxrhino.rhp “3Dconnexion 3D Mouse”
C:\Program Files\Rhino 8\Plug-ins\Displacement.rhp “Displacement”
C:\Program Files\Rhino 8\Plug-ins\SectionTools.rhp “SectionTools”
Thank you all for your help!
Please see attached .gh:
20240714_RS_Command_Preventing_GH_Mouse_Interaction_01a.gh (658.9 KB)