# Python method equivalent to SetObjectDisplayMode?

**URL:** <https://discourse.mcneel.com/t/python-method-equivalent-to-setobjectdisplaymode/119916>\
**Category:** Rhino Developer\
**Tags:** windows\
**Created:** [March 8, 2021, 10:12am UTC](https://discourse.mcneel.com/t/python-method-equivalent-to-setobjectdisplaymode/119916 "2021-03-08T10:12:22Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![DanBayn](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/danbayn/32/477847_2.png) [@DanBayn](https://discourse.mcneel.com/u/DanBayn)\
**Post date:** [March 8, 2021, 10:12am UTC](https://discourse.mcneel.com/t/python-method-equivalent-to-setobjectdisplaymode/119916/1 "2021-03-08T10:12:22Z")

</div>

I have a couple of scripts that will strip away any object display modes that the user has chosen. I would like to be able to detect an object’s display mode and restore it when the script finishes. I don’t see any Python methods to accomplish this. Has anyone added this type of functionality to their scripts? If so, how did you do it?

Thanks,

Dan

---

<div class="post-metadata">

**Author:** ![Willem](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/willem/32/554347_2.png) [@Willem](https://discourse.mcneel.com/u/Willem)\
**Post date:** [March 8, 2021, 10:46am UTC](https://discourse.mcneel.com/t/python-method-equivalent-to-setobjectdisplaymode/119916/2 "2021-03-08T10:46:58Z")

</div>

Hi Dan,

Did you find these already, it looks like they are what you are looking for:

[https://developer.rhino3d.com/api/RhinoCommon/html/M\_Rhino\_DocObjects\_ObjectAttributes\_HasDisplayModeOverride.htm](https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_DocObjects_ObjectAttributes_HasDisplayModeOverride.htm)

[https://developer.rhino3d.com/api/RhinoCommon/html/Overload\_Rhino\_DocObjects\_ObjectAttributes\_SetDisplayModeOverride.htm](https://developer.rhino3d.com/api/RhinoCommon/html/Overload_Rhino_DocObjects_ObjectAttributes_SetDisplayModeOverride.htm)

-Willem

---

<div class="post-metadata">

**Author:** ![DanBayn](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/danbayn/32/477847_2.png) [@DanBayn](https://discourse.mcneel.com/u/DanBayn)\
**Post date:** [March 8, 2021, 10:52am UTC](https://discourse.mcneel.com/t/python-method-equivalent-to-setobjectdisplaymode/119916/3 "2021-03-08T10:52:38Z")

</div>

No I didn’t see these. This should be exactly what I need.

Thanks Willem,

Dan

---

<div class="post-metadata">

**Author:** ![DanBayn](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/danbayn/32/477847_2.png) [@DanBayn](https://discourse.mcneel.com/u/DanBayn)\
**Post date:** [March 8, 2021, 11:46am UTC](https://discourse.mcneel.com/t/python-method-equivalent-to-setobjectdisplaymode/119916/4 "2021-03-08T11:46:38Z")

</div>

It seems that HasDisplayModeOverride returns a boolean. If I understand correctly that’s only going to tell me that there is a object display mode set, but not which one it is, so therefore, no real way to restore the object display mode that was previously set.

I guess another angle to take on this is to figure out if ExplodePolysurfaces can **not** turn off an existing display mode override. That’s probably my real issue here. Basically I want an exploded polysurface to still have the same object display mode that it had prior to exploding.

Did I miss something with the examples provided that could do this?

Thanks,

Dan

---

<div class="post-metadata">

**Author:** ![Dancergraham](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/dancergraham/32/497397_2.png) [@Dancergraham](https://discourse.mcneel.com/u/Dancergraham)\
**Post date:** [March 8, 2021, 12:50pm UTC](https://discourse.mcneel.com/t/python-method-equivalent-to-setobjectdisplaymode/119916/5 "2021-03-08T12:50:00Z")

</div>

> [@DanBayn](#):
>
> It seems that HasDisplayModeOverride returns a boolean. If I understand correctly that’s only going to tell me that there is a object display mode set, but not which one it is, so therefore, no real way to restore the object display mode that was previously set.

Have you seen this method to get the guid of the display mode override - I presume that would allow you to find the override in a table somewhere of from the display mode discription of the associated viewport?

[https://developer.rhino3d.com/api/RhinoCommon/html/M\_Rhino\_DocObjects\_ObjectAttributes\_GetDisplayModeOverride.htm](https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_DocObjects_ObjectAttributes_GetDisplayModeOverride.htm)

[https://developer.rhino3d.com/api/RhinoCommon/html/T\_Rhino\_Display\_DisplayModeDescription.htm](https://developer.rhino3d.com/api/RhinoCommon/html/T_Rhino_Display_DisplayModeDescription.htm)

---

<div class="post-metadata">

**Author:** ![Willem](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/willem/32/554347_2.png) [@Willem](https://discourse.mcneel.com/u/Willem)\
**Post date:** [March 8, 2021, 3:11pm UTC](https://discourse.mcneel.com/t/python-method-equivalent-to-setobjectdisplaymode/119916/6 "2021-03-08T15:11:06Z")

</div>

Hi Dan

See if the below code gets you started to record the modes  
I did not have time to also write a method to restore/set the modes but maybe you get that working based on this example?

```python
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino

def get_displaymodename_byid(mode_id):
    #return name of displaymode by guid of displaymode
    modes = Rhino.Display.DisplayModeDescription.GetDisplayModes()
    for mode in modes:
        if mode.Id == mode_id:
            return mode.LocalName

def record_custom_displaymode(obj_id):
    
    robj = rs.coercerhinoobject(obj_id)
    """ create a record of custom displaymodes for this object
    Args: 
        Guid of the object to check
    Return:
        a list of tuples with custom displaymodes 
        (viewport_id, mode_id, mode_name)
        note that mode_name is just for human readability
    """
    
    records = []
    view_ids = sc.doc.Views
    for view in view_ids:
        #test if custom mode is present
        if robj.Attributes.HasDisplayModeOverride(view.MainViewport.Id):
            mode_id = robj.Attributes.GetDisplayModeOverride(view.MainViewport.Id)
            mode_name = get_displaymodename_byid(mode_id)
            records.append((view.MainViewport.Id, mode_id, mode_name))
    
    return records

#dictionary to store displaymodes for each id that has custom modes
displaymode_records = {}

obj_ids = rs.GetObjects('get objects to test')
for obj_id in obj_ids:
    cdm_record = record_custom_displaymode(obj_id)
    if cdm_record: displaymode_records[obj_id] = cdm_record

for key,value in displaymode_records.items():
    print key, value

```

HTH  
-Willem

---

<div class="post-metadata">

**Author:** ![DanBayn](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/danbayn/32/477847_2.png) [@DanBayn](https://discourse.mcneel.com/u/DanBayn)\
**Post date:** [March 8, 2021, 5:50pm UTC](https://discourse.mcneel.com/t/python-method-equivalent-to-setobjectdisplaymode/119916/7 "2021-03-08T17:50:38Z")

</div>

Thanks Willem and Graham. This all looks very helpful.
