Rhino Common Issue with Rhinoview.CaptureToBitmap

viewport

(Phoberg97) #1

Hello Everybody,

i’m currently trying to create Bitmaps from Rhino Viewports. It’s important that my Images are created in Rendered Mode, also when the user is using Wireframe Mode for example.
So im using this [SDK Command] (http://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Display_RhinoView_CaptureToBitmap_5.htm) to achive this. It says Supported in: 5.4 WIP (Mac) but when im using this with any DisplayModeDescription it throws following exception:
System.NullReferenceException: Object reference not set to an instance of an object
at MechanismRemix.Commands.imgRendering.RunCommand (Rhino.RhinoDoc doc, RunMode mode) [0x000dd] in :0

Code to GetDescription:

 DisplayModeDescription getRenderMode(){
            DisplayModeDescription[] modes = DisplayModeDescription.GetDisplayModes();
            foreach (var dmd in modes)
            {
                if (dmd.EnglishName.Equals("Rendered")) return dmd;
            }
            return null; 
        }

It is not retruning null, i tested it.

Code for Creating Image:

Bitmap bm = doc.Views.ActiveView.CaptureToBitmap(new Size(bounds.Width, bounds.Height), getRenderMode());

Im using the latest WIP build fo Rhino for Mac.


#2

This may or may not not be related, but recently for one of my scripts I found that

DisplayModeDescription.GetDisplayModes() can return a list of display modes some of which could be None/Null…


(Phoberg97) #3

Thank you for the very quick answer!
Seems to not be related, i can do some operations on the Mode that is returned so it should not be null.
But its good to be aware ot that anyway :slight_smile:


(Dale Fugier) #8

Hi @phoberg97,

Thanks for reporting this.

https://mcneel.myjetbrains.com/youtrack/issue/MR-3201

– Dale


(Dale Fugier) #9

Also, this might be a more sane way of finding the Rendered display mode

private System.Guid RenderId
{
  get  { return new System.Guid("cae60bae-2d51-4299-abf7-a339fca86f3b"); }
}

...

var renderMode = DisplayModeDescription.GetDisplayMode(RenderId);
if (null !- renderMode)
{
  // TODO...
}

– Dale


(Dan Belcher) #11

Hi @phoberg97. Thanks again for reporting this. This will be fixed in the upcoming 5.4 update to Rhino for Mac.


(Dan Belcher) #12

@phoberg97 The 5.4 update to Rhino for Mac is published. This should be fixed.