SetObjectDisplayMode - question and wish

I have a question related to SetObjectDisplayMode. I am working on a C# script to set it for all views at once (Model and Layout) for selected objects.

I am aware that Rhino 8 has an option to set the view-related Display Mode for a single object in multiple views:

But that is not good enough for me, as one has to set the mode in each view manually, and a Detail view in a Layout appears in the list only when inside that same view.

What I am trying to do is a one-shot solution with a C# script. I have found that the SetDisplayModeOverride method has an override that should set the object view mode for all viewports:

https://developer.rhino3d.com/api/rhinocommon/rhino.docobjects.objectattributes/setdisplaymodeoverride#(displaymodedescription)

I’ve implemented it in the attached script, but it fails when I try to run the script. If you try the script (open it with the ScriptEditor and run it), after the objects selection and display mode selection, the script writes in the command line the result of the attempt to change the object display mode for each selected object (and it is invariably False). The script also has the option to choose the Display Mode via an Eto Dialog (for this, set the useEto variable to true).

Am I missing something in my script?

I’ve also seen this other script:

and it works, but it uses the view-based override of SetDisplayModeOverride, cycling through all existing Model viewports, but not the Layouts.

I’ve also seen these other related threads, but none of them offer a solution to my question:

Since the all-view override of SetDisplayModeOverride isn’t working, I cannot test whether the Display Mode set for an object persists even in new viewports (but I doubt it).

That would also be a desired option: set the Display Mode for a single object so that it is an attribute of the object regardless of the viewport. There was already a request for this here: SetObjectDisplayMode applies to only one viewport. Is that logical?

This resulted in a YouTrack that was subsequently closed as considered solved by the Rhino 8 option to set Display Mode for multiple views from the Object Properties panel: https://mcneel.myjetbrains.com/youtrack/issue/RH-59215

Of course that is an improvement of the previous situation, but hardly the same thing as what was requested; I still would like the option of an object Display Mode set in one shot for all views (present and newly created).

Sorry for the long post, I wanted to give an as much as possible comprehensive context; here’s the script I’m working on.

SetObjectDIsplayMode_allViews.cs (4.9 KB)

As far as I can tell, my script referenced above can work in layout views, but the problem is that the detail needs to be active in order for the object display mode attribute to be changed. If not, it looks like the change is simply ignored. The proof is you can activate a layout detail and then run the script from there, select the objects, the objects’ display mode in the activated detail will change along with all of the model viewports. But it will not work in any of the other non-active detail views.

So, either one needs to cycle through all the layouts and in each detail view activate it, change the object(s) display mode then deactivate it, or, find some other workaround (unknown to me) that allows this the display mode change to happen even if the layout detail is not activated.

Edit:
So, try the following - it should now work on both model views as well as all details on all layout pages (if any exist). I’ll let you translate it in to C#…

SetObjDisplayModeAllViewportsPlusLayouts.py (2.8 KB)

Edit 2:
Here is the “antidote”, removes all display overrides in all views including layout details

RemObjDisplayModeAllViewportsPlusLayouts.py (1.8 KB)

1 Like

@Helvetosaur, thank you very much for your scripts, I think it won’t take much to translate them (I already did it for the model-only views version), and they are a good workaround to my problem.

Still, my question (for the devs, not for you obviously) remains: why is the view-independent override of SetDisplayModeOverride not working?

And so does my wish, as described in my original post.

It does actually… My old script did not use this override - I was perhaps not aware of it at the time - but I just tried a modification using it and it works on all viewports including layout details… No need to activate them.

Hmm, lot of work this morning for nothing… All I needed to do was change one line and remove a few others…

SetObjDisplayModeAllViewports-Test3.py (1.7 KB)

2 Likes

Ah, I see… looking at your script I think there’s a key step I’ve been missing when applying the attributes. Thank you very much again, I’ll make some tests as soon as I can!

Thank you for getting me to look at it, the scripts are better now!

2 Likes

Just reporting back, I found the issue with my script; I was thrown off track by this:

SetDisplayModeOverride returns a bool value that should be “true if setting was successful”, so I assumed the method worked only if the return value was true. Hence my script called ModifyAttributes only if SetDisplayModeOverride returned true. As it turns out, it returns false but does its job anyway.

Now the question for the devs becomes: isn’t this documentation confusing?

Here attached is the current version of my script.

PS: the method preserves the display mode change in newly created windows (yay!)
PPS: to remove the display changes, the ClearAllObjectDisplayModes Rhino command works as well.

SetObjectDIsplayMode_allViews.cs (4.2 KB)