Create NamedView C++

I am writing an importer, that takes cameras/views from another software/file format and re-creates them in rhino as named views. I have tried several avenues but cannot get the AddNamedView command to return anything other than -1

Any guidance on this would be greatly appreciated. Heres a code snippet:

ON_3dmView view = ON_3dmView();
view.m_name = ON_wString(cameraName);
view.m_vp.CameraDirection().Set(direction.x, direction.y, direction.z);
view.m_vp.CameraX().Set(x.x, x.y, x.z);
view.m_vp.CameraUp().Set(up.x, up.y, up.z);
view.m_vp.CameraLocation().Set(location.x, location.y, location.z);
CRhinoDocProperties& props = aDoc->Properties();
int result = props.AddNamedView(view);

feels like something @dale would know how to do :slight_smile:

Hi @_richard,

CRhinoDocProperties::AddNamedView returns -1 if the ON_3dmView argument’ is invalid.

if (named_view.IsValid())
  return -1;

You can get useful information from IsValid, by passing a reference to an ON_TextLog. For example:

CRhinoCommand::result CCommandTest::RunCommand(const CRhinoCommandContext& context)
  ON_3dmView named_view;
  // TODO: fill in named view

  ON_wString str;
  ON_TextLog log(str);
  bool rc = named_view.IsValid(&log);
  if (!rc)
    RhinoApp().Print(L"%ls\n", static_cast<const wchar_t*>(str));

  return CRhinoCommand::success;

Does this help?

– Dale

1 Like

Thank you @dale! I wasn’t aware of this logging method, very helpful. It appears the

viewport port extents settings

are invalid. I’ll keep digging…

SetScreenPort() was the command I was missing on my viewports