Welcome to the ninth tutorial of Navisworks® API series, this post is to cover how to get and set Viewpoint’s camera via JSON AutodeskCommonCamera object and, to zoom the Viewpoint’s camera to the selected ModelItem(s). As usual, we’re going to write an add-ins for this.

Set Camera via JSON AutodeskCommonCamera
Zoom Selection

Setting up Navisworks® Add-Ins project in the visual studio, you can follow Creating Navisworks Add-Ins tutorial to set up the project. When you are ready, in the Execute method creates two variables, doc and vpoint to store Document and Viewpoint respectively. To collect Viewpoint, doc.CurrentViewpoint property returns DocumentCurrentViewpoint object and it includes a method to get a copy of the current Viewpoint object, CreateCopy() method. (figure 1.1)

figure 1.1 – Get Viewpoint

Viewpoint includes a method to collect its properties in terms of an JSON AutodeskCommonCamera object (it is actually a json file), we can write and export this return json data of viewpoint to a text file and save it on desktop or anywhere you like.

GetCamera Method

Copy these json data and open it in one of the JSON Formatter/Validator website, here is one. And you will see data structure something like below image, and save it as a JSON format file.

JSON AutodeskCommonCamera object

You can modify and play with these numbers from our json file. After modified these values, we will uses this JSON AutodeskCommonCamera object to set Viewpoint value. First have to read these json data as a string and provide the string value to SetCamera method as a parameter (figure 1.2).

figure 1.2 – Set Viewpoint

The last part is to zoom selected Modelitems to the center of the Viewpoint. Viewpoint contains a method called “ZoomBox” which requires a BoundingBox parameter. To collect the BoundingBox of the selected Modelitems, just simply call BoundingBox method with boolean parameter value (true value is not to include hidden items).

That’s all for this tutorial, you can get the complete source code from here, Cheers!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.