Site Tools


Modifying an Annotation Object's Dimension Style

.NET

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.

Question

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

Answer

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.

VB.NET

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, _
IRhinoObjectIterator.object_category.active_objects)
  it.IncludeLights(False)
  it.IncludeGrips(False)
 
  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
        new_obj.SetStyleIndex(dimstyle_index)
        new_obj.UpdateText()
 
        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
  Next
 
  context.m_doc.Redraw()
 
End Function
developer/sdksamples/dimstyle.txt ยท Last modified: 2016/01/12 by sandy