Need to set Advanced Options in script runtime

If I change the code like this (below), only the first run needs the Sleep(1000), others don’t need it and update just fine.

And yes, I need this to run on for many users on different machines, so needs to be bullet-proof.

    import Rhino
    import rhinoscriptsyntax as rs

    def setdegradation(level,sleep):
        settings = Rhino.PlugIns.PlugIn.GetPluginSettings(Rhino.RhinoApp.CurrentRhinoId, False)
        s = settings.GetChild("Options").GetChild("OpenGL")
        s.SetInteger("SkylightShadowResolutionScale", level)
        Rhino.PlugIns.PlugIn.SavePluginSettings( Rhino.RhinoApp.CurrentRhinoId)
        if sleep:
            rs.Sleep(1000)

    print "Degradation set to 3"
    setdegradation(3,True)
    Rhino.PlugIns.PlugIn.RaiseOnPlugInSettingsSavedEvent()
    Rhino.RhinoDoc.ActiveDoc.Views.Redraw()

    rs.Command("_TestMaxSpeed _Enter")

    print "Degradation set to 2"
    setdegradation(2,False)
    Rhino.PlugIns.PlugIn.RaiseOnPlugInSettingsSavedEvent()
    Rhino.RhinoDoc.ActiveDoc.Views.Redraw()

    rs.Command("_TestMaxSpeed _Enter")

    print "Degradation set to 1"
    setdegradation(1,False)
    Rhino.PlugIns.PlugIn.RaiseOnPlugInSettingsSavedEvent()
    Rhino.RhinoDoc.ActiveDoc.Views.Redraw()

    rs.Command("_TestMaxSpeed _Enter")

Some others question

  • if you remove Rhino.RhinoDoc.ActiveDoc.Views.Redraw (), does it still work ?

  • (just like that :)) Your script will often be used? is a delay of 1 really binding ?

  • Test if an event Idle work for you ? I do not know Python and my call attempt on an Idle event failed

def Callback():
    print("pass")

Rhino.RhinoApp.Idle += Callback

(it does not do anything)

it was option 1, in c# I will test something like this


def RunProgram():
    Rhino.RhinoApp.Idle -= RunProgram
   # ...
   # restore the settings
   # SavePluginSettings & RaiseOnPlugInSettingsSavedEvent
    Rhino.RhinoApp.Idle += EndProgram

def EndProgram():
    Rhino.RhinoApp.Idle -= EndProgram
    # ...

# set the settings
# SavePluginSettings & RaiseOnPlugInSettingsSavedEvent
Rhino.RhinoApp.Idle += RunProgram

And it still does not work, option 2: I will test the same code in a sub process

In short, the trick is to find a way to force the Python interpreter to let the hand to Rhino for his downtime (Idle)…

I did the maximum :slight_smile:
-jmv

1 Like

This one is not needed, can be removed.

Yes, this is for real-time viewport stuff and need to relatively seamlessly swtich between the degradation modes.

Yes :slight_smile: That was the key! You really did the maximum! Thank you so much. No more questions, now it does exactly what I needed it to do, with no delay to update at all.

The trick is to add:

    Rhino.RhinoApp.Idle
    rs.Sleep(0)

right after this line:
Rhino.PlugIns.PlugIn.SavePluginSettings( Rhino.RhinoApp.CurrentRhinoId)

So the final sample code would be:

import Rhino
import rhinoscriptsyntax as rs

def setdegradation(level):
    settings = Rhino.PlugIns.PlugIn.GetPluginSettings(Rhino.RhinoApp.CurrentRhinoId, False)
    s = settings.GetChild("Options").GetChild("OpenGL")
    s.SetInteger("SkylightShadowResolutionScale", level)
    Rhino.PlugIns.PlugIn.SavePluginSettings( Rhino.RhinoApp.CurrentRhinoId)
    Rhino.RhinoApp.Idle
    rs.Sleep(0)

print "Degradation set to 3"
setdegradation(3)
Rhino.PlugIns.PlugIn.RaiseOnPlugInSettingsSavedEvent()
rs.Command("_TestMaxSpeed _Enter")

print "Degradation set to 2"
setdegradation(2)
Rhino.PlugIns.PlugIn.RaiseOnPlugInSettingsSavedEvent()
rs.Command("_TestMaxSpeed _Enter")

print "Degradation set to 1"
setdegradation(1)
Rhino.PlugIns.PlugIn.RaiseOnPlugInSettingsSavedEvent()
rs.Command("_TestMaxSpeed _Enter")
1 Like

Good !!! In python the line

Rhino.RhinoApp.Idle

Trigger the event ?

it is for stork ?

Adding it after Rhino.PlugIns.PlugIn.SavePluginSettings( Rhino.RhinoApp.CurrentRhinoId), before rs.Sleep seems to do the trick.
Then the setting actually triggers in Vport after you run the Rhino.PlugIns.PlugIn.RaiseOnPlugInSettingsSavedEvent()

good guess :medal_sports:

1 Like

Impressive work!

I need this in c#

What exactly do you need in c#?

If you need to change the advanced options, the code is almost identical to Python:

// get settings
Rhino.PersistentSettings settings = Rhino.PlugIns.PlugIn.GetPluginSettings(Rhino.RhinoApp.CurrentRhinoId, false);
Rhino.PersistentSettings options = settings.GetChild("Options");
Rhino.PersistentSettings openGl = settings.GetChild("OpenGL");
// set value
openGl.SetInteger("SkylightShadowResolutionScale", 2);
// reload the interface and apply the changes
Rhino.PlugIns.PlugIn.RaiseOnPlugInSettingsSavedEvent();

If you need something else you’ll have to be a little more precise.

~robin

Hi, the code is not the same, in c# GetPluginSettings not exists

Hello

I don’t know what version of the SDK or Rhino you’re running, but I can assure you that it definitely does exist:
https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_PlugIns_PlugIn_GetPluginSettings.htm
I tested it with RhinoCommon SDK 6.17.

~robin

Yes, of course, but the problem is I can’t use RhinoCommon, i’m using Rhino3dmIO

If you are running outside of Rhino, then you need to find and edit the settings XML file. The settings file is typically located at
%AppData%\McNeel\Rhinoceros\6.0\settings