I am working on integrating a NAvis Viewer in my Web Application. I am using the Navis API for listing the clashes in a Dropdown.
But I get the error:
[ERROR MESSAGE]
Unable to cast COM object of type 'System.__ComObject' to interface type 'NavisWorksAPI6.InwPluginsColl'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{D74F889B-01BA-11D5-A066-00B0D011BBC8}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
Code:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NavisWorksAPI6;
using NavisWorks6;
public partial class Clash : System.Web.UI.Page
{
nwOpState m_state;
InwOpClashElement m_clash = null;
DocumentClass m_doc;
public const string NWD_FILENAME = "C:\\Program Files\\Autodesk\\Navisworks Manage 2009\\API\\COM\\examples\\clashtest.nwd";
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
m_doc = new DocumentClass();
m_doc.Visible = true;
m_state =(nwOpState)m_doc.State();
m_doc.OpenFile(NWD_FILENAME);
m_state.CurrentView.ViewPoint.Paradigm = nwEParadigm.eParadigm_APPLICATION;
foreach (InwPluginsColl plugin in (InwPluginsColl)m_state.Plugins()) // ERROR LINE
{
InwPlugin plugin1;
plugin1 = (InwPlugin)plugin;
if (plugin1.ObjectName == "nwOpClashElement")
{
m_clash = (InwOpClashElement)plugin;
break;
}
}
if (m_clash == null)
{
Response.Write("Failed to find clash detective");
}
m_clash.RunAllTests("gatehouse.nwd");
foreach (InwOclClashTest clashTest in m_clash.Tests())
{
ListBox1.Items.Add("# CLASH TEST - " + clashTest.name + "#");
ListBox1.Items.Add("New Result:" + clashTest.NumNewResults);
foreach (InwOclTestResult clashResult in clashTest.results())
{
ListBox1.Items.Add("- RESULT[" + clashResult.name + "] Status[" + clashResult.status + "]");
}
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
}