| McNeel Wiki | |||||
| edit · print · help · all topics | |||||
Main Pages
Languages
| The following sample code demonstrates how to determine a selected object's layer name using the Rhino SDK. C++
CRhinoCommand::result CCommandTest::RunCommand( const CRhinoCommandContext& context )
{
CRhinoGetObject go;
go.SetCommandPrompt( L"Select object" );
go.GetObjects( 1, 1 );
if( go.CommandResult() != CRhinoCommand::success )
return go.CommandResult();
const CRhinoObjRef& objref = go.Object(0);
const CRhinoObject* object = objref.Object();
if( !object )
return CRhinoCommand::failure;
const CRhinoObjectAttributes& attributes = object->Attributes();
int layer_index = attributes.m_layer_index;
const CRhinoLayerTable& layer_table = context.m_doc.m_layer_table;
const CRhinoLayer& layer = layer_table[layer_index];
ON_wString layer_name = layer.LayerName();
RhinoApp().Print( L"The selected object's layer is \"%s\"\n", layer_name );
return CRhinoCommand::success;
}
VB.NET (Rhino 4)
Public Overrides Function RunCommand(ByVal context As IRhinoCommandContext) _
As IRhinoCommand.result
Dim go As New MRhinoGetObject
go.SetCommandPrompt("Select object")
go.GetObjects(1, 1)
If (go.CommandResult() <> IRhinoCommand.result.success) Then
Return go.CommandResult()
End If
Dim objref As IRhinoObjRef = go.Object(0)
Dim obj As IRhinoObject = objref.Object()
If (obj Is Nothing) Then Return IRhinoCommand.result.failure
Dim attributes As IRhinoObjectAttributes = obj.Attributes()
Dim layer_index As Integer = attributes.m_layer_index
Dim layer_table As IRhinoLayerTable = context.m_doc.m_layer_table
Dim layer As IRhinoLayer = layer_table(layer_index)
Dim layer_name As String = layer.LayerName()
Dim msg As String = _
String.Format("The selected object's layer is '{0}'" + vbCrLf, layer_name)
RhUtil.RhinoApp.Print(msg)
Return IRhinoCommand.result.success
End Function
C# (Rhino 4)
public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
{
MRhinoGetObject go = new MRhinoGetObject();
go.SetCommandPrompt("Select object");
go.GetObjects(1, 1);
if(go.CommandResult() != IRhinoCommand.result.success)
return go.CommandResult();
IRhinoObjRef objref = go.Object(0);
IRhinoObject obj = objref.Object();
if(obj == null)
return IRhinoCommand.result.failure;
IRhinoObjectAttributes attributes = obj.Attributes();
int layer_index = attributes.m_layer_index;
IRhinoLayerTable layer_table = context.m_doc.m_layer_table;
IRhinoLayer layer = layer_table[layer_index];
string layer_name = layer.LayerName();
string msg = string.Format("The selected object's layer is '{0}'\n", layer_name);
RhUtil.RhinoApp().Print(msg);
return IRhinoCommand.result.success;
}
| ||||
| rename · changes · history · subscriptions · lost and found · references · file upload | |||||