Quantcast
Channel: Le Zhang » Navisworks
Viewing all 12 articles
Browse latest View live

Navisworks 2013 API Getting Started Tutorial

$
0
0

Autodesk Navisworks has been providing API for advanced users to extend its functionality since 2011. The newest version, 2013, has even more power build in. However, it seems there is a lack of complete getting started tutorial, either in the API doc package or on the Web. So here I am writing one myself.

Before getting your hands dirty, make sure you have Navisworks Manage (Simulate should work also) installed. Freedom does not support API. Also, make sure you have Microsoft Visual Studio (VS) installed. This tutorial is finished in VS 2012, but older version should also work. Besides the software requirements, you do not need any knowledge about programming language to finish this tutorial, but obviously, if you want to do something serious with the API you need to learn programming. I recommend C#.

You may have been trying to search the Web for an API package download and in vain. In fact the API is shipped with the standard Navisworks installation. Go to the Navisworks installation folder (I am gonna use <NavisworksFolder> below to denote this folder), you should be able to find an “api” folder. All we need are in there.

Among the three folders (COM, net, nwcreate) in the api folder, we are going to use the “net” folder. In the “net\documentation” folder, there is a windows help file named “NET API.chm”. This file has two main parts: a “Developer Guide” as a tutorial and a “Reference Guide” as the API documentation. This is a good resource and you may want to read through the first part and finish the sample code later and keep the second part handy for reference. Most of the content in this tutorial is corresponding to the “Developer Guide – Plug-ins – Writing Plug-in” article in this help file. But: first, some very critical information is missing from that article (although the information is scattered through the help file); second, this article is hidden in the middle of the help file and there is no clue it is the getting started tutorial that you should read first (seriously, the article should be placed at the very beginning of the help file).

Now let’s code our first plug-in in Navisworks that does nothing but show us a “Hello World” message.

1. Start a new project.

Click File – New – Project to start a new project in VS. Choose “Visual C#” from the left panel of Templates, and then the “Class Library” template. Give the project a name “LeZhangPlugin” (or whatever you like). VS will automatically create a solution with the same name to put this project in. Make sure the “Create directory for solution” is checked. Don’t worry about the solution stuff but do remember the location of the project, since you will need to go there later to dig some file out. Click OK and it may take a while for VS to create and open the project. (BTW, click the pictures in this blog to see actual size pics.)

2. Add project reference.

In the right panel Solution Explorer, right-click the “References” and click “Add Reference”.

First reference we need to add is System.Windows.Forms. Find it in “Assemblies-Framework”.

The second reference we need is Autodesk.Navisworks.Api.dll. You need to click “Browse” and find it in the folder <NavisworksFolder>\api\net\bin\x86.

Click OK. Note: After the references are added, you need to select Autodesk.Navisworks.Api in the Solution Explorer, and change the “Copy Local” property to false. Otherwise it will not build.

3. Add code.

VS has already added some code skeleton. We need to add something more:

Add these two lines below the last “using xxx”:

using System.Windows.Forms;
using Autodesk.Navisworks.Api.Plugins;

Add the following code below “namespace LeZhangPlugin {“ and above “public class Class1″. Let’s ignore the meaning of the strings for now, just remember it is a configuration code for our plugin.

[PluginAttribute("LeZhangPlugin.MyAddIn", "LZNT", ToolTip = "Hello World by LeZhang.net", DisplayName = "LeZhang.net")]

After “public class”, change “Class1″ to “MyAddIn : AddInPlugin”.

Add the following code in the inner curly brackets:

public override int Execute(params string[] parameters)
{
MessageBox.Show(Autodesk.Navisworks.Api.Application.Gui.MainWindow, “Hello World”);
return 0;
}

At last, although not really necessary, you may want to change the name of the cs file from Class1.cs to MyAddIn.cs (same name as the class name). This is a good programming habit that will benefit you in the long run.

4. Build the project.

Click Build – Build Solution, or simply press F6 on your keyboard. If Warnings are shown at the bottom, ignore it for now as long as they are not Errors.

5. Create a folder for the plugin.

Go to <NavisworksFolder>\Plugin, create a folder named “LeZhangPlugin” (the exact name used for the project).

6. Copy the dll file.

Go to <VisualStudioProjectFolder>\LeZhangPlugin\LeZhangPlugin\bin\Debug, copy the LeZhangPlugin.dll file to the <NavisworksFolder>\Plugin\LeZhangPlugin folder we have just created.  Make sure the dll file name and the plugin folder name match each other.

7. Start Navisworks. You should see a new tab named “Add-ins”, with a new button named “LeZhang.net”. Move your mouse on the button and it shows “Hello World by LeZhang.net”. Now you know the meaning of the configuration code. Click it and a message box is shown saying “Hello World”.

Hooray~ This is the end of this tutorial. If you find this is getting interesting, you may want to checkout my next tutorial: Navisworks 2013 API DockPane Tutorial


AppInfo Tool in Navisworks 2013 API

$
0
0

AppInfo is a tool for developers provided in Navisworks 2013 API. It provides useful information in real time, and can be used as a dynamic reference documentation. But it seems the information in the tool is not complete. Developers should use AppInfo along with the API doc. Here I listed some of the info that is not shown in AppInfo.

1. Autodesk.Navisworks.Api.Application.Gui.MainWindow.

This is used when a MessageBox is shown, e.g. “MessageBox.Show(Autodesk.Navisworks.Api.Application.Gui.MainWindow, “Hello World”);”. But the “MainWindow” property is not included in Gui of AppInfo.

Navisworks 2013 API DockPane Tutorial

$
0
0

This tutorial continues our effort in Navisworks 2013 API from the Getting Started Tutorial by adding a Graphical User Interface (GUI) in the form of DockPanePlugin to the basic AddInPlugin. I am assuming you have finished that tutorial first, or, you already have a running AddInPlugin in Navisworks as the entry point that we can working on.

1. In the same project, right click the project in the Solution Explorer – Add – Class…; Choose “User Control” from the list of all available Visual C# Items; Change the Name to “HelloWorldControl.cs”. This will be the user interface shown when our plugin is triggered.

2. Click Add and a blank grey box should be automatically shown in a new window. If not, double click the “HelloWorldControl.cs” in the Solution Explorer. This grey box works as a canvas where you can put stuff on. The stuff available are organized in Toolbox. Click the “Toolbox” tab at the left top corner of the window right under the VS toolbar, and a floating panel called “Toolbox” should appear as shown below. You may want to pin this panel so it will stay there.

3. As you can see, the panel has all kinds of controls that you should already be familiar from using different Windows-base applications. We are just going to add a Label, which is under “Common Controls”, into the grey box.

4. Highlight the Label. At right bottom corner of the window it shows all the “Properties” of the label. Find “Text” property (NOT the “(Name)” property) and change it to “HelloWorld”. You should see the text on the label changed to”HelloWorld” immediately. That’s all we need for the user interface HelloWorldControl right now.

5. Now we need to add another class as the link between the AddInPlugin and this HelloWorldControl. Right click on the project, click Add-Class…. Choose the basic “Class” type, and I will name this class “MyDockPane”. Add the following code:

Add two lines of using statements:

using System.Windows.Forms;
using Autodesk.Navisworks.Api.Plugins;

Add two lines afte namespace name but before class name:

[Plugin("LeZhangPlugin.MyDockPane", "LZNT", DisplayName = "LeZhang.net", ToolTip = "Basic DockPane by LeZhang.net")]
[DockPanePlugin(700, 700)]

After the class name “MyDockPane”, add “: DockPanePlugin”.

Add the following code as the body of the class:

public override Control CreateControlPane()
{
HelloWorldControl control = new HelloWorldControl();
control.CreateControl();
return control;
}

public override void DestroyControlPane(Control pane)
{
pane.Dispose();
}

6. Then we need to go back the MyAddIn class to add code to call MyDockPane. Add the following code after the call of MessageBox but before “return 0;”:

// starting new code for DockPanePlugin
// find the plugin first using its pluginId

PluginRecord pr = Autodesk.Navisworks.Api.Application.Plugins.FindPlugin(“LeZhangPlugin.MyDockPane.LZNT”);

if (pr != null && pr is DockPanePluginRecord && pr.IsEnabled)
{
MessageBox.Show(Autodesk.Navisworks.Api.Application.Gui.MainWindow, “MyDockPane found”);
// the plugin might need to be loaded into the system
if (pr.LoadedPlugin == null) { pr.LoadPlugin(); }
MessageBox.Show(Autodesk.Navisworks.Api.Application.Gui.MainWindow, “MyDockPane loaded”);
// the plugin need to be casted into a more specific type
DockPanePlugin dpp = pr.LoadedPlugin as DockPanePlugin;
if (dpp != null) { dpp.Visible = !dpp.Visible; }
}

// end of new code for DockPanePlugin

7. At last we need to build the solution and copy the dll file to <NavisworksFolder>\Plugins\LeZhangPlugin folder. Start the Navisworks and have a look at what you got.

Try to play around with all the different controls and have fun!

After this tutorial, you may want to take a closer look of the sample projects coming with Navisworks and try to understand the meanings of the code.

How to Use the Navisworks 2013 API Sample Projects

$
0
0

(Still under construction… Any comments are appreciated.)

This article only deals with the sample projects ships with Navisworks 2013 API. They are good starting point to get yourself familiar with the API, both the code itself and the way the different classes are organised. The sample projects are installed with standard Navisworks Manage installation. You can find them in folder “C:\Program Files\Autodesk\Navisworks Manage 2013\api\net\examples” (referred to as <examples> below). All the 32 sample projects are organised in one single VS solution, with Examples.sln solution file in the examples folder. Check here for other sample projects and other resources I collected from the Web.

First, I recommend you to copy the whole “examples” folder to a new and secure place on your hard drive, just for reference and for backup. Then, there will be basically two ways to use them: 1. use the original project files in the Navisworks folder directly; 2. use the copied new files.

Using the original files

One of the advantages of using the original solution is that you can take advantage of the post-build events already build into the projects, which will copy the generated dll file to the proper position in the Plugin folder automatically. The disadvantage is the management and relationship of the whole bunch of the 32 projects. I have tried to sort them through below. I recommend building and debugging the projects one by one on the project instead of building or running the complete solution, or you might find some unexpected stuff going on, like too many add-ins appear in Navisworks all of a sudden.

Since the original files are in Program Files folder in Windows system, so another nuance is that the VS may need special authorization to work in the Program Files folder directly. I recommend turning off Windows UAC completely.

Note that the organisation of the project files, including folder names and order etc., in the VS Solution Explorer are NOT the same as the folder organization in Windows. (Although I personally don’t think this is a best practice.) Check the following two pics showing both for your reference. In this section whenever I am referring some folder I man the ones in VS (Windows folders are used in the next section.)

Of the 32 projects, only 1 is C++ and 4 are VB. Both of these are in “Basic Examples” folder. All the others are written in C#.

1. Tools

The projects are organised into 6 folders. The first you should try is the Tools, which has three projects (in fact there are only two tools, project CodeRunLib is used in project CodeRun). The AppInfo is the first one you should try. It is pretty straight forward and the tool is useful. You may want to check this blog for more information about this tool. The CodeRun is a little naughty. Check this blog for more details on building and running this tool.

2. Basic Examples

The next step is to go through the Basic Examples, which include 9 C# projects, 1 C++ projects and 4 VB projects.

Of the 9 C#projects, the BasicPlugIn is the simplest HelloWorld, the first one you may want to try. This project is corresponding to “Developer Guide – Plug-ins – Writing Plug-ins” in the API doc. But if you are not familiar with C# or the API, try to follow this tutorial to get started. The next project you may want to check out is the BasicDockPanePlugin. This one adds a user interface to the basic HelloWorld. Check this tutorial for reference. I have not find corresponding article in the API doc. The third project is the CustomRibbon project. Although no corresponding article in the API is found yet also, but this sample project has extensive inline comment on building diversified ribbon menu items like the one shown below. You may also want to study how the resources like the icons and pictures are organised.

Next you may want to check out FileManipulation. This project is different in that it is not a “Class Library” type but a “Console Application” type, which means running this program will NOT need to activate Navisworks first (or you can also think Navisworks are activated but running at background). This project uses the Autodesk.Navisworks.Api.Automation namespace. What it does is to merge two CAD files into one NWD file, although the merge is certainly not perfect (see pic below). Note the merged files are stored in the Windows Explorer folder “<examples>\Basic Examples\CSharp\Debug” instead of in the FileManipulation folder. This sample projects is corresponding to the “Developer Guide – Automation” from the API doc. In that article there is also code for calling existing plugins through Automation API.

Next project to check out is the Viewer, which again is not a typical Class Library type plugin but a Windows Application. The namespace used is Autodesk.Navisworks.Api.Control, which adds the Navisworks user interface controls to your own Windows forms application. For example, this project generates a simple Navisworks file viewer as shown below. This project is corresponding to “Developer Guide – Using the Controls” from the API doc.

The other projects may not be really interesting. The ControlsAndCOM project calls the legacy COM API. This project is corresponding to “Developer Guide – Using the Navisworks COM API with the .NET API” from the API doc (Note the description of the sample project location in the doc is wrong).

Using the new files

The advantage of using the new files is that you can add the sample projects one by one. Easy to manage, easy to understand. But the post-build events probably are not going to work so you need to edit the event or to manually copy the generated dll files to the installation folder.

The folders being referred in this section are those in Windows Explorer (which are not necessarily the same as in VS).

CodeRun Tool in Navisworks 2013 API

$
0
0

The CodeRun tool included in Navisworks 2013 API is supposed to be able to run code snippets without involving building and copying and restarting Navisworks. This tool actually includes two projects, “CodeRun” and “CodeRunLib”, which must work together.

File locations

If you are using the original sample projects files in the Navisworks folder, post-build events are already configured to copy the generated dll files to the proper location in Plugins folder. However, if you are trying to build from another location, you maybe confused where to place the generated dll files. Here is the answer:

In C:\Program Files\Autodesk\Navisworks Manage 2013\Plugins\, create a new folder called “CodeRun.ADSK”, and in this folder create a new folder called “Compilers”. Below is a pic of the resulting folder structure.

Then put the “CodeRun.ADSK.dll” file generated by CodeRun project into “CodeRun.ADSK” folder; put the “CodeRunLib.dll” file generated by CodeRunLib project into “CodeRun.ADSK\Compiliers” folder.

VS2012 problem

It seems the CodeRunLib project has some problem with Visual Studio 2012, at least the RC version I am using at the time of writing. Here is a detailed discussion of this problem. Or, jump the length discussion and find the remedy here.

How to Debug/Run Navisworks 2013 API Programs

$
0
0

Of course you can just type in code, click build, go to Windows Explorer, copy your dll files to Plugins folder, start Navisworks and click the buttons on the Add-in tab. But what’s fun with that? Besides, that will not give you useful real-time info for debugging. Here in this blog I present you some simple configurations that can make your API life a little bit easier.

Use Post-build Event

Using post-build event to copy the generated dll file (and pdb file for debugging) to the destination folder in Plugins.

1. Right-click the project, choose Properties.

2. Click the Build Events tab on the left, copy the following to the “Post-build event command line”:

xcopy /Y “$(TargetDir)*.*” “C:\Program Files\Autodesk\Navisworks Manage 2013\Plugins\$(TargetName)\”

The “xcopy” is a Windows command for copying stuff. The “/Y” is a switch that tells the system to overwrite anything in the destination folder without letting the user confirm.

The $(Xyz) are macros that will be replaced by actually values. For example, on my machine it will be replaced as “xcopy /Y “D:\zhangle\BIM\Navisworks\API\myVsProjects\LeZhangPlugin\LeZhangPlugin\bin\Debug\*.*” “C:\Program Files\Autodesk\Navisworks Manage 2013\Plugins\LeZhangPlugin\”". Using the macros are good for code portability and ease to read and understand. If your Navisworks is not installed at the default folder, you need to adjust the destination folder accordingly. If you want to know all the macros, you may want to click the “Edit Post-build …” button, and click the “Macros” button.

Configure Start Action

If you just click the “Start” button in VS just like you are doing for any stand-alone application, VS will show you the following error message. Indeed, what we have created is a “Class Library” project, which generates a dll file. We need somehow trigger Navisworks first and run our program in it.

1. Right-click your project name in the Solution Explorer, and click Properties, which is at the bottom of the pop-up menu.

2. Click Debug tab on the left; in Start Action group, choose “Start external program”. Click the browse button to go to Navisworks installation folder, and choose “Roamer.exe”. (I have no idea about the name, but trust me.) Save and close the project properties page.

3. In the code you want to run and debug, find an interesting statement and click the left side border of the code window as shown below. A red dot should be added as a “break point”, which means when running, the program will stop BEFORE running this statement to give you a chance to look into the status of the program.

4. Click the Start button in VS again. Navisworks should start automatically.

5. Do something that will trigger your break point code. You will notice that your program will stop at the statement, while you can check the program status and use the different debug tools.

Keep these in mind if a strange bug appears

Check which .NET framework you are using. Right-click your project – Properties. Make sure the “Target framework” is selected as .NET Framework 4. Since VS2012 uses .NET 4.5 as the default framework, some strange bugs may be as a result of the compatibility between different .NET framework versions. In one of my VS2012 project using Autodesk.Navisworks.Automation.dll, the assembly can be added into the reference without errors, but when running it throws “FileNotFoundException” on the Automation file. Changing the framework back to 4 then works fines.

Object Counter by LeZhang.net v0.5

$
0
0

LeZhang.net is proud to announce its first product: Object Counter Plugin for Autodesk Navisworks 2013.

0. General information 

This tool takes advantage of Navisworks API, which allows advanced users to code plugins to add functionality to existing Navisworks functions. The purpose of this plugin is to count the number of the actual model objects in a single model file, while filtering out the supporting entities including File, Layer and Subentity.

Navisworks Manage should be installed. (Simulate should work also, but not tested.) The plugin works on nwc, nwf and nwd files.

The Navisworks model project that the plugin is developed for is generated from an AutoCAD dwg file. It should work for models from other files also, but minor changes may be required.

1. Installation 

Close Navisworks application if it is open.

Find Plugins folder in the Navisworks installation folder. Create a folder named LeZhangPlugin.

Copy the LeZhangPlugin.dll file into this folder. The folder hierarchy should look like this:

Start Navisworks. A new tab named Add-ins should appear. A button named Object Counter should be available on this tab.

2. Before activating the plugin 

A model file should be opened first. Otherwise the plugin throws a warning notice as below:

3. Selection mode 

Two modes are currently supported. If a selection is made somehow before activating the plugin (either using the selection tree or mouse-click directly in model viewer, either single node/object or multiple nodes/objects, or any other way), it will automatically use selection mode and only count the number of objects in the selection and all its children. As shown below:

It will show the count of file, layer, subentity and actual model element. The last one is what you want.

4. Non-selection mode

If no selection is made before activating the plugin, it will count everything included in the model. The result would be the same as if you have selected the root element. As shown below:

This is also the mode that will be used in our next product: Object Counter Automation, where a bunch of model files are processed automatically.

Let me know if you have any questions.

Object Counter by LeZhang.net v0.6

$
0
0

This document is an incremental update of the User Manual for Object Counter by LeZhang.net v0.5. Only updates are listed. Please refer to the original document for complete manual.

LeZhang.net is proud to announce its first product: Object Counter Plugin for Autodesk Navisworks 2013.

0. General information 

No updates in this section.

1. Installation 

Update: If you already have a dll file with the same name in the specified location, replace the old one with the new one.

2. Before activating the plugin 

No updates in this section.

3. Selection mode 

Update: The resulting message now only shows the count of the actual model objects. The count of the other supporting objects are no longer shown.

4. Non-selection mode

New function: The object count of each first-level children of the root item (the layers in current project) are recorded in an Excel file in the specified folder (C:\turner\ in current project). The output file name will be LeZhangPlugin-20120729200740.xls, in which the suffix is a time stamp in the format of YYYYMMDDHHMMSS (year-month-day-hour-minute-second). A new output file will be generated for each activation of the Plugin in non-selection model. Usually the newest one will appear as the one at the bottom of the file list in Windows Explorer. The older ones can either be deleted or archived for future reference. Refer the following picture:

In the file, there will be two columns used. The first column records the name of the layers, the second column records the object count of corresponding layer, as shown below. The total number of records will be equal to the number of first-level children of the root item in the current model file.

Update: The resulting message now only shows the count of the actual model objects. The count of the other supporting objects are no longer shown.

Any comments are welcome!


Object Counter by LeZhang.net v0.7

$
0
0

This document is an incremental update of the User Manual for Object Counter by LeZhang.net v0.6. Only updates are listed. Please refer to the original document for complete manual.

LeZhang.net is proud to announce its first product: Object Counter Plugin for Autodesk Navisworks 2013.

0. General information

No updates in this section.

1. Installation

No updates in this section.

2. Before activating the plugin

No updates in this section.

3. Selection mode

No updates in this section.

4. Non-selection mode

Update: The output Excel file is now stored in a different folder from the source model files. The output folder is now C:\turner\output. You may need to manually create this folder before activating the plugin.

5. Automation mode

New function: An automation mode is added in this version, which will trigger the LeZhangPlugin automatically on each model file stored in a folder, and output the information into a single Excel file.

To use:

  1. Create a “C:\turner” folder.
  2. In this folder, create a folder named “output”. The resulting folder structure should look like the following pic.
  3. Copy all the model files to “C:\turner” folder.
  4. Double-click LeZhangAutomation.exe (whose location in the computer should NOT be relevant). Message should be shown on screen on each file being processed as well as a final message showing process completion.
  5. The output file, named LeZhangPlugin.xls (without the time stamp suffix), is placed in the folder “C:\turner\output”, which you should have created manually in step 2. You may want to manually backup the content of this file for your record, because each activation of the automation mode will erase all the previous stored information in this file.
  6. When a new batch of model files need to be processed, please clear the model files in “C:\turner” folder (but keep the output subfolder intact), and close the LeZhangPlugin.xls file (but it does not need to be deleted).  Then repeat from step 3.

Note 1:

This function uses the Navisowork Automation API, which triggers Navisworks functions (the LeZhangPlugin.dll in this case) over a bunch of model files without the user actually opening each model file.

For the first model file encountered by the plugin in the designated folder, it will record all the layer name and the number of objects in the layer in the output Excel file. For each subsequent model file, a new column is created. For each layer, the plugin will try to find a layer with same name. If a matching layer is found, the number of objects is recorded in the same line using the new column. If not, a new line is created at the end of the file in the new column.

For information purpose only, a message box is shown before and after each model file processing is started. This message box needs to be dismissed by the user for the program to continue the model file processing. (Alternatively, comment out the message box statement in the code to let the program running all the way to the end, but be aware that it may take a while so you need to be patient.)

Another similar message is the “Excel instance destroyed” message. However, it is recommended not to comment out this message. Because otherwise, for unknown reason, the Excel instance called by the plugin are not always destroyed as it should be after each model file processing. As a result, the residues of the Excel instances pile up in the memory and will make the processing of the later files becoming extremely slow. Adding this message seems to be the only way to force the Excel instances to be destroyed. Another way to force the deletion of the Excel instances is to used the debug mode in VS, as described below.

Note 2: 

If the execution of the plugin terminates prematurely, residues of the Excel and/or Navisworks programs may not be cleared. Open the Windows “Task Manager” and check the Processes to make sure you do not have any Excel or Navisworks program running. If there are any “EXCEL.exe” or “Roamer.exe” shown, manually terminate them all by highlighting the process and clicking the “End Process” button before trying anything further, as shown in the pic below.

6. To use source code in Visual Studio (VS): 

1. Download the complete .zip file and extract all the files to a folder.

2. Open VS, click menu: file-open-project/solution and browse to open the “LeZhangPlugin.sln” file.

3. There are two projects in this solution.

The “LeZhangPlugin” project is the one that generates the LeZhangPlugin.dll file, which is used as a normal Navisworks plugin that need to be triggered manually in Navisworks.

The “LeZhangAutomation” project is the one that generates the LeZhangAutomation.exe file, which is the automation plugin.

4. Both of the plugins can be triggered in debug mode, which gives the user the opportunity to watch the code being executed step by step. Please refer to this blog for details of debugging a Navisworks plugin.

5. Whenever changes are made in the code, the project need to be rebuild (menu: build-rebuild solution, or press F6) to regenerate a new dll or exe file. For the dll file, the new one need to be copied to the designated Navisworks Plugin folder to replace the old one. This can be done automatically by a post-build event in VS, which is also described in this blog. Note that you need to close Navisworks to be able to replace the dll files.

Object Counter by LeZhang.net v0.81

$
0
0

This document is an incremental update of the User Manual for Object Counter by LeZhang.net v0.7. Only updates are listed. Please refer to the original document for complete manual.

LeZhang.net is proud to announce its first product: Object Counter Plugin for Autodesk Navisworks 2013.

0. General information

No updates in this section.

1. Installation

No updates in this section.

2. Before activating the plugin

No updates in this section.

3. Selection mode

No updates in this section.

4. Non-selection mode

No updates in this section.

5. Automation mode

Update: The automation mode is updated with more user-friendly functions.

No specific project folder location is required. On activating the LeZhangAutomation.exe, user will be prompted to select a project folder. The project folder should contains a range of trade folders, which contains a range of layer folders. All the model files should be placed in specific layer folders.

All the Excel output files, one for each trade and named according to trade folder names, will be placed in a folder called “output” created in the project folder. In each Excel file, the worksheets are named according to the layer folder names. In each worksheet, each column is headered according to the model file name. The output folder will be cleared prior to each activation of the program.

Also addressed in this version is the Excel instance cannot be cleaned timely issue. The message, which forces the .net garbage collection, is removed; other information-purpose messages are shown in a command console only. The automation program now can be executed from start to end without manual intervention. User should be aware that it may take a while so you need to be patient.

NOTE: In this version, the project folder – trade folder – layer folder – model file hierarchy is strictly required for the automation mode to run correctly. If for other projects that do not have this structure, you can race the system by creating dummy structures similar to this.

6. To use source code in Visual Studio (VS): 

No updates in this section.

Object Counter by LeZhang.net v0.82

$
0
0

This document is an incremental update of the User Manual for Object Counter by LeZhang.net v0.81. Only updates are listed. Please refer to the original document for complete manual.

LeZhang.net is proud to announce its first product: Object Counter Plugin for Autodesk Navisworks 2013.

0. General information

No updates in this section.

1. Installation

No updates in this section.

2. Before activating the plugin

No updates in this section.

3. Selection mode

No updates in this section.

4. Non-selection mode

No updates in this section.

5. Automation mode

BugFix: An issue on handling strings in Excel cells are fixed.

6. To use source code in Visual Studio (VS): 

No updates in this section.

How to Debug/Run Navisworks 2013 API Programs

$
0
0

Of course you can just type in code, click build, go to Windows Explorer, copy your dll files to Plugins folder, start Navisworks and click the buttons on the Add-in tab. But what’s fun with that? Besides, that will not give you useful real-time info for debugging. Here in this blog I present you some simple configurations that can make your API life a little bit easier.

Use Post-build Event

Using post-build event to copy the generated dll file (and pdb file for debugging) to the destination folder in Plugins.

1. Right-click the project, choose Properties.

2. Click the Build Events tab on the left, copy the following to the “Post-build event command line”:

xcopy /Y “$(TargetDir)*.*” “C:\Program Files\Autodesk\Navisworks Manage 2013\Plugins\$(TargetName)\”

The “xcopy” is a Windows command for copying stuff. The “/Y” is a switch that tells the system to overwrite anything in the destination folder without letting the user confirm.

The $(Xyz) are macros that will be replaced by actually values. For example, on my machine it will be replaced as “xcopy /Y “D:\zhangle\BIM\Navisworks\API\myVsProjects\LeZhangPlugin\LeZhangPlugin\bin\Debug\*.*” “C:\Program Files\Autodesk\Navisworks Manage 2013\Plugins\LeZhangPlugin\””. Using the macros are good for code portability and ease to read and understand. If your Navisworks is not installed at the default folder, you need to adjust the destination folder accordingly. If you want to know all the macros, you may want to click the “Edit Post-build …” button, and click the “Macros” button.

Configure Start Action

If you just click the “Start” button in VS just like you are doing for any stand-alone application, VS will show you the following error message. Indeed, what we have created is a “Class Library” project, which generates a dll file. We need somehow trigger Navisworks first and run our program in it.

navi-1

1. Right-click your project name in the Solution Explorer, and click Properties, which is at the bottom of the pop-up menu.

2. Click Debug tab on the left; in Start Action group, choose “Start external program”. Click the browse button to go to Navisworks installation folder, and choose “Roamer.exe”. (I have no idea about the name, but trust me.) Save and close the project properties page.

3. In the code you want to run and debug, find an interesting statement and click the left side border of the code window as shown below. A red dot should be added as a “break point”, which means when running, the program will stop BEFORE running this statement to give you a chance to look into the status of the program.

navi-2

4. Click the Start button in VS again. Navisworks should start automatically.

5. Do something that will trigger your break point code. You will notice that your program will stop at the statement, while you can check the program status and use the different debug tools.

navi-3

Keep these in mind if a strange bug appears

Check which .NET framework you are using. Right-click your project – Properties. Make sure the “Target framework” is selected as .NET Framework 4. Since VS2012 uses .NET 4.5 as the default framework, some strange bugs may be as a result of the compatibility between different .NET framework versions. In one of my VS2012 project using Autodesk.Navisworks.Automation.dll, the assembly can be added into the reference without errors, but when running it throws “FileNotFoundException” on the Automation file. Changing the framework back to 4 then works fines.

NOTE: This is a re-post due to broken links on website transfer. The original link to this page is: http://lezhang.net/2012/06/29/how-to-debugrun-navi​sworks-2013-api-programs/

Viewing all 12 articles
Browse latest View live