Click or drag to resize

TextLogPrint Method (String)

Send text to the text log

Namespace:  Rhino.FileIO
Assembly:  RhinoCommon (in RhinoCommon.dll)
Since: 5.1
Syntax
public void Print(
	string text
)

Parameters

text
Type: SystemString

[Missing <param name="text"/> documentation for "M:Rhino.FileIO.TextLog.Print(System.String)"]

Examples
using Rhino;
using Rhino.DocObjects;
using Rhino.FileIO;
using Rhino.Commands;

namespace examples_cs
{
  public class InstanceDefinitionTreeCommand : Command
  {
    public override string EnglishName { get { return "csInstanceDefinitionTree"; } }

    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
      var instance_definitions = doc.InstanceDefinitions;
      var instance_definition_count = instance_definitions.Count;

      if (instance_definition_count == 0)
      {
        RhinoApp.WriteLine("Document contains no instance definitions.");
        return Result.Nothing;
      }

      var dump = new TextLog();
      dump.IndentSize = 4;

      for (int i = 0; i < instance_definition_count; i++)
        DumpInstanceDefinition(instance_definitions[i], ref dump, true);

      RhinoApp.WriteLine(dump.ToString());

      return Result.Success;
    }

    private void DumpInstanceDefinition(InstanceDefinition instanceDefinition, ref TextLog dump, bool isRoot)
    {
      if (instanceDefinition != null && !instanceDefinition.IsDeleted)
      {
        string node = isRoot ? "─" : "└";
        dump.Print(string.Format("{0} Instance definition {1} = {2}\n", node, instanceDefinition.Index, instanceDefinition.Name));

        if (instanceDefinition.ObjectCount  > 0)
        {
          dump.PushIndent();
          for (int i = 0; i < instanceDefinition.ObjectCount ; i++)
          {
            var obj = instanceDefinition.Object(i);
            if (obj == null) continue;
            if (obj is InstanceObject)
              DumpInstanceDefinition((obj as InstanceObject).InstanceDefinition, ref dump, false); // Recursive...
            else
              dump.Print("\u2514 Object {0} = {1}\n", i, obj.ShortDescription(false));
          }
          dump.PopIndent();
        }
      }
    }
  }
}
Python
from scriptcontext import doc
import Rhino

def RunCommand():
  instanceDefinitions = doc.InstanceDefinitions
  instanceDefinitionCount = instanceDefinitions.Count

  if instanceDefinitionCount == 0:
    print "Document contains no instance definitions."
    return

  dump = Rhino.FileIO.TextLog()
  dump.IndentSize = 4

  for i in range(0, instanceDefinitionCount):
    DumpInstanceDefinition(instanceDefinitions[i], dump, True)

  print dump.ToString()

def DumpInstanceDefinition(instanceDefinition, dump, isRoot):
  if instanceDefinition != None and not instanceDefinition.IsDeleted:
    if isRoot:
      node = '-'
    else:
      node = '+'
    dump.Print(u"{0} Instance definition {1} = {2}\n".format(node, instanceDefinition.Index, instanceDefinition.Name))

    if instanceDefinition.ObjectCount  > 0:
      dump.PushIndent()
      for i in range(0, instanceDefinition.ObjectCount):
        obj = instanceDefinition.Object(i)
        if obj != None and type(obj) == Rhino.DocObjects.InstanceObject:
          DumpInstanceDefinition(obj.InstanceDefinition, dump, False) # Recursive...
        else:
          dump.Print(u"+ Object {0} = {1}\n".format(i, obj.ShortDescription(False)))
      dump.PopIndent()

if __name__ == "__main__":
  RunCommand()
See Also