Changing ViewportScale from code does not work

(Menno Deij - van Rijswijk) #1

Expected output:
Old Y-scale: 1.0
Setting to 10.0
New Y-scale: 10.0

Found output:
Old Y-scale: 1.0
Setting to 10.0
New Y-scale: 1.0

Let me know how to change the vertical scale on a viewport from code. This approach does not work…

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    RhinoApp.WriteLine("Old Y-scale: "+doc.Views.ActiveView.ActiveViewport.DisplayMode.DisplayAttributes.ViewSpecificAttributes.VerticalViewportScale);
    RhinoApp.WriteLine("Setting to 10.0");
        VerticalViewportScale = 10.0;
    RhinoApp.WriteLine("New Y-scale: " + doc.Views.ActiveView.ActiveViewport.DisplayMode.DisplayAttributes.ViewSpecificAttributes.VerticalViewportScale);
    return Result.Success;

(Dale Fugier) #2

How about this:

Rhino.Display.DisplayModeDescription display_mode = Rhino.Display.DisplayModeDescription.GetDisplayMode(doc.Views.ActiveView.ActiveViewport.DisplayMode.Id);
RhinoApp.WriteLine("Old Y-scale: " + display_mode.DisplayAttributes.ViewSpecificAttributes.VerticalViewportScale);

RhinoApp.WriteLine("Setting to 10.0");
display_mode.DisplayAttributes.ViewSpecificAttributes.VerticalViewportScale = 10.0;

RhinoApp.WriteLine("New Y-scale: " + doc.Views.ActiveView.ActiveViewport.DisplayMode.DisplayAttributes.ViewSpecificAttributes.VerticalViewportScale);

(Menno Deij - van Rijswijk) #3

Aha! I wil use this as soon as I have the chance. Thanks!

(Menno Deij - van Rijswijk) #4

Ok, it’s been over two weeks but I have tested this today and it works.
Thanks @dale for your solution.


i would like to see these lines in python. Do you see a chance to make this happen? I am looking for a long time for a analysis function like in IcemSurf. As I went a bit into python now, this could be my next project.
PS. I am still new into that stuff.
Thank you in advance and best regards,

(Dale Fugier) #6

Here you go:

import Rhino as rh
import scriptcontext as sc

def TestViewportScale():
    dm_id = sc.doc.Views.ActiveView.ActiveViewport.DisplayMode.Id
    dm = rh.Display.DisplayModeDescription.GetDisplayMode(dm_id);
    rh.RhinoApp.WriteLine("Old Y-scale: " + dm.DisplayAttributes.ViewSpecificAttributes.VerticalViewportScale.ToString());

    rh.RhinoApp.WriteLine("Setting to 10.0");
    dm.DisplayAttributes.ViewSpecificAttributes.VerticalViewportScale = 10.0;

    rh.RhinoApp.WriteLine("New Y-scale: " + sc.doc.Views.ActiveView.ActiveViewport.DisplayMode.DisplayAttributes.ViewSpecificAttributes.VerticalViewportScale.ToString());

if( __name__ == "__main__" ):


Thank you very much, Dale. I will go on with that.