ViewportInfo from Viewport

Hello,

This is my first question here, hope not an unsolvable one:)

I would like to attach user Data to views. I can not attach data directly to Viewport objects, but it is possible to add user data to ViewportInfo objects.

Is it possible to get the connected ViewportInfo object from Viewport object (or View object) somehow? These should have a connection I think… or maybe not?

Márton

Hi @marton.parlagh,

I’ve never tried storing user data on a Rhino viewport - it may not be possible.

Rather than trying to store user data on a viewport, you might consider just keeping a table viewport user data and storing it as document data. Viewports have unique ids (System.Guid), so you can use this as the field to key off of.

– Dale

Dale

I know it’s possible - we do it in Bongo. We store the user data on ON_Viewport - which is the CRhinoViewport::m_vp member.

  • Andy

If this is the case, then something like this should work. Let me know if you find otherwise.

var vp = new ViewportInfo(view.ActiveViewport);
vp.UserData.Add(...);
view.ActiveViewport.SetViewProjection(vp, true);

– Dale

Thank you!

It seems to work actually:)

These parameters are not undo-able right? I can use undo/Redo mechanism with my user data in case of geometries, but it seems not for view user data.

Márton

Hi @marton.parlagh,

Viewport changes don’t play in the document undo/redo system. Rather, each view maintain’s it’s own undo stack. Thus, you will want to use UndoView and RedoView.

– Dale

Oh, and it works automatically. Super:)
Thanks!

Márton