Site Tools


Differences

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

Link to this comparison view

developer:rhinocommonsamples:dimstyle [2015/09/14] (current)
Line 1: Line 1:
 +===== Sample: Modifying an Annotation Object'​s Dimension Style =====
 +
 +===== C# =====
 +<code c#>
 +public class ChangeDimensionStyleCommand : Rhino.Commands.Command
 +{
 +  public override string EnglishName
 +  {
 +    get { return "​csChangeDimensionStyle";​ }
 +  }
 +
 +  protected override Result RunCommand(RhinoDoc doc, RunMode mode)
 +  {
 +    foreach (var rhino_object in doc.Objects.GetObjectList(ObjectType.Annotation))
 +    {
 +      var annotation_object = rhino_object as AnnotationObjectBase;​
 +      if (annotation_object == null) continue;
 +
 +      var annotation = annotation_object.Geometry as AnnotationBase;​
 +      if (annotation == null) continue;
 +
 +      if (annotation.Index == doc.DimStyles.CurrentDimensionStyleIndex) continue;
 +
 +      annotation.Index = doc.DimStyles.CurrentDimensionStyleIndex;​
 +      annotation_object.CommitChanges();​
 +    }
 +
 +    doc.Views.Redraw();​
 +
 +    return Result.Success;​
 +  }
 +}
 +</​code>​
 +===== VB.NET =====
 +<code vb>
 +Public Class ChangeDimensionStyleCommand
 +  Inherits Rhino.Commands.Command
 +  Public Overrides ReadOnly Property EnglishName() As String
 +    Get
 +      Return "​vbChangeDimensionStyle"​
 +    End Get
 +  End Property
 +
 +  Protected Overrides Function RunCommand(doc As RhinoDoc, mode As RunMode) As Result
 +    For Each rhino_object As RhinoObject In doc.Objects.GetObjectList(ObjectType.Annotation)
 +      Dim annotation_object = TryCast(rhino_object,​ AnnotationObjectBase)
 +      If annotation_object Is Nothing Then
 +        Continue For
 +      End If
 +
 +      Dim annotation = TryCast(annotation_object.Geometry,​ AnnotationBase)
 +      If annotation Is Nothing Then
 +        Continue For
 +      End If
 +
 +      If annotation.Index = doc.DimStyles.CurrentDimensionStyleIndex Then
 +        Continue For
 +      End If
 +
 +      annotation.Index = doc.DimStyles.CurrentDimensionStyleIndex
 +      annotation_object.CommitChanges()
 +    Next
 +
 +    doc.Views.Redraw()
 +
 +    Return Result.Success
 +  End Function
 +End Class
 +d Namespace
 +</​code>​
 +===== Python =====
 +<code python>
 +from Rhino import *
 +from Rhino.DocObjects import *
 +from Rhino.Commands import *
 +from Rhino.Geometry import *
 +from scriptcontext import doc
 +
 +def RunCommand():​
 +  for annotation_object in doc.Objects.GetObjectList(ObjectType.Annotation):​
 +    if not isinstance (annotation_object,​ AnnotationObjectBase):​
 +      continue
 +
 +    annotation = annotation_object.Geometry
 +
 +    if annotation.Index == doc.DimStyles.CurrentDimensionStyleIndex:​
 +      continue
 +
 +    annotation.Index = doc.DimStyles.CurrentDimensionStyleIndex
 +    annotation_object.CommitChanges()
 +
 +  doc.Views.Redraw()
 +  return Result.Success
 +
 +if __name__ == "​__main__":​
 +  RunCommand()
 +</​code>​
 +
 +{{tag>​Developer rhinocommon}}
  
developer/rhinocommonsamples/dimstyle.txt ยท Last modified: 2015/09/14 (external edit)