11/05/2012

Check saved viewpoints of Navisworks model on-site –Part I

Cloud & mobile (C&M) is an exciting technology. My colleagues have created many excellent tutorials on various aspects that can be used to integrate Autodesk products with C&M. I believe some Navisworks developers are thinking the applications to connect Navisworks with C&M. Recently, I started to try my hands on it and created a first demo. In addition, my colleague Simon Bee in the engineer team has delivered another demo on the DevCamp in June this year. I will post them in a series as a start for the practice of Navisworks.

In the office, we open the Navisworks model, switch to each saved viewpoints, export to the image and upload it to the cloud. When we are working on-site, we can use mobile to connect with the cloud, download the images and view the viewpoints that we are interested in. Actually, you can apply this demo with other Autodesk products such as Inventor, Revit, uploading the latest list of viewpoints and check them anywhere with the mobile. I hope this tiny demo would be helpful for you to get started with Simon’s demo : ) – that is more interesting!

In this practice, we use Amazon cloud and the services S3. At the mobile end, it is Android. Please make sure you have the following environments:

We will not introduce in detail on how to setup these environments. If you are new to cloud and mobile technology, I would suggest you get started with the tutorials on Android Development and Amazon Cloud .

Creating Navisworks .NET plug-in

First we need to create a .NET plug-in of Navisworks, adding a button in Add-Ins tab to execute our command. Simply, create a class from AddInPlugin. Add the basic references of Navisworks API. The references are required:

Navisworks 2013 has exposed the .NET API for viewpoints and saved viewpoints. These are some posts on the relevant topic on AEC blog. However, we still need to use COM interop to access the ability of exporting image. In this demo, we iterate the collection of each save viewpoint, export the current viewpoint to the image.

After that, the image will be uploaded to the cloud. We will firstly check if a bucket named “nw_demo_test” exists. If not, create one. To category the saved viewpoints from different files, we create a folder for each model in the bucket.

Of course, we could use an Automation application (calling the plug-in) to do all the jobs above, when we are sleeping.

Following is the source code. It self-explains the functionalities.

// namespaces of Navisworks

using Autodesk.Navisworks.Api;

using Autodesk.Navisworks.Api.Plugins;

using Autodesk.Navisworks.Api.DocumentParts;

usingComBridge = Autodesk.Navisworks.Api.ComApi.ComApiBridge;

using ComApi = Autodesk.Navisworks.Api.Interop.ComApi;

//namespaces of Amazon cloud

using Amazon.S3;

using Amazon.S3.Model;

[PluginAttribute("NW_API_Cloud_Mobile",

//4 character Developer ID or GUID

"ADSK",

//The tooltip for the item in the ribbon

ToolTip = "demo of Navisworks and C & M",

//Display name for the Plugin in the Ribbon

DisplayName = "Autodesk C&M")]

publicclassClass1 : AddInPlugin

{

// execute the plug-in command

publicoverrideint Execute(paramsstring[] parameters)

{

// export the saved viewpoints to images

dumpSavedVP();

// upload images to cloud

uploadToCloud();

return 0;

}

#region "produce images"

//locations to export the images

staticstring _snapshos_location = "c:\\temp\\";

// array of names of the saved viewpoints

List<string> _fileArray = newList<string>();

// export the saved viewpoints to images

privatevoid dumpSavedVP()

{

// get the active document

Document oDoc = Autodesk.Navisworks.Api.Application.ActiveDocument;

// get the state of COM

ComApi.InwOpState10 oState =

ComBridge.State;

// get the IO plugin for image

ComApi.InwOaPropertyVec options =

oState.GetIOPluginOptions("lcodpimage");

// configure the option "export.image.format"

//to export png

foreach (ComApi.InwOaProperty opt in

options.Properties())

{

if (opt.name == "export.image.format")

opt.value = "lcodpexpng";

}

// swtich to the saved viewpoint

foreach (SavedViewpoint oSVP in

oDoc.SavedViewpoints.ToSavedItemCollection())

{

string svpName = oSVP.DisplayName;

// set the current viewpointoDoc.SavedViewpoints.CurrentSavedViewpoint = oSVP;

Comments

Cloud & mobile (C&M) is an exciting technology. My colleagues have created many excellent tutorials on various aspects that can be used to integrate Autodesk products with C&M. I believe some Navisworks developers are thinking the applications to connect Navisworks with C&M. Recently, I started to try my hands on it and created a first demo. In addition, my colleague Simon Bee in the engineer team has delivered another demo on the DevCamp in June this year. I will post them in a series as a start for the practice of Navisworks.

In the office, we open the Navisworks model, switch to each saved viewpoints, export to the image and upload it to the cloud. When we are working on-site, we can use mobile to connect with the cloud, download the images and view the viewpoints that we are interested in. Actually, you can apply this demo with other Autodesk products such as Inventor, Revit, uploading the latest list of viewpoints and check them anywhere with the mobile. I hope this tiny demo would be helpful for you to get started with Simon’s demo : ) – that is more interesting!

In this practice, we use Amazon cloud and the services S3. At the mobile end, it is Android. Please make sure you have the following environments:

We will not introduce in detail on how to setup these environments. If you are new to cloud and mobile technology, I would suggest you get started with the tutorials on Android Development and Amazon Cloud .

Creating Navisworks .NET plug-in

First we need to create a .NET plug-in of Navisworks, adding a button in Add-Ins tab to execute our command. Simply, create a class from AddInPlugin. Add the basic references of Navisworks API. The references are required:

Navisworks 2013 has exposed the .NET API for viewpoints and saved viewpoints. These are some posts on the relevant topic on AEC blog. However, we still need to use COM interop to access the ability of exporting image. In this demo, we iterate the collection of each save viewpoint, export the current viewpoint to the image.

After that, the image will be uploaded to the cloud. We will firstly check if a bucket named “nw_demo_test” exists. If not, create one. To category the saved viewpoints from different files, we create a folder for each model in the bucket.

Of course, we could use an Automation application (calling the plug-in) to do all the jobs above, when we are sleeping.

Following is the source code. It self-explains the functionalities.

// namespaces of Navisworks

using Autodesk.Navisworks.Api;

using Autodesk.Navisworks.Api.Plugins;

using Autodesk.Navisworks.Api.DocumentParts;

usingComBridge = Autodesk.Navisworks.Api.ComApi.ComApiBridge;

using ComApi = Autodesk.Navisworks.Api.Interop.ComApi;

//namespaces of Amazon cloud

using Amazon.S3;

using Amazon.S3.Model;

[PluginAttribute("NW_API_Cloud_Mobile",

//4 character Developer ID or GUID

"ADSK",

//The tooltip for the item in the ribbon

ToolTip = "demo of Navisworks and C & M",

//Display name for the Plugin in the Ribbon

DisplayName = "Autodesk C&M")]

publicclassClass1 : AddInPlugin

{

// execute the plug-in command

publicoverrideint Execute(paramsstring[] parameters)

{

// export the saved viewpoints to images

dumpSavedVP();

// upload images to cloud

uploadToCloud();

return 0;

}

#region "produce images"

//locations to export the images

staticstring _snapshos_location = "c:\\temp\\";

// array of names of the saved viewpoints

List<string> _fileArray = newList<string>();

// export the saved viewpoints to images

privatevoid dumpSavedVP()

{

// get the active document

Document oDoc = Autodesk.Navisworks.Api.Application.ActiveDocument;

// get the state of COM

ComApi.InwOpState10 oState =

ComBridge.State;

// get the IO plugin for image

ComApi.InwOaPropertyVec options =

oState.GetIOPluginOptions("lcodpimage");

// configure the option "export.image.format"

//to export png

foreach (ComApi.InwOaProperty opt in

options.Properties())

{

if (opt.name == "export.image.format")

opt.value = "lcodpexpng";

}

// swtich to the saved viewpoint

foreach (SavedViewpoint oSVP in

oDoc.SavedViewpoints.ToSavedItemCollection())

{

string svpName = oSVP.DisplayName;

// set the current viewpointoDoc.SavedViewpoints.CurrentSavedViewpoint = oSVP;