why m_clash variable is always empty???????
No matter what file, the results are the same.
public void GetClashDetail() {
ComApi.InwOpState10 oState;
oState = ComApiBridge.ComApiBridge.State;
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) //m_clash is always empty ??????
{
System.Windows.Forms.MessageBox.Show("cannot find clash test plugin!");
return;
}
ComApi.InwOclClashTest oNewTest = (ComApi.InwOclClashTest)oState.ObjectFactory(Autodesk.Navisworks.Api.Interop.ComApi.nwEObjectType.eObjectType_nwOclClashTest, null, null);
oNewTest.name = "Mytest";
oNewTest.status = Autodesk.Navisworks.Api.Interop.ComApi.nwEClashTestStatus.eClashTestStatus_NEW;
m_clash.Tests().Add(oNewTest);
}
I'm sorry,I should add that,it not a Plugin,it is a C# desktop program.
all the code:
using Autodesk.Navisworks.Api.Controls;
using ComApi = Autodesk.Navisworks.Api.Interop.ComApi;
using ComApiBridge = Autodesk.Navisworks.Api.ComApi;
using ComBridge = Autodesk.Navisworks.Api.ComApi.ComApiBridge;
using Autodesk.Navisworks.Api.Interop.ComApi;
using Autodesk.Navisworks.Api.Clash;
using Autodesk.Navisworks.Api.Automation;
using Autodesk.Navisworks.Api;
namespace NavisworksDemo
{
public partial class Form1 : Form
{
ViewControl VC;
DocumentControl DC;
public Form1()
{
InitializeComponent();
if (this.components == null)
{
this.components = new System.ComponentModel.Container();
}
VC = new ViewControl();
DC = new DocumentControl(this.components);
VC.DocumentControl = DC;
VC.Dock = DockStyle.Fill;
//VC.Location = new Point(Left + 10, Top - 10);
VC.Name = "myVC";
VC.Size = new System.Drawing.Size(750, 750);
this.Controls.Add(VC);
DC.SetAsMainDocument();
}
//open
private void tSMIOpenFile_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == DialogResult.OK)
{
DC.Document.TryOpenFile(ofd.FileName);
DC.Document.Tool.Value = Tool.Select;
}
}
//clash test event
private void tsmiClash_Click(object sender, EventArgs e)
{
Cla****erateResults();
}
void Cla****erateResults()
{
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")//no find InwOpClashElement
{
m_clash = (ComApi.InwOpClashElement)oPlugin;
break;
}
}
if (m_clash == null)//Always is null
{
System.Windows.Forms.MessageBox.Show("cannot find clash test plugin!");
return;
}
ComApi.InwOclClashTest oNewTest = (ComApi.InwOclClashTest)oState.ObjectFactory(Autodesk.Navisworks.Api.Interop.ComApi.nwEObjectType.eObjectType_nwOclClashTest, null, null);
oNewTest.name = "Mytest";
oNewTest.status = Autodesk.Navisworks.Api.Interop.ComApi.nwEClashTestStatus.eClashTestStatus_NEW;
m_clash.Tests().Add(oNewTest);
}
}
}