Rhinoscript button to test if command present

I would like to put some additional Rhinoscript code in a toolbar button that will load the RVB file if it is not already loaded. In that way there is no memory consumed by the code unless it is needed. What I show below does not work because LoadScript is not seeing the file path (there’s just a space between LoadScript and C:.Rhino_Toolbars…). Any ideas?

! -_RunScript (
if not Rhino.isCommand(“SelectLengthUnit”) then Rhino.Command “_LoadScript C:\Rhino_Toolbars\Weight Estimate.rvb”)
Call SelectLengthUnit
)

Hello - try a dash in front of LoadScript.

-_Loadscript

-Pascal

image

New code:
! -_RunScript (
if not Rhino.isCommand(“SelectLengthUnit”) then Rhino.Command “-_LoadScript C:\Rhino_Toolbars\Weight Estimate.rvb”)
Call SelectLengthUnit
)

Curly quotes! “ vs. ". the straight ones work…

-Pascal

Getting closer!, but:

  1. Rhino.IsCommand returns false regardless of whether there is a RhinoScript sub named SelectWeightUnit. Perhaps IsCommand is the wrong thing to use to identify the presence of a Rhinoscript sub?
  2. The space between “weight” and “estimate” in the file name is being interpreted as a carriage return.

Ah, OK - send quote marks to the command line with chr(34) like so:

Rhino.Command "-_LoadScript " & chr(34) & “C:\Rhino_Toolbars\Weight Estimate.rvb” & chr(34)

-Pascal

That helps. Here’s what I have now. The only issue remaining is that it ALWAYS reports “Loaded script file.” Therefore Rhino.isCommand is not looking at RhinoScript subs (I think). Does RhinoScript implement the GetREF command, which could be used instead of IsCommand?

! -_RunScript (
if not Rhino.isCommand(“SelectLengthUnit”) then
Rhino.Command "-_LoadScript " & chr(34) & “C:\Rhino_Toolbars\Weight Estimate.rvb” & chr(34)
Rhino.print “Loaded script file.”
end if
Call SelectLengthUnit
)

Hello - try Rhino.IsProcedure()

-Pascal

Success! Thank you!