RhinoCommon/Python : ViewDisplayMode copying problem

Hi All,

I am trying to work with ViewDisplayMode copies but ran into a problem that I can’t figure out. Sample code below.The goal is to make a copy of given display mode with specific name, [do anything to it] and then delete at the end of the script. Repeat at each run of the script.

The problem is, the code below works only once for each new duplicate with the same name.
Even though the copied mode gets successfully deleted at the end of the script (I can tell from the Options > View > Advanced menu), the next time I run the script no copy is made, and the returned guid is all 0000-0000-0000…

What am I missing here? Should there be any use of Dispose method so the copy can be created each time the code runs ?

import Rhino.Display
import System
import rhinoscriptsyntax as rs

g=rs.ViewDisplayModeId("Shaded")
newguid = Rhino.Display.DisplayModeDescription.CopyDisplayMode(g,"Shaded---COPY")
guid_s = System.Guid.ToString(newguid)
Rhino.Display.DisplayModeDescription.DeleteDiplayMode(newguid)
print guid_s

thanks in advance for any hints

–jarek

Hi Jarek,

I have found that if you -in between script runs- open the options dialog and hit enter, you can make a new copy.
So the options dialog ‘refreshes’/‘updates’ the displaymodes state somehow. I did not find something in RhinoCommon,…

-Willem

1 Like

Hi Willem,

that’s right, I can repeat that. Interesting… it still doesn’t solve the problem but there is definitely some “refresh” or “purge” missing in the code.

-j

Hi @Jarek,

Perhaps this example helps?

import Rhino
import System

jarek_id = Rhino.Display.DisplayModeDescription.AddDisplayMode("Jarek")
jarek = Rhino.Display.DisplayModeDescription.GetDisplayMode(jarek_id)
print jarek.EnglishName, jarek.Id

shaded_id = Rhino.Display.DisplayModeDescription.ShadedId
shaded = Rhino.Display.DisplayModeDescription.GetDisplayMode(shaded_id)
print shaded.EnglishName, shaded.Id

shaded_copy_id = Rhino.Display.DisplayModeDescription.CopyDisplayMode(shaded_id, "Copy of Shaded")
shaded_copy = Rhino.Display.DisplayModeDescription.GetDisplayMode(shaded_copy_id)
print shaded_copy.EnglishName, shaded_copy.Id

if Rhino.Display.DisplayModeDescription.DeleteDiplayMode(jarek_id):
    print jarek_id, 'deleted'

— Dale

Hi Dale,

The issue Jarek ran into is that if you run his code twice, the method Rhino.Display.DisplayModeDescription.DeleteDiplayMode(newguid)
did not delete the display mode somehow, as the creation of a new copy will return none

Only after running the Options command and hitting OK, it seems the “displaymode cache” is flushed and the new copy can be created.

In other words deleting a displaymode with Rhino.Display.DisplayModeDescription.DeleteDiplayMode() is not sufficient to be able to create a new display mode with the same name as the just deleted displaymode.

Does this make sense?

-Willem

Hi Dale, thanks - the issue is what I and Willem explained that even though deleting the mode works and copied mode is no longer visually on the views list, on the next run of the script you cant make a copy with the same name ( unless you open Options dialog and hit OK ). The script i posted on the 2nd and following runs returns empty guid and doesnt create a copy.

Yes I see that.

https://mcneel.myjetbrains.com/youtrack/issue/RH-48392

– Dale

1 Like

Great, thanks.

Works OK now. Thanks for the quick fix.