iCAx开思工具箱

标题: rhino犀牛的二次开发sdk程序代码 [打印本页]

作者: johnsunjiang    时间: 2006-3-9 14:40
标题: rhino犀牛的二次开发sdk程序代码
大家有空一起讨论讨论
以下代码是简单的添加新层的功能:
CRhinoCommand::result CCommandAddNewLayer::RunCommand(
        const CRhinoCommandContext& context
        )
  {
    // Get reference to the document's layer table
    CRhinoLayerTable& layer_table = context.m_doc.m_layer_table;


    // Cook up an unused layer name
    ON_wString unused_name;
    layer_table.GetUnusedLayerName( unused_name );


    // Prompt the user to enter a layer name
    CRhinoGetString gs;
    gs.SetCommandPrompt( L"Name of layer to add" );
    gs.SetDefaultString( unused_name );
    gs.AcceptNothing( TRUE );
    gs.GetString();
    if( gs.CommandResult() != CRhinoCommand::success )
      return gs.CommandResult();


    // Was a layer named entered?
    ON_wString layer_name = gs.String();
    layer_name.TrimLeftAndRight();
    if( layer_name.IsEmpty() )
    {
      RhinoApp().Print( L"Layer name cannot be blank.\n" );
      return CRhinoCommand::cancel;
    }


    // Is the layer name valid?
    if( !RhinoIsValidName(layer_name) )
    {
      RhinoApp().Print( L"\"%s\" is not a valid layer name.\n", layer_name );
      return CRhinoCommand::cancel;
    }


    // Does a layer with the same name already exist?
    int layer_index = layer_table.FindLayer( layer_name );
    if( layer_index >= 0 )
    {
      RhinoApp().Print( L"A layer with the name \"%s\" already exists.\n", layer_name );
      return CRhinoCommand::cancel;
    }


    // Create a new layer
    ON_Layer layer;
    layer.SetLayerName( layer_name );


    // Add the layer to the layer table
    layer_index = layer_table.AddLayer( layer );
    if( layer_index < 0 )
    {
      RhinoApp().Print( L"Unable to add \"%s\" layer.\n", layer_name );
      return CRhinoCommand::failure;
    }


    return CRhinoCommand::success;
  }
作者: yefeiqq    时间: 2009-1-13 21:13
加我QQ147026546
作者: 张少杰    时间: 2010-11-21 15:30





欢迎光临 iCAx开思工具箱 (https://t.icax.org/) Powered by Discuz! X3.3