Navisworks 2014 API new feature – RenderPlugin

By Xiaodong Liang

I have frequently heard the voice that the developers want to draw some custom graphics in Naivsworks e.g. the custom red line. Now it came true. The new plugin type provides methods to render user-graphics. It can render in 3D model space or 2D screen space. The new class Graphics is used to create the 2D/3D primitives.

Firstly, create a class deriving from RenderPlugin. It is a kind of implicit plugin which has no interface. So the attribute DisplayName is useless.

[Plugin("RenderPluginTest", 
            "ADSK")]
    public class RenderPluginTest : RenderPlugin
    {
    }

Next, override the methods you want to use.

  • public virtual void OverlayRenderModel(View view,Graphics graphics)

This method renders the graphics in the overlay buffer.By default it’s set up for you to call graphics methods that take 3D model space coordinates. You can call graphics methods that take 2D model space coordinates from inside a BeginWindowContext-EndWindowContext block.

  • public virtual void OverlayRenderWindow(View view,Graphics graphics)

This method renders the graphics in the overlay buffer. By default it’s set up for you to call graphics methods that take 2D window space coordinates. You can also call graphics methods that take 3D model space coordinates from inside a BeginModelContext-EndModelContext block

  • public virtual void RenderModel(View view,Graphics graphics)

Similar to OverlayRenderModel, but renders in the main buffer.

  • public virtual void RenderWindow(View view,Graphics graphics)

Similar to OverlayRenderWindow but renders in the main buffer.

Where possible, it is recommended that you should be using Overlay*** to do ‘overly graphics’ rather than using ‘Render***’.

The code below draws a triangle and two lines.

public override void OverlayRenderWindow(View view,
                                Graphics graphics)
{   
    // the color for the graphics
    Color colorRed = Color.FromByteRGB(255, 0, 0);
    // color and alpha value 
    graphics.Color(colorRed, 0.7);
 
    //set line width
    graphics.LineWidth(5);
 
    Point2D p1 = new Point2D(20, 20);
    Point2D p2 = new Point2D(view.Width - 20, 20);
    Point2D p3 = new Point2D(view.Width /2.0, view.Height - 20);
 
    // draw triangle, fill in it
    graphics.Triangle(p1,p2,p3,true);
 
    // the color for the graphics
    Color colorGreen = Color.FromByteRGB(0, 255, 0);
    // color and alpha value 
    graphics.Color(colorGreen, 0.7);
 
    Point2D p4 = new Point2D(20, 20);
    Point2D p5 = new Point2D(view.Width / 2.0, (view.Height - 20) / 2.0);
    Point2D p6 = new Point2D(view.Width - 20, 20);
 
    //draw two lines
    graphics.Line(p4, p5);
    graphics.Line(p5, p6);
}

Since the 2D is in window space coordinates, the graphics will update with the view size changing.

 

 image

 

 

image

 

The code below draws a cylinder.

public override void OverlayRenderModel(View view, Graphics graphics)
{ 
    // the color for the graphics
    Color colorBlue = Color.FromByteRGB(0, 0, 255);
    // color and alpha value 
    graphics.Color(colorBlue, 1); 
 
    Point3D p1 = new Point3D(0, 0,0);
    Point3D p2 = new Point3D(0, 0,10);     
 
    // draw Cylinder 
    graphics.Cylinder(p1,p2,10);
 
    // the color for the graphics
    Color colorGrey = Color.FromByteRGB(128, 128, 128);
    // color and alpha value 
    graphics.Color(colorGrey, 1);
 
    Point3D p3 = new Point3D(20, 20,0);     
 
    // draw sphere
    graphics.Sphere(p3, 10);
}

image


Comments

8 responses to “Navisworks 2014 API new feature – RenderPlugin”

  1. Thanks for sharing this informative blog about 3D Graphic Model Rendering. It s very helpful blog.

  2. This is really a cool new feature, however, several things have changed in NW2015 and it no longer seems to work properly:
    – it’s no longer derived from ToolPlugin but directly from Plugin
    – there’s now only two functions: Render and OverlayRender
    – OverlayRender no longer seems to produce any visible graphics
    – Render seems to work like OverlayRender did previously, but only while debugging; when running NW2015 normally, the graphics pop up shortly then directly disappear again
    to summarize: what’s up?! How do I fix my code?

  3. Thanks for the article. I just tried this in Navisworks 2018 and was able to make some progress so I can clarify on Michael’s questions.
    OverlayRender now seems to work in screen space, replacing BeginWindowContext-EndWindowContext.
    Render works for me, but does have some issues with the camera near clipping distance, so geometry that is outside the bounding box of the existing loaded models gets cut off depending on the camera angle.

  4. NAVEEN D LAZAR Avatar
    NAVEEN D LAZAR

    Hi Kyle,
    The sphere creates and then suddenly disappears. I’m not having any luck in implementing the BeginWindowContext-EndWindowContext. Below is my code. I would really appreciate your help. Please help :( Thanks.
    public override void Render(View view, Graphics graphics)
    {
    counter_graphic++;
    if (counter_graphic == 1)
    {
    Point3D p3d = null;
    BeginWindowContext(view, graphics);
    {
    //color for graphics
    Color yellow = Color.FromByteRGB(255, 255, 0);
    graphics.Color(yellow, 0.8);
    //center of the current selection
    p3d = new Point3D(169.259, 39.538, 213.128);
    //Point3D oCenter = GetClosestGridIntersection();
    if (p3d != null)
    {
    //draw a Sphere
    graphics.Sphere(p3d, 1);
    }
    //}
    }
    EndWindowContext(view, graphics);
    {
    graphics.Sphere(p3d, 1);
    }
    }
    }

  5. Oscar Ramirez Avatar
    Oscar Ramirez

    Hello NAVEEN D LAZAR,
    Did you have any luck with it? I am having the same issue renderig geometries. As soon as I stop moving the camera, they disappear.
    There is little to none information in regards to RenderPlugin class.

  6. You have to redraw your geometries each time.

  7. It seems that the render method is triggered each time your mouse move.
    You can test by removing your IF condition.
    If you want to keep your “counter_graphic”, you have to save each geometries into a list and redraw each element in render method.

  8. HI, I could implement it well in Revit 2020. But my question is: How to control this and show the geometry when the user hit the button to activate? I am able to do this when use ToolPlugin but I would rather not overlay any tool to make that available. So Using RenderPlugin should be perfect if I could apply this.

Leave a Reply to NAVEEN D LAZARCancel reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading