Site Tools


Differences

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

Link to this comparison view

developer:sdksamples:layerobjects [2015/09/14] (current)
Line 1: Line 1:
 +====== Getting Layer Objects ======
 +> **Developer:​** //​[[developer:​cplusplusplugins|C++]]//​
 +> **Summary:​** //​Demonstrates how to get all of the objects on a layer.//
  
 +===== Question =====
 +Is there a way to get all the objects on a specific layer?
 +
 +===== Answer =====
 +You can get all of the objects on a specified layer in two ways:
 +
 +  - Use **CRhinoDoc::​LookupObject**.
 +  - Use a **CRhinoObjectIterator**.
 +
 +The **CRhinoDoc::​LookupObject** is somewhat easier. So, we will demonstrate this in the following example.
 +
 +==== C++ ====
 +
 +<code c++>
 +CRhinoCommand::​result CCommandTest::​RunCommand( const CRhinoCommandContext&​ context )
 +{
 +  ON_wString layer_name = L"​Default";​ // some layer name to search for
 +  int layer_index = context.m_doc.m_layer_table.FindLayer( layer_name );
 +  if( layer_index >= 0 )
 +  {
 +    const CRhinoLayer&​ layer = context.m_doc.m_layer_table[layer_index];​
 +    ON_SimpleArray<​CRhinoObject*>​ objects;
 +    int object_count = context.m_doc.LookupObject( layer, objects );
 +    if( object_count > 0 )
 +    {
 +      const CRhinoObject* object = 0;
 +      int i;
 +      RhinoApp().Print( L"%s layer objects:​\n",​ layer_name );
 +
 +      for( i = 0; i < object_count;​ i++ )
 +      {
 +        object = objects[ i ];
 +        if( object )
 +          RhinoApp().Print( L" ​ %s\n", object->​ShortDescription(false) );
 +      }
 +    }
 +  }
 +
 +  return CRhinoCommand::​success;​
 +}
 +</​code>​
 +
 +
 +\\
 +
 +{{tag>​Developer cplusplus}}
developer/sdksamples/layerobjects.txt ยท Last modified: 2015/09/14 (external edit)