Welcome to the sixth tutorial of
Navisworks® API series, this post will be covered how to manipulate Viewpoint’s Camera, we’ll create an add-ins that move and rotate the position of the camera and finally going to save the current Viewpoint.
And this task is Lab-10 exercise from Navisworks® SDK.(figure 1.0)
So, first things first, 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
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)
We will start how to move the camera of the current viewpoint first. To do so, we collect the current position of the camera in 3D space by using its Position property,
vpoint.Position . Next, create a new position (a
Point3D) based on the current position X, Y, Z values. Point3D is an object represents a position in 3D space. And set new position value to the current viewpoint position and update the current viewpoint of the document. (figure 1.2)
Below is a short demo for the camera position movement. We just moved increment of +10 to “X” direction and you might notice that ViewCube doesn’t change at all. But when we rotate, it will follows the rotation.
For the camera rotation, viewpoint object has a property called, Rotation which returns rotation of camera from base orientation. From the rotation object, we collect the result object ,
AxisAndAngleResult, by using
ToAxisAndAngle method which holds the values of the current rotational axis and angle. (figure 1.3)
To create a new Rotation, (figure 1.4) we can construct a new Rotation3D object (Quaternion) with a UnitVector3D (Vector with unit length and represents a direction in 3D space) and a double (angle in radians). As you can see in (figure 1.5) , we created new angle value : 10 degree in radians and a new rotational axis : UnitVector3D(0,0,1) to rotate Z axis, as two arguments for Rotation3D constructor.
To increment rotation values, we have to write a method to multiply the current rotation and new rotation values (figure 1.6) . ( Multiply method is from Navisworks SDK Lab10 sample which is the multiplication of quaternion’s components A,B,C,D. )
Set the current viewpoint Rotation value and update the current viewpoint of the document. Finally, saved the viewpoint with a name and add to document’s savedviewpoints. (figure 1.7)
That’s all for this Viewpoint Part-1 tutorial, you can find the complete source code from here, Cheers!
Founder and Developer @twentytwo.space