How to iterate through all the viewports that are present?

viewport

(Alex) #1

Hi,

So I want to iterate through all the viewports and get their information. But, with the current code I have, I can only get the information of the last viewport that I was working on.

How do I modify this to ensure that all the viewports are ensured?

const unsigned int docSN = context.m_rhino_doc_sn;
CRhinoViewportIterator viewPortItr(docSN, rhinoDocument.ActiveRhinoViewSerialNumber());
CRhinoViewport* currentViewPort = nullptr;
for (currentViewPort = viewPortItr.First(); nullptr != currentViewPort; currentViewPort = viewPortItr.Next())
{
	// TO DO

}

(Dale Fugier) #2

Hi @alexian007,

Use CRhinoDoc::GetViewList.

The SDK samples on GitHub has samples of it’s usage.

– Dale


(Alex) #3

Hi @dale,
Thank you, I did end up using the GetViewList and it is giving me my expected results.

But, there is a specific problem that I’m facing now.

You see, when I get the viewports by the following, what happens is when a namedview is also active in the document, then it just gives me the namedview+3 default viewports, what I need is this : namedView + all 4 default viewports.

How should I proceed with that, is there any option to let the GetViewList only traverse through the default viewports(active/inactive) and ignore the namedview?

My current code looks like this:

// Get all the viewports

::RhinoApp().Print("\nProcessing views!");

CRhinoView* currentRhinoView = nullptr;

for (int vpc = 0; vpc < viewPortsCount; vpc++)
{
	currentRhinoView = allViewPorts[vpc];

	std::string currentVpName(GetNameFromONwStr(currentRhinoView->Viewport().Name()));

	::RhinoApp().Print("\nThe view name is %s\n", currentVpName);

	std::string currentVpId(GetUUIDFromONUUID(currentRhinoView->Viewport().ViewportId()));

	// DO STUFF
}

::RhinoApp().Print("\nDone Processing views!");



// Iterate through named views:

if (namedViewsCount > 0)
{
	const ON_wString namedViewName;

	while (nullptr != (view_3dm = rhinoDocument.Properties().NamedView(namedViewIndex)))
	{
		//Get name for the NamedView:
		const char* currentNamedViewName = GetNameFromONwStr(view_3dm->m_name);
		::RhinoApp().Print("\n The named view's name is %ls!", currentNamedViewName);

		// Get named view ID:
		const char* currentNViewUUID = GetUUIDFromONUUID(view_3dm->m_named_view_id);

		// DO STUFF:



		objectIndex++;

	}
}

(Dale Fugier) #4

Named views are never active. They are simply snapshots of a view projection that are saved off, in the document, with some user-defined name. Often the names coorespond with those of standard views.

Named views can be restored to any view at anytime by the user. If you are not familiar with the feature, then you may want to try it out.

I’m not sure what this means - perhaps this helps.

CRhinoCommand::result CCommandTest::RunCommand(const CRhinoCommandContext& context)
{
  // Process standard views
  ON_SimpleArray<CRhinoView*> standard_views;
  const int standard_view_count = context.m_doc.GetViewList(standard_views, true, false);
  RhinoApp().Print(L"Standard view count = (%d)\n", standard_view_count);
  for (int i = 0; i < standard_view_count; i++)
  {
    CRhinoView* view = standard_views[i];
    if (nullptr != view)
    {
      RhinoApp().Print(L"  Standard view(%d) = %s\n",
        i, static_cast<const wchar_t*>(view->ActiveViewport().Name())
      );
    }
  }

  // Process named views. Note, not all documents contain named views.
  ON_ClassArray<ON_wString> named_views;
  int named_view_count = 0;
  const ON_3dmView* view_3dm = nullptr;
  while (nullptr != (view_3dm = context.m_doc.Properties().NamedView(named_view_count)))
  {
    named_views.Append(view_3dm->m_name);
    named_view_count++;
  }

  RhinoApp().Print(L"Named view count = (%d)\n", named_view_count);
  for (int i = 0; i < named_view_count; i++)
  {
    RhinoApp().Print(L"  Named view(%d) = %s\n",
      i, static_cast<const wchar_t*>(named_views[i])
    );
  }

  return CRhinoCommand::success;
}

– Dale