Workaround to export image of clash result

By Xiaodong Liang

I have heard such question a couple of times. The .NET API provided Clash, but did not expose the ability to export the viewpoint image of the clash result. In COM API, the clash result (InwOclTestResult) provides viewpoint and the method CreatePicture which should create a picture of this clash. But  it looks CreatePicture does not work.

Following is a workaround which may help a bit. It gets one clash test, gets its viewpoint, creates one saved viewpoint.And it applies the saved viewpoint. Finally it exports the current view to a picture by the plug-in “lcodpimage”. Unfortunately, the image has NOT the information to show (highlight) the clash entities as what you can see from UI.

 

// export the viewpoint image of clash result    public void exportClashViewPoint()    {        ComApi.InwOpState10 oState;        oState = ComBridge.State;             //find the clash detective plugin        ComApi.InwOpClashElement m_clash = null;             foreach (ComApi.InwBase oPlugin in oState.Plugins())        {            if (oPlugin.ObjectName == "nwOpClashElement")            {                m_clash = (ComApi.InwOpClashElement)oPlugin;                break;            }        }             if (m_clash == null)        {            System.Windows.Forms.MessageBox.Show(                "cannot find clash test plugin!");            return;        }             //Run all  clash test or specific clash        //or assume the UI has the results already             //m_clash.RunAllTests(null);                  // get the plug-in of exporting image        ComApi.InwOaPropertyVec options =             oState.GetIOPluginOptions("lcodpimage");             // set to the format to png        foreach (ComApi.InwOaProperty opt in options.Properties())        {            if (opt.name == "export.image.format")                opt.value = "lcodpexpng";        }                try        {            // get the first Test and its first clash result            ComApi.InwOclClashTest clashTest = m_clash.Tests()[1];            ComApi.InwOclTestResult clashResult = clashTest.results()[1];                 // create a temporary saved viewpoint            ComApi.InwOpView oSV =                 oState.ObjectFactory(                ComApi.nwEObjectType.eObjectType_nwOpView);            oSV.name = "temp-view";            oSV.anonview.ViewPoint = clashResult.GetSuitableViewPoint().Copy();                    oState.SavedViews().Add(oSV);                 // apply the temp saved viewpoint            oState.ApplyView(oState.SavedViews().Last());                 // export it to an image            string tempFileName =                "c:\temp\" +                 clashTest.name + "- " +                 clashResult.name + ".PNG";            oState.DriveIOPlugin(                "lcodpimage",                 tempFileName,                options);                 // delete the temp saved viewpoint            oState.SavedViews().RemoveLast();        }        catch (Exception ex)        {            MessageBox.Show(ex.ToString());        }    }

Comments

3 responses to “Workaround to export image of clash result”

  1. Thanks for the post Xiaodong Liang, yes this workaround helps a bit. :)
    A note on above code…
    The ComApi.InwOclTestResult has the method “GetSuitableViewPoint” and the property “ViewPoint”.
    If the clash result has a saved viewpoint, you can use the ViewPoint property to get that saved viewpoint, otherwise you can use the GetSuitableViewPoint method to get a nice focused view on the clash.
    Regards
    Wolfgang

  2. Evgeny Fedorov Avatar
    Evgeny Fedorov

    And again you have helped. Thank you Xiaodong Liang.
    Regards. Evgeny Fedorov(sgnhp).

  3. Nicholas Avatar
    Nicholas

    Hi Xiaodong,
    Is there a way to export images when in “-NoGui” mode?
    I have tried the above com code and this .net code below, nothing works.
    Bitmap bitmap = doc.ActiveView.GenerateThumbnail(960, 540);
    bitmap.Save(imageSaveName, System.Drawing.Imaging.ImageFormat.Jpeg);
    i have been using this command line argument to start Navisworks with out any GUI as it works much faster for most processes.
    command line argument
    -NoGui-ExecuteAddInPlugin “NavExportImageTest.BIMe” “BatchMode”

Leave a Reply to Wolfgang WehCancel reply

Discover more from Autodesk Developer Blog

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

Continue reading