retrieve the camera location in model view?

G'day.

I'm looking to retrieve the camera (maybe wrong terminology?) location as seen in the model editor.

Example:  User is creating a model, yadda yadda yadda, they zoom out a bit, pan a bit, rotate a bit, they like the view they have of the model w.r.t. the screen, and I need to retrieve the location of the "camera" as it views the model.  So in the image below, where are my eyeballs located as I look at this model, and how do I retrieve that location info thru the API?

I gather that SW is able to do this since I can save a model and when I re-open it, I start from the same viewing position.  I've seen a lot about cameras in the forums, but they appear (to me at least) that they are talking to cameras added to the model by the user.

My issue may be one of terminology, so any assistance even at that level would be greatly appreciated.  If I can even just get to the API object which speaks to the location of this view I believe I can take myself the rest of the way home.

SolidworksApi macros
Answers 4
MB
MB 2018-02-08 Best Answer

What are you trying to accomplish with the view? If you simply want to go back to it at a later time, then you can save the view as a named view and go back to it later.

MC
MC 2018-02-08

Matt, thanks for the reply, but unfortunately not as simple as that.

I'm using a macro to export to a third-party visualization engine (stl, simple enough) which allows me to set the camera location on startup.  The default location is at the origin which often puts it inside of my model.  I'd like to retrieve the camera location so that I can save it to a txt file to be loaded by the viz engine.

You bring up an interesting approach... the user can create a named view, then I'm sure I can get info on that named view, but that's an extra step I'd like to keep out of the process.  We do hundreds (and would happily do thousands if we can automate) of these processes, so every minute of design time adds up.

MB
MB 2018-02-08

While I have never tried this, you might be able to use the IModelView.GetEyePoint Method. It might be worth a shot.

2017 SOLIDWORKS API Help - GetEyePoint Method (IModelView)

ST
ST 2018-02-08

I feel that the information you require will be contained in IModelView::Orientation3 and IModelView::Translation3

I think you need to create a MathPoint (0, 0, 1)

Multiply that by the MathTransform returned by Orientation3 (possibly its inverse actually)

Then translate the resulting point by the vector returned by Translation3 (again, most likely the inverse vector - i.e. with X, Y and Z components multiplied by -1)

I think the eye point will be the final point.