Community
Navisworks API
Welcome to Autodesk’s Navisworks API Forums. Share your knowledge, ask questions, and explore popular Navisworks API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Recreate Saved Views from Camera params

3 REPLIES 3
Reply
Message 1 of 4
excelthoughts
657 Views, 3 Replies

Recreate Saved Views from Camera params

I am saving the Camera params from a Saved View into a database.

 

var oView = _state.CurrentView.ViewPoint as nw.InwNvViewPoint2;
                var camera = oView.Camera;

                var scv = new SavedCameraView();
                scv.Name = viewName;
                scv.AspectRatio = camera.AspectRatio;
                scv.HeightField = camera.HeightField;
                scv.PostionData1 = camera.Position.data1;
                scv.PostionData2 = camera.Position.data2;
                scv.PostionData3 = camera.Position.data3;
                scv.Projection = (int)camera.Projection;
                scv.RotationAngle = camera.Rotation.angle;

 I want to be able to recreate this SavedView on reentering the model but reconstructing it from the saved camera params.

Here is my attempt.

 

InwSavedViewsColl savedViews = _state.SavedViews();
                            InwOpView sv = (InwOpView)_state.ObjectFactory(nwEObjectType.eObjectType_nwOpView, null, null);
                            sv.name = scv.Name;
                            //sv.anonview = (InwOpAnonView)_state.CurrentView;
                            
                            var camera = (InwNvCamera)_state.ObjectFactory(nwEObjectType.eObjectType_nwNvCamera, null, null);
                            var viewPoint = (InwNvViewPoint2)_state.ObjectFactory(nwEObjectType.eObjectType_nwNvViewPoint, null, null);
                            var axis = (InwLUnitVec3f)_state.ObjectFactory(nwEObjectType.eObjectType_nwLUnitVec3f, null, null);
                            //axis.data1 = 0;
                            //axis.data2 = 0;
                            //axis.data3 = 0;

                            camera.AspectRatio = scv.AspectRatio.Value;
                            camera.HeightField = scv.HeightField.Value;
                            camera.Position.data1 = scv.PostionData1.Value;
                            camera.Position.data2 = scv.PostionData2.Value;
                            camera.Position.data3 = scv.PostionData3.Value;
                            camera.Projection = (nwEProjection) scv.Projection;

                            camera.Rotation = (InwLRotation3f)_state.ObjectFactory(nwEObjectType.eObjectType_nwLRotation3f, null, null);
                            camera.Rotation.SetValue(axis, scv.RotationAngle.Value);
                            
                            viewPoint.Camera = camera;
                            sv.anonview.ViewPoint = viewPoint;
                            savedViews.Add(sv);

The issue is that Camera.Rotation.angle is not set. You cannot set it directly as it is read only.

If I run the code as is, the reconstructed SavedView has Rotation angle =0, and AspectRatio and HeightField are incorrect.

I assume I need to do some Vector maths here instead of what I am doing?

 

How can achieve this step?

3 REPLIES 3
Message 2 of 4

Hi,

 

have you tried InwLRotation3f.SetValue? It is to set axis and angle.

 

 

Message 3 of 4

That would be this line in my code..

 

camera.Rotation.SetValue(axis, scv.RotationAngle.Value);
Message 4 of 4
KempCE
in reply to: excelthoughts

I believe the Error is that you do not set the  Axis

 

var axis = (InwLUnitVec3f)_state.ObjectFactory(nwEObjectType.eObjectType_nwLUnitVec3f, null, null); 
axis.SetValue(10.00, 10.00, 10.00);

 

 

I hope this Helps....

 

Regards,

Colin 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


Autodesk Design & Make Report