|
![]() |
As well as the samples provided with the API several tools have been written to aid developers in learning the .NET API.
Tool Locations
The tools are all contained in source code in the samples directory: '<drive>:\Program Files\Autodesk\Navisworks <Product> 2015\api\net\examples' The tools locations relative to this folder are:
- AppInfo – PlugIns\AppInfo
- CodeRun – PlugIns\CodeRun and PlugIns\CodeRun\CodeRunLib
Building the tools
All the tools are delivered as part of the API samples as source code and need to be built before they can be used.
- Load the project's '.csproj' project file in Visual Studio.Net.
- If the Navisworks API was not installed in the Navisworks Installation directory then edit the post build step to copy the required files into the {ProjectName}.ADSK directory under the plug-ins directory. This directory does not yet exist but will be created by the post build step.
- Select Release Mode and Build the project.
AppInfo Plug-in
The AppInfo plug-in is a useful tool for developers as it displays a lot of information regarding the document and the application as well as the relative relationships of classes.
A key feature of the tool is that the Model's objects and properties in the API can be explored in a running application with real data.
Clicking 'AppInfo' under the 'Add-Ins' tab
will bring up the tool as seen below:
AppInfo displays the Model a tree which can be explored on the left. When users click on an object in the tree the available class properties, methods and events are listed on the right. For both the selected object and its properties the ToString() values are displayed.
Events can be subscribed to using the checkboxes. When the event is raised, the output area at the bottom of the window displays the event and the parameters passed with it.
CodeRun Plug-in
This plug-in, written in C#, enables developers to test aspects of code and samples within Navisworks, without having to re-build entire plug-ins and restart Navisworks.
The plug-in comes in two parts. First is the main program (CodeRun) and second is a library (CodeRunLib) which contains the methods used to compile and run code in .NET.
Clicking 'CodeRun' under the 'Add-Ins' tab will bring up the tool as seen below:
As this assembly has all the access of a standard plug-in, you can effectively access anything you would normally from a plug-in. For example try the following:
- In CodeRunner Select Visual C# .NET from the Language combo (1).
- Click 'Set Default Template' (2).
- Replace the text in the main body code (3) marked '/*Code goes here!!*/' with the following as in the example: Console.Write(Autodesk.Navisworks.Api.Application.ActiveDocument.SuggestedFileName);
- Ensure the 'Full Class Name' (4) matches that shown in the 'Main Code Body' (3).
- Ensure the 'Main Function' (5) matches that contained in the 'Main Code Body' (3).
- Click Run (6). The output (7) will now show the output of the function which was written to the Console.
There is also a menu for opening and saving files to and from the 'Main Code body'.
Using other .NET languages with CodeRun
If a user has an alternative .NET compliant language that they wish to use then there is an abstract class (contained in CodeRun\CodeRun.cs) which can be derived from. The compiled assembly should then be built and placed in the directory '<drive>:\Program Files\Autodesk\Navisworks <Product> 2015\Plugins\CodeRun.ADSK\Compilers'.