DrawtoBitmap with my own created RhinoViewport - c# RhinoCommon

Hi,
It’s possible to draw own created RhinoViewport with DisplayPipeline.DrawToBitmap method to Bitmap?
With standard Rhino Viewports DrawToBitmap works perfect, but when I create my own viewport then DrawToBitmap return null bitmap.

RhinoViewport rviewport = new RhinoViewport();
Bitmap vportBitmap = DisplayPipeline.DrawToBitmap(rviewport,200,200);

Hi Marcin,

Can you explain a little bit more details about what you want to do and why? What problem are you trying to solve?

Thanks,

– Dale

I want to generate a preview Image of i.e MeshObject, something like Preview in MaterialEditor.
I draws the object on Viewport through DisplayConduit:

if(Viewport.Id == MyViewport.Id)
{
DrawMesh(myMesh);
}

The problem is that when I call the method DrawToBitmap (MyViewport) then return null Bitmap.

Hi,
I found a simple solution (maybe not elegant) just simply create a InstanceDefinition from object, then create preview with InstanceDefinition.CreatePreviewBitmap. After create bitmap simply purge InstanceDefinition from InstanceDefinitionTable.

  List<Rhino.DocObjects.ObjectAttributes> objattrs = new List<Rhino.DocObjects.ObjectAttributes>();
            List<Rhino.Geometry.GeometryBase> geometries = new List<Rhino.Geometry.GeometryBase>();

            Rhino.DocObjects.ObjectAttributes objattr = new Rhino.DocObjects.ObjectAttributes();
            objattr.ObjectColor = System.Drawing.Color.Red;
            objattrs.Add(objattr);
            geometries.Add((Rhino.Geometry.GeometryBase) new Rhino.Geometry.Torus(Rhino.Geometry.Plane.WorldXY,100,PenSize.Value.Value).ToNurbsSurface());

            int idefindex = Rhino.RhinoDoc.ActiveDoc.InstanceDefinitions.Add("for preview", "preview image", new Rhino.Geometry.Point3d(0, 0, 0),geometries, objattrs);

        previewBitmap = `Rhino.RhinoDoc.ActiveDoc.InstanceDefinitions[idefindex].CreatePreviewBitmap(DefinedViewportProjection.Perspective, Rhino.DocObjects.DisplayMode.RenderPreview, new System.Drawing.Size(200,200));`

:slight_smile:

Hello

Sorry realive

sorry to revive this topic.

I’m using this method to extract small images from some objects;

Rhino.RhinoDoc.ActiveDoc.InstanceDefinitions[idefindex].CreatePreviewBitmap(DefinedViewportProjection.Top, Rhino.DocObjects.DisplayMode.Shaded, ponto,true)

Does anyone know how I can create the bitmap without isocurves and with the object’s color?

This my orignal:

This is the Bitmap result:
test

Thanks

Hi @MatrixRatrix,

Turn off the object’s isocurves before capturing.

– Dale

Hello @dale

Can I make my own DisplayMode just for this CreatePreviewBitmap?
Rhino.DocObjects.DisplayMode

Thanks

Sorry @dale

How do I convert DisplayModeDescription to DisplayMode?

Thanks