2 Apr 2020

Generate images for Inventor models

You may want to generate images for your models from different angles automatically, so that they could be used e.g. on your website.

The Model Derivative API enables you to get a model's thumbnail in different sizes, but you cannot change the orientation - see POST jobThumbnail Output section.

In case of using the desktop version of Inventor, there would be an ActiveView under the Application object with a Camera that you could drive and call its SaveAsBitmap method to generate the image.

Though InventorServer (which is used by Design Automation API) has no ActiveView, you can still create a Camera object and drive the Document's ComponentDefinition with it. Here is the relevant part of the AppBundle that is using InventorServer to generate the images for different orientations of the model: 

public void RunWithArguments(Document doc, NameValueMap map)
    LogTrace("Processing " + doc.FullFileName);

    DisplayOptions opt = inventorApplication.DisplayOptions;

    // you can also set options available through the DisplayOptions object
    opt.Show3DIndicator = false;
    opt.DisplayQuality = DisplayQualityEnum.kSmootherDisplayQuality;

    // the properties under NewWindowDisplayMode have no effect, 
    // so e.g. currently you cannot switch to Wireframe mode
    opt.NewWindowDisplayMode = DisplayModeEnum.kWireframeRendering;

    dynamic invDoc = doc;
    ViewOrientationTypeEnum[] orientations = {
    var imagesFolder = System.IO.Path.Combine(
        System.IO.Directory.GetCurrentDirectory(), "OutputImages");
    foreach (var orientation in orientations)
        var fileName = orientation.ToString() + ".png";
        var filePath = System.IO.Path.Combine(imagesFolder, fileName);
        Camera cam = inventorApplication.TransientObjects.CreateCamera();
        cam.SceneObject = invDoc.ComponentDefinition;
        cam.ViewOrientationType = orientation;
        cam.SaveAsBitmap(filePath, 200, 200, Type.Missing, Type.Missing);
        LogTrace($"Saved image as {filePath}");

This would not only work for Inventor models, but all file types that Inventor can load.

You can find the sample project here: https://github.com/adamenagy/CreateImagesDA

If you want to set things up on Forge and run a WorkItem using the Interaction project of the above solution, then just add your Forge credentials to appsettings.json and provide signed URL's in the GetWorkItemArgs() function of Publisher.Custom.cs 

Related Article