Site Tools


Differences

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

Link to this comparison view

developer:sdksamples:layerfullpath [2015/09/14] (current)
Line 1: Line 1:
 +======Print a Layer'​s Full Path======
 +> **Developer:​** //​[[developer:​cplusplusplugins|C++]]//​
 +> **Summary:​** //​Demonstrates now to obtain a layer'​s full path.//
  
 +=====Question=====
 +I could like to print a layer'​s full path. That is, if a layer "​MyLayer"​ is nested, I would like to print out the nesting like this:
 +
 +<​code>​
 +"​GreatGrandParent / GrandParent / Parent / MyLayer"​
 +</​code>​
 +
 +Is there any way of getting this from the SDK?
 +
 +=====Answer=====
 +
 +See the function below:
 +
 +<code c++>
 +static ON_wString RhinoFullLayerPath( CRhinoDoc&​ doc, const CRhinoLayer&​ layer )
 +{
 +  ON_wString layer_path;
 +
 +  CRhinoLayerNode layer_node;
 +  layer_node.Create(layer.m_layer_index,​ 2, 0, true );
 +  if( layer_node.m_parent_count > 0 )
 +  {
 +    int i, layer_index = -1;
 +    for( i = layer_node.m_parent_count - 1; i >= 0; i-- )
 +    {
 +      layer_index = layer_node.m_parent_list[i];​
 +      layer_path += doc.m_layer_table[layer_index].LayerName();​
 +      layer_path += L" / ";
 +    }
 +  }
 +  layer_path += layer.LayerName();​
 +
 +  return layer_path;
 +}
 +</​code>​
 +
 +You can use this function like this:
 +
 +<code c++>
 +CRhinoCommand::​result CCommandTest::​RunCommand( const CRhinoCommandContext&​ context )
 +{
 +  ON_wString s = RhinoFullLayerPath( context.m_doc,​ context.m_doc.m_layer_table.CurrentLayer() );
 +  RhinoApp().Print( L"​%s\n",​ s.Array() );
 +  return CRhinoCommand::​success;​
 +</​code>​
 +
 +\\
 +
 +{{tag>​Developer cplusplus}}
developer/sdksamples/layerfullpath.txt ยท Last modified: 2015/09/14 (external edit)