Site Tools

Modifying an Annotation Object's Dimension Style


Version: Rhino 4
Summary: Demonstrates how to modify the dimension style of a annotation object.
Notice: The Rhino.NET SDK is deprecated in Rhino 5. This example adapted for the new RhinoCommon SDK is here.


What is the method used to set the dimension style of an annotation object?


To modify the dimension style of an annotation object - CRhinoAnnotationObject or MRhinoAnnotationObject - use its SetStyleIndex member.

The following example code demonstrates how to iterate through every annotation object in the document and change the dimension style to the current dimension style.


Public Overrides Function RunCommand(ByVal context As RMA.Rhino.IRhinoCommandContext) As RMA.Rhino.IRhinoCommand.result
  ' Get the current dimension style index
  Dim dimstyle_table As MRhinoDimStyleTable = context.m_doc.m_dimstyle_table
  Dim dimstyle_index As Integer = dimstyle_table.CurrentDimStyleIndex
  ' Iterate through all undeleted, active objects
  Dim it As New MRhinoObjectIterator( _
IRhinoObjectIterator.object_state.undeleted_objects, _
  For Each obj As MRhinoObject In it
    ' Is the object an annotation object
    Dim annotation_obj As MRhinoAnnotationObject = MRhinoAnnotationObject.Cast(obj)
    If (annotation_obj IsNot Nothing And annotation_obj.StyleIndex <> dimstyle_index) Then
      ' Copy the annotation object
      Dim new_obj As MRhinoAnnotationObject = annotation_obj.Duplicate()
      If (new_obj IsNot Nothing) Then
        ' Modify the dimension style index
        Dim ref As New MRhinoObjRef(obj)
        ' Replace the original object with the modified one
        context.m_doc.ReplaceObject(ref, new_obj)
      End If
    End If
End Function
developer/sdksamples/dimstyle.txt ยท Last modified: 2020/08/14 (external edit)