Community
Navisworks API
Welcome to Autodesk’s Navisworks API Forums. Share your knowledge, ask questions, and explore popular Navisworks API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Navisworks 2011 .NET API Questions

13 REPLIES 13
SOLVED
Reply
Message 1 of 14
Anonymous
5256 Views, 13 Replies

Navisworks 2011 .NET API Questions

Hi All.

 

I am trying to automate the generation of a large number of NWD files via the automation 2011 API. I am running into a few problems and any guidance would be greatly appreciated.

 

a) Is the only way to apply PublishProperties onto a NWD is via the Document class? Can I use the Automation API here instead?

 

b) is the Autodesk.Navisworks.Api.Controls.DocumentControl the only way to access and construct a new Document object?I would rather use the Automation API as I don't need any visible control!

 

c) When processing the files via the Document object, if a DWG has a linked reference that cannot be found, it fails hard with a dialog indicating the issue. This of course is a blocking operation and doesn't lend well to automation. When processing the same files via the Automation API, I don't get this error dialog. Is there anything I can do to prevent the dialogs from coming up?

 

d) Since the Automation API seems to handle the error conditions silently, can I generate all of the NWDs without including PublishProperties from the original DWG, and then run a second pass applying the PublishProperties onto the NWDs?

 

e) does the 2012 API provide any new features that could help me here?

 

Thanks,

13 REPLIES 13
Message 2 of 14
Anonymous
in reply to: Anonymous

wow, the lack of support with the .NET API is disturbing. I can understand Autodesk trying to "force" their users into purchasing an ADN subscription, (and who knows the level of support is worth the purchase?), but not everyone has that kind of dough.

 

Does anyone,  have any thoughts on the above questions?

 

 

Message 3 of 14
john.lipp
in reply to: Anonymous

Hi |flyte|,


There is no publish method for the Autodesk.Navsiworks.Api.Automation.NavisworksApplication class, so you’ll need to use the Document class that has the PublishFile method.

Rather than create a control that you need to have open, you can still use Autodesk.Navisworks.Api.Automation.NavisworksApplication to run Navisworks silently and use its ExecuteAddInPlugin method. Create the add-in plug-in to publish to your NWD. In the plug-in, to get the document use the ActiveDocument  property of the Autodesk.Navisworks.Api.Application class.  Then call its PublishFile method.

There is an example that demonstrates how to use the Automation and plugin API libraries to send and receive information from a standalone application and a Navisworks Plugin:
 

 - C:\Program Files\Autodesk\Navisworks Manage 2011\api\net\examples\Automation\MessageSenderReceiver

Setting the visible property to false for the instance of NavisworksApplication should allow the "browse to" messages to be ignored when the XREFS aren’t found.  Those missing files just won’t be included in the NWD.

The 2012 version of the API does not have a publish method for the Autodesk.Navsiworks.Api.Automation.NavisworksApplication class either.  I’d recommend logging an enhancement on the feedback page for it:
 - http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=1109794


Best regards,



John Lipp
Support Specialist
Product Support
Autodesk, Inc.

Message 4 of 14
Anonymous
in reply to: john.lipp

Thank you John for your assistance!

 

I have another question - this one is quite odd.

 

If I use the API to "merge" files via the OpenFile and Save methods, sometimes the seection tree in the resutling NWD is "missing" nodes. For example:

 

if I have the following NWDs:

 

1.nwd

2.nwd

a.nwd

b.nwd

 

If I open and "merge" them as follows:

 

1.nwd

    2.nwd

         a.nwd

 

then in the resulting merged nwd, when opened in the selecion tree, looks like this:

 

1.nwd

   a.nwd

 

If the "parent" nwd only contains 1 "child" nwd, then the parent node is omitted. If it contains more than one, like in this example:

 

1.nwd

   2.nwd

     a.nwd

     b.nwd

 

then the selection tree appears as expected.

 

What is causing the parent nwd, that conains only 1 child, to dissappear?

Message 5 of 14
Anonymous
in reply to: john.lipp

Also, is it possible to publish to a different file version? The SaveFile method on Document has the ability to specify a DocumentFileVersion. but there is no obvious way with the PublishFile method.

 

Given the 2011 API, how can I publish to a 2010 verion?

Message 6 of 14
john.lipp
in reply to: Anonymous

Hi |flyte|,  


Thank you for the update.  Regarding the merging issue, could you send a snippet of the code that containing the opening/merging/saving?  I’m not sure of the ordering of the saving/merging and if files are being overwritten etc.

Here is an explanation of what may have occurred:

If you open a file (NWC/DGN/DGW/NWD) by itself, the original filename is replaced by the filename of the NWD you save to. The selection tree looks like:

NWD FILE
 - Layers/Levels

 

If you open multiple files or an NWF that references multiple files and save to an NWD file, the selection tree will be

NWD FILE
 - File1
 - - Layers/Levels
 - File2
 - - Layers/Levels



If you open that same NWD file, and save it again to RESAVE.NWD, the selection tree will be:

RESAVE.NWD
- File1
 - - Layers/Levels
 - File2
 - - Layers/Levels

 

And the original file name of the NWD disappears from the tree.  I think that this has to do with why a parent NWD that contains 1 child NWD is omitted in your code.  However, I’m confused as why the selection tree would still show:

1.nwd
   a.nwd


Is a.nwd merged with some other file besides an NWD before saving to 1.nwd?

Regarding publishing to a previous version NWD, this currently is not possible.  You are correct that the SaveFile method allows for the enum DocumentFileVersion; however, PublishFile does not.

Likewise, there is no ability to publish to a previous version from within the application, and there are enhancement requests logged in this regard for both (Application and API).  I’d recommend logging an enhancement on the feedback page for it.


Best regards,



John Lipp
Support Specialist
Product Support
Autodesk, Inc.

Message 7 of 14
Anonymous
in reply to: Anonymous

I’m afraid I have to agree. The .NET API is disappointingly limited. To do anything even remotely interesting the COM API bridge has to be used. But even on ADN the documentation for the COM APIs is virtually non-existent. 😞 The ADN knowledge base does contain a number of examples written in C# and VB6 that seem to capture much of the “tribal knowledge” of the Navisworks developers but its still a scavenger hunt.

Message 8 of 14
Anonymous
in reply to: john.lipp

Hey flyte, I was wondering if you could send me your code for this file merging concept.

 

I, like you, am finding documentation and support for these autodesk APIs to be very limited outside of the ADN.

 

This source code would be a great help to get me started with a similar thing I am trying to do.

 

Thanks!

 

(kurt.schempp.9999@gmail.com)

Message 9 of 14
Anonymous
in reply to: john.lipp

Thanks again for the response John. Sorry for the late reply.

 

I will double check my "merging" issues.. I will try to formulate an example should this appear again.

 

Some other questions:

 

a) Even though I have set the Visible property to false as soon as I create my NavisworksApplication instance, I do occasionally see an error dialog. See this image: navis api error message.JPG

 

Note the large (?) memory usage of the roamer.exe process. As soon as this process is killed in the task manager, the dialog goes away. This dialog is not from my application.

 

b) I also notice that the set of Automation*Exceptions thrown often have poor messages and don't explain why it occured: Typically they say "Error calling method: " with some negative integer. Here are some of the ones I have gotten recently:

 

Error calling method: -2147417851

Error calling method: -2147023170

Error calling method: -2147023174

 

Can you offer any more insight as to what is causing these exceptions to be thrown? This occur in some combination of OpenFile / SaveFile calls. Any idea what method those numbers refer to?

 

c) Navisworks is stealing application focus when it is being called from the Automation API. I have confirmed this by making a Win32 API call (I can provide the code if needed) to find out what application has focus when it is stolen from mine. I get the following:

 

Caption: Untitled - Navisworks Label: 2756932

 

Very annoying. If you have Tweak UI, you can enable a setting that will prevent apps from stealing focus (verified in XP, not sure in Win7) which solves my problem, but it would be better if Naviswork's didn't steal the focus in the first place.

 

Thanks again.

Message 10 of 14
Anonymous
in reply to: Anonymous

Can anyone from Autodesk, (John perhaps ? )  comment on the last set of questions above? Particularily on item b) regarding the error messages from the Automation API? I am running into these more and more often and I would like to know how I can at least attempt to identify the problem.

 

thanks,

Message 11 of 14
john.lipp
in reply to: Anonymous

Hi |flyte|

Regarding the “Failed to add an image to a list control.”  I’ve not been able to find any information on this type of error.  Being that the error message goes away when you kill the roamer.exe process, this suggests that the error message occurs in the application create, though you didn’t create the dialogue for it.

Would you be able to post your code so that I would be able to recreate the issue?  If the data is sensitive, could you log a support case through ADN?

 - www.autodesk.com/joinadn

 

I’m unsure of the memory usage being that large.  Does it not correspond to the file sizes of the models that you are loading/converting to an NWD? 

Regarding B, again, without the code and being able to reproduce the behavior, I’m unaware of what these errors are referring to.

Regarding C, when you state that it steals application focus, is this that the window of the API application takes focus on the screen?  Is this a different application than the one which you run with the visibility property set to false?


Best regards,




John Lipp
Support Specialist
Product Support
Autodesk, Inc.

Message 12 of 14
Anonymous
in reply to: john.lipp

Hi John, Sorry again for the late reply.. I have been busy with other items, but I also have spent more time on the above issues.

 

With respect to b);

 

Here is the code that would sometimes cause the errors in question:

 

try
{
    automationApplication.OpenFile(modelFile);
}

catch (Exception ex)
{
    logger.Warn("Unable to generate single NWD from model for: " + modelFile + " " + e.Message);
}

That is it. No other code is causing the exceptions + poor error messages. I am simply calling OpenFile() a number of times (1000's) and eventually calling SaveFile or Publish (via the plugin) to save a NWD.

 

I have discovered that some of the exceptions being thrown by the automation API (with the error message stating: Error calling method: -2147417851 [for example]) can be explained by some missing ObjectEnablers that needed to be installed for Navisworks Manage 2011. After installing these, many, (but not all), of the errors were avoided.

 

However, when I do come accross a DWG that causes an exception to occur, I notice two things:

1) once I get into the catch block, the roamer.exe process has terminated, thus causing the subsequent calls to OpenFile() to fail (Note that my NavisworksApplication object is still valid (i.e.: not null), but the roamer.exe process is gone.)

 

2) In the console output I see "A first chance exception of type 'System.InvalidOperationException' occured in Autodesk.Navisworks.Automation.dll

 

So as a temp workaround, I terminate and reinitialize my reference to the NavisworksApplication object once the exception is caught, (not shown in the above code snippet).  This at least allows me to continue on (mostly successfully) with the rest of the models to process.

 

Now the really puzzling this is that models that failed to open in one run would succeed to be opened in another. For example, modelA.dwg would fail to be opened in a run, but if I launch the run again (processing the same models) modelA.dwg may succeed in being opened.

 

This leads me to think that perhaps some other intermittent thing is at play here. I have tried copying and processing the models locally, but I still have the bizzarre results.

 

Could this be a license thing? I am accessing a  license server, and there are 100's of licenses available. Perhaps a license is trying to be grabbed at every OpenFile operation and this occurs too quickly??? Or does a a license only get grabbed when the roamer.exe process is started?

 

I'm grasping here.. but this issue is really killing me.

 

What are some other causes of the InvalidOperation exception being thrown by the Automation API, (keeping in mind that sometimes it works fine, sometimes it fails.)

 

As for C) - this issue is not nearly as critical to solve as B is for me. But to answer your question, ANY application that has focus (for example, Notepad) will loose it once myApp calls AnyMethodInNavisworksAutomationApi(). Running any application that uses the automation API and watching / monitoring which application window has focus will indicate this.

 

 

Message 13 of 14
Anonymous
in reply to: Anonymous

With respect to the license not available train of thought; I borrowed a license and tried my scenario again, but upon the first launch of the roamer.exe, the License Manager dialog appears indicating that I am using a borrowed license. This appears even though I have the Visible property set to false. The fact that this dialog appears is a non starter for me, and really makes no point to appear when accessing the Automation API (makes automation pointless if I have to manually dismiss it, or create a tool to watch for this dialog to appear, and then dismiss it

 

😕

 

 

Message 14 of 14
Anonymous
in reply to: Anonymous

bump

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


 

Autodesk Design & Make Report