Hi Wolfgang,
I am very new to coding and in a learning mode. I got something from a post of Xiaodong Liang. Here is what i executed. But I am not able to see anything in my Navisworks project.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Autodesk.Navisworks.Api;
using Autodesk.Navisworks.Api.Clash;
using Autodesk.Navisworks.Api.ComApi;
using Autodesk.Navisworks.Api.Plugins;
using Autodesk.Navisworks.Api.Interop.ComApi;
using Autodesk.Navisworks.Api.Interop.Plugins;
using ComApi = Autodesk.Navisworks.Api.Interop.ComApi;
using ComApiBridge = Autodesk.Navisworks.Api.ComApi;
namespace ClassLibrary1
{
public class Class1
{
// export the viewpoint image of clash result
public void exportClashViewPoint()
{
ComApi.InwOpState10 oState;
oState = ComApiBridge.ComApiBridge.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());
}
}
}
}