Site Tools


Differences

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

Link to this comparison view

developer:sdksamples:printinstancedefinitions [2015/09/14] (current)
Line 1: Line 1:
 +====== Print Instance Definition Names ======
 +> **Developer:​** //​[[developer:​cplusplusplugins|C++]],​ [[developer:​dotnetplugins|.NET]]//​
 +> **Summary:​** //​Demonstrates how to print the names of all instance definitions in the document.//
 +> **NOTICE:** //The Rhino.NET SDK is deprecated in Rhino 5.  This example adapted for the new RhinoCommon SDK is [[developer:​rhinocommonsamples:​printinstancedefinitions|here]]//​
 +===== Question =====
 +How can I print the names of all instance definitions,​ in the instance definition table, in the active document?
  
 +===== Answer =====
 +See the following example code:
 +
 +==== C++ ====
 +<code c++>
 +CRhinoCommand::​result CCommandTest::​RunCommand( const CRhinoCommandContext&​ context )
 +{
 +  const CRhinoInstanceDefinitionTable&​ idef_table = context.m_doc.m_instance_definition_table;​
 +  int idef_count = idef_table.InstanceDefinitionCount();​
 +  if (idef_count == 0)
 +  {
 +    RhinoApp().Print("​No instance definitions found.\n"​);​
 +    return CRhinoCommand::​nothing;​
 +  }
 +
 +  int num_printed = 0;
 +  for (int i = 0; i < idef_count; i++)
 +  {
 +    const CRhinoInstanceDefinition* idef = idef_table[i];​
 +    if (idef != 0 && idef->​IsDeleted() == false)
 +    {
 +      ON_wString idef_name = idef->​Name();​
 +      RhinoApp().Print(L"​Instance definition %d = %s\n", num_printed,​ idef_name);
 +      num_printed += 1;
 +    }
 +  }
 +
 +  return CRhinoCommand::​success;​
 +}
 +</​code>​
 +
 +==== C# ====
 +<code c#>
 +public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
 +{
 +  MRhinoInstanceDefinitionTable idef_table = context.m_doc.m_instance_definition_table;​
 +  int idef_count = idef_table.InstanceDefinitionCount();​
 +  if (idef_count == 0)
 +  {
 +    RhUtil.RhinoApp().Print("​No instance definitions found.\n"​);​
 +    return IRhinoCommand.result.nothing;​
 +  }
 +
 +  int num_printed = 0;
 +  for (int i = 0; i < idef_count; i++)
 +  {
 +    IRhinoInstanceDefinition idef = idef_table[i];​
 +    if (idef != null && idef.IsDeleted() == false)
 +    {
 +      string idef_name = idef.Name();​
 +      RhUtil.RhinoApp().Print(String.Format("​Instance definition {0} = {1}\n",​ num_printed,​ idef_name));​
 +      num_printed += 1;
 +    }
 +  }
 +
 +  return IRhinoCommand.result.success;​
 +}
 +</​code>​
 +
 +==== VB.NET ====
 +<code vb>
 +Public Overrides Function RunCommand(ByVal context As RMA.Rhino.IRhinoCommandContext) As RMA.Rhino.IRhinoCommand.result
 +
 +  Dim idef_table As MRhinoInstanceDefinitionTable = context.m_doc.m_instance_definition_table
 +  Dim idef_count As Integer = idef_table.InstanceDefinitionCount()
 +  If (idef_count = 0) Then
 +    RhUtil.RhinoApp().Print("​No instance definitions found."​ + vbCrLf)
 +    Return IRhinoCommand.result.nothing
 +  End If
 +
 +  Dim num_printed As Integer = 0
 +  For i As Integer = 0 To idef_count - 1
 +    Dim idef As IRhinoInstanceDefinition = idef_table(i)
 +    If (idef IsNot Nothing AndAlso idef.IsDeleted() = False) Then
 +      Dim idef_name As String = idef.Name()
 +      RhUtil.RhinoApp().Print(String.Format("​Instance definition {0} = {1}" + vbCrLf, num_printed,​ idef_name))
 +        num_printed += 1
 +    End If
 +  Next
 +
 +  Return IRhinoCommand.result.success
 +End Function
 +</​code>​
 +
 +\\
 +
 +{{tag>​Developer cplusplus dotnet}}
developer/sdksamples/printinstancedefinitions.txt ยท Last modified: 2015/09/14 (external edit)