I would like to extract the viewpoint data (XYZ positions and rotations) from the graphics window in RS. I can see that the XYZ positions are given next to the “controller status” bar. It seems these values are only updated by clicking in the active area of the graphics window.
Is there another way of extracting viewpoint data in RS?
The values in the status bar is the the position of the white marker, which has nothing to do the viewpoint.
You could write a simple addin to retrieve the viewpoint, using the LookAt and LookFrom properties of the GraphicControl object. This isn’t supported in VSTA, so you would have to use Visual Studio.
That’s definitely possible.
The project should be a C# or VB.Net Class Library. The AddinMain() method is the way RS identifies and activates an addin so it must be present. (Also see this post.)
Something like this should do the trick:
GraphicControl gc = GraphicControl.ActiveGraphicControl;
gc.LookFrom = new Vector3(x, y, z);
// Give graphic control time to redraw
Application.DoEvents();
Bitmap bmp = gc.ScreenShot();
Thanks for the advice, it seemed to work ok but l have some more queries.
I would like to view an object from the target points perspective i.e. the viewpoint should be at the same position and rotation as the target point, so…
How do the vector3 arguments (x,y,z) relate to the target point arguments (x,y,z,rot_x,rot_y,rot_z)?
Does the “camera” class offer any additional functionality for controlling the viewpoint?
The x/y/z components of an object’s global matrix corresponds to the x/y/z axis of the object’s local coordinate system. So to look along the z axis of a target you could do this:
That last piece of code worked ok and I can now SET the LookAt property.
I am now trying to GET the LookAt property from the ActiveGraphicControl object.
I would like to manually select a view in the RS graphics window (using mouse control) and display the vector3 values for that viewpoint in a simple message box.
The problem is that when I move to a new viewpoint in the RS graphics window, the vector3 values are not updated accordingly. I have tried to update the graphic control object but it has made no difference. I have also tried using both GraphicControl and Camera classes but I get the same result.
The code using the GraphicControl object is given below.
When using the LookAt property, the ActiveGraphicControl is updated when selecting the pre-defined viewpoints on the view toolbar. and not by panning and tilting with mouse.
However using the LookFrom property, the ActiveGraphicControl is also updated when selecting the view by panning and tilting with mouse.
LookAt will not change when you rotate or zoom the view, because LookAt is the point around which the view is rotated/zoomed!
It should change when you pan the view (CTRL + left mouse button) though, are you sure that’s not the case?
Sorry for rekindling an old thread, but I was wondering if there is any way to lock or set the ROLL of the camera? Using LookAt and LookFrom can change the yaw and pitch of the camera, but they are unable to define the roll. It seems that the camera automatically attempts to be as “straight up” as possible (0 degrees along what would be perceived as its Y-axis) but I would really like to be able to manipulate it myself. Any ideas?
You are right that in the GUI and the GraphicControl API there is no way to set the roll of the camera.
However, if you connect a Camera object to the GraphicControl you get some additional possibilities. One of these is to set the UpDirection which corresponds to the ‘Y-axis’ of the view. Another is to lock the view so the user cannot change zoom/pan/rotation.