Site Tools


Differences

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

Link to this comparison view

developer:rhinocommonsamples:printinstancedefinitions [2015/09/14]
developer:rhinocommonsamples:printinstancedefinitions [2020/08/14] (current)
Line 1: Line 1:
 +===== Sample: Print Instance Definition (Block) Names =====
 +
 +===== C# =====
 +<code c#>
 +[System.Runtime.InteropServices.Guid("71692574-73D4-4665-A617-72A937EBADEE")]
 +public class InstanceDefinitionNamesCommand : Command
 +{
 +  public override string EnglishName { get { return "csInstanceDefinitionNames"; } }
 +
 +  protected override Result RunCommand(RhinoDoc doc, RunMode mode)
 +  {
 +    var instanceDefinitionNames = (from instanceDefinition in doc.InstanceDefinitions 
 +                                   where instanceDefinition != null && !instanceDefinition.IsDeleted
 +                                   select instanceDefinition.Name);
 +
 +    foreach (var n in instanceDefinitionNames)
 +      RhinoApp.WriteLine(String.Format("Instance definition = {0}", n));
 +
 +    return Result.Success;
 +  }
 +}
 +</code>
 +===== VB.NET =====
 +<code vb>
 +<System.Runtime.InteropServices.Guid("B7391004-8A5D-4B54-88F5-1D2004D70BAC")> _
 +Public Class ex_printinstancedefinitions
 +  Inherits Command
 +  Public Overrides ReadOnly Property EnglishName() As String
 +    Get
 +      Return "vbInstanceDefinitionNames"
 +    End Get
 +  End Property
 +
 +  Protected Overrides Function RunCommand(doc As RhinoDoc, mode As RunMode) As Result
 +    Dim instanceDefinitionNames = (From instanceDefinition In doc.InstanceDefinitions
 +                                   Where instanceDefinition IsNot Nothing AndAlso Not instanceDefinition.IsDeleted
 +                                   Select instanceDefinition.Name)
 +
 +    For Each n As String In instanceDefinitionNames
 +      RhinoApp.WriteLine([String].Format("Instance definition = {0}", n))
 +    Next
 +
 +    Return Result.Success
 +  End Function
 +End Class
 +d Namespace
 +</code>
 +===== Python =====
 +<code python>
 +from scriptcontext import doc
 +
 +def RunCommand():
 +  instanceDefinitionNames = [instanceDefinition.Name for instanceDefinition in doc.InstanceDefinitions 
 +                             if instanceDefinition != None and not instanceDefinition.IsDeleted]
 +
 +  for n in instanceDefinitionNames:
 +    print "instance definition = {0}".format(n)
 +
 +if __name__ == "__main__":
 +  RunCommand()
 +</code>
 +
 +{{tag>Developer rhinocommon}}