Creating DisplayModes in .Net

I have the exact same need now, cannot find this key for R6? Or has programmatic ability to create display modes been added to 6?

1 Like

this does create the mode in the menu, but i cannot see how to setup the diplaymode properties as per the manual method to set all objects in this display mode to use one colour etc. I have to set it up seperately in the sactual viewport settings and its not “sticky” in the display mode created. changing object colour settings etc in the code has no impact in rhino, it remains wireframe despite setting shading etc. see the edit view of the mode created like this, none of the settings are actually applied in it?

using System;
using System.Collections.Generic;
using System.Drawing;
using Eto.Drawing;
using Rhino;
using Rhino.Commands;
using Rhino.Display;
using Rhino.Geometry;
using Rhino.Input;
using Rhino.Input.Custom;

namespace CreateAXMode
    public class CreateAXModeCommand : Command
        public CreateAXModeCommand(){Instance = this;}
        public static CreateAXModeCommand Instance{get; private set;}
        public override string EnglishName{get { return "CreateAXMode"; }}
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)

            //see if its already in rhino
            var LookForAX = DisplayModeDescription.FindByName("AX1");
            if (LookForAX != null)
                return Result.Success; //gtfo out dodge.

            //wasnt there, lets make it. 
            var CreatedAxMode = DisplayModeDescription.FindByName("AX1");
            CreatedAxMode.DisplayAttributes.AmbientLightingColor = System.Drawing.Color.White;
            CreatedAxMode.DisplayAttributes.CastShadows = false;
            CreatedAxMode.DisplayAttributes.ShowPoints = false;
            CreatedAxMode.DisplayAttributes.ShowIsoCurves = false;
            CreatedAxMode.DisplayAttributes.ShowText = false;
            CreatedAxMode.DisplayAttributes.ShadingEnabled = true;
            CreatedAxMode.DisplayAttributes.ObjectColor = System.Drawing.Color.Aquamarine;
            CreatedAxMode.DisplayAttributes.ShowCurves = false;

            //etc etc.. does not sem to be working though, in rhino view looks the same as wireframe.. 
            //also cannot fogure out how to set object colour for this mode. 

            //now set the viewport as we cannot do it in the displaymode settings above
            return Result.Success;

        private void SetupViewPort(DisplayModeDescription ax)
            Rhino.DocObjects.Tables.ViewTable GetTheViews = RhinoDoc.ActiveDoc.Views;
            RhinoView[] TheViews = GetTheViews.GetViewList(true, false);
            TheViews[0].Maximized = true;
            TheViews[0].ActiveViewport.DisplayMode = ax;
            TheViews[0].ActiveViewport.ConstructionGridVisible = false;
            TheViews[0].ActiveViewport.ConstructionAxesVisible = false;
1 Like

I’ve moved this to a new topic, since you reopened one that was closed 6 years ago.

To add a new display mode, use DisplayModeDescription.AddDisplayMode. Note, not all display mode properties, displayed in Rhino’s UI, are exposed in RhinoCommon.

– Dale

Hi @dale, I don’t get something here you point method where you need to pass DisplayModeDescription while it doesn’t have a public constructor … So how do I create DisplayModeDescription on fly not using this overload?

Also, the problem with this with name is that when it’s once created and deleted it seems to be impossible to create it again using the same name as FindByName will return null…

I went all the way but it still has no effect. @dale please grab zip (80.8 KB)
open 3dm and load GH there is C# component with code inside. No errors, I’ve prepared ptr on the native side and created instance using internal ctor. However, I can’t see mode in vp dropdown list nor in SetDisplayMode command nor in Options > Display Modes also per object assignment it doesn’t work.

Ah and I confirm that when trying to do it via name and change properties nothing is happening like @ChristopherBotha mentioned

Also copy doesn’t change a thing - It looks like those properties are doing nothing …

How about something like this?

public DisplayModeDescription CreateDisplayModeDescription(string name)
  DisplayModeDescription dmd = null;
  if (!string.IsNullOrEmpty(name))
    var id = DisplayModeDescription.AddDisplayMode(name);
    dmd = DisplayModeDescription.GetDisplayMode(id);
  return dmd;

Also, you should never call Rhino’s unsafe native methods. They are undocumented and you don’t have the knowledge of how to use the return values correctly without either leaking memory or crashing Rhino. Also, these functions names and their behavior change frequently. Using them is unsafe, hence the name of the namespace.

– Dale

1 Like

Question was how not to use it.

If I’ll use AddDisplayMode with name and then change properties and AddDisplayMode using description I will endup with two modes.

IMHO the copy one feels most robust.

Actually, the main issue is that properties assignments seems to do literally nothing.

P.S. Due to unsafe stuff - its obvious - however some thrill won’t hurt :sweat_smile:

1 Like