Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

developer:sdksamples:activeviewport [2015/09/14] (current)
Line 1: Line 1:
 +====== Determining the Active Viewport ======
 +> **Developer:​** //​[[developer:​cplusplusplugins|C++]]//​
 +> **Summary:​** //​Demonstrates how to determine the active viewport.//
  
 +===== Question =====
 +I am using the Rhino C++ SDK and I am trying to determine if the current active ​
 +view is a detail or a standard view. I am having some trouble differentiating between an active page layout and an active detail in a page layout. Any help would be appreciated.
 +
 +===== Answer =====
 +Standard Rhino views are represented by the **CRhinoView** class. Layout views are represented by the **CRhinoPageView** class. This class is derived from **CRhinoView**. A **CRhinoPageView** object maintains an array of **CRhinoDetailViewObject** objects - one for each detail in the layout.
 +
 +To determine whether a layout or one if it's details is active, get the UUID of the layout'​s active detail object. If the returned UUID is nil, then the layout itself is active. Otherwise, the detail object that has the returned UUID is active.
 +
 +===== Example =====
 +
 +<code c++>
 +CRhinoCommand::​result CCommandTest::​RunCommand( const CRhinoCommandContext&​ context )
 +{
 +  CRhinoView* view = RhinoApp().ActiveView();​
 +  if( 0 == view )
 +    return CRhinoCommand::​failure;​
 +
 +  if( view->​IsKindOf(RUNTIME_CLASS(CRhinoPageView)) )
 +  {
 +    CRhinoPageView* page_view = static_cast<​CRhinoPageView*>​(view);​
 +    if( page_view )
 +    {
 +      ON_wString layout_name = page_view->​MainViewport().Name();​
 +
 +      ON_UUID active_detail_uuid = page_view->​ActiveDetailObject();​
 +      if( ON_UuidIsNotNil(active_detail_uuid) )
 +      {
 +        ON_wString detail_name = page_view->​ActiveViewport().Name();​
 +        RhinoApp().Print( L"The detail \"​%s\"​ on layout \"​%s\"​ is active.\n",​ detail_name,​ layout_name );
 +      }
 +      else
 +      {
 +        RhinoApp().Print( L"The layout \"​%s\"​ is active.\n",​ layout_name );
 +      }
 +    }
 +  }
 +  else
 +  {
 +    ON_wString viewport_name = view->​ActiveViewport().Name();​
 +    RhinoApp().Print( L"The viewport \"​%s\"​ is active.\n",​ viewport_name );
 +  }
 +
 +  return CRhinoCommand::​success;​
 +}
 +</​code>​
 +
 +\\
 +
 +{{tag>​Developer cplusplus}}
developer/sdksamples/activeviewport.txt ยท Last modified: 2015/09/14 (external edit)