API to find the best viewpoint for clashes

API to find the best viewpoint for clashes

Anonymous
Not applicable
3,558 Views
10 Replies
Message 1 of 11

API to find the best viewpoint for clashes

Anonymous
Not applicable

To find the best viewpoint for any clash, I want to have a camera viewpoint which has no/minimum obstruction. 

 

Is there a way to select the best viewpoint using API as manually finding the best viewpoint is very cumbersome as number of clashes are very high.

0 Likes
3,559 Views
10 Replies
Replies (10)
Message 2 of 11

Anonymous
Not applicable
I do not want to Hide other objects as it creates difficulty in coordination. Without hiding, I want to find the viewpoint with minimum obstruction.
0 Likes
Message 3 of 11

Wolfgang.B.Weh
Enthusiast
Enthusiast

Hi,

 

Did you try the GetSuitableViewPoint function?

 

The function is member of the COM test result:

Autodesk.Navisworks.Api.Interop.ComApi.InwOclTestResult

 

Regards

 

Wolfgang

0 Likes
Message 4 of 11

Anonymous
Not applicable

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());
}
}
}
}

0 Likes
Message 5 of 11

Anonymous
Not applicable

I saved the .dll file in the navisworks manage 2016 plugin folder. I did the registry for COM Api plugin. When I run the program, it opens navisworks but before opening it gives the message "third party plugin cannot be loaded". I am unable to solve this problem.

0 Likes
Message 6 of 11

Wolfgang.B.Weh
Enthusiast
Enthusiast

Hello amin9,

 

I'm using similar code, based on the example from Xiaodong Liang, and it works fine for me.

 

Are there any clashes stored in your Navisworks file?

 

Did you run the clash detective and save the Navisworks file afterwards?

 

Regards

 

Wolfgang

0 Likes
Message 7 of 11

Wolfgang.B.Weh
Enthusiast
Enthusiast

Hello amin9,

 

from what I can see on the screenshot, you haven't defined any PluginAttribute with your addin.

 

Did you already download the SDK already?

And the training labs?

http://usa.autodesk.com/adsk/servlet/index?id=15024694&siteID=123112

 

I would strongly recommend to read the first few chapters of the "NET API.chm".

"Plugins > Writing Plugins" tells you what you have to do to create a basic plugin.

 

The API also has a number of examples to get you started.

 

Hope that helps.

 

Wolfgang

0 Likes
Message 8 of 11

Anonymous
Not applicable

Thank You for your response. I went through the chapters. I am able to see the plugin in Navisworks. But it is not doing anything.

Please find my current code and snapshot attached.

 

Also where can I find the exported image when I click the PlugIn?

 

 

0 Likes
Message 9 of 11

Anonymous
Not applicable

Can somebody help me with the problem ?

0 Likes
Message 10 of 11

Wolfgang.B.Weh
Enthusiast
Enthusiast

Line 48 should read :

return 0;

 

The method "Execute" must return an integer.

0 is usually interpreted as False.

1 is usually interpreted as True.

 

https://msdn.microsoft.com/en-us/library/1h3swy84.aspx

http://www.homeandlearn.co.uk/csharp/csharp_s6p3.html

http://www.codeproject.com/Articles/79508/Mastering-Debugging-in-Visual-Studio-A-Beginn

 

 

HTH

 

Wolfgang

 

0 Likes
Message 11 of 11

Anonymous
Not applicable

Thanks a lot. The plugin worked.

 

But the function getsuitableviewpoint() just zooms in the viewpoint of "focus on clash". If there is any obstruction of the viewpoint, then still the clash is hidden and we have to rotate the camera manually.

 

Is there any function or a way which moves the camera positon so that it detects that there is no object between the camera and the clash point ? This will prevent the manual work of rotating and zooming around the clash point in order to see it clearly.

0 Likes