Sdk Dim Style
Last changed: dale@mcneel.com-204.177.179.95

.
Developer.NET
VersionRhino 4
SummaryDemonstrates how to modify the dimension style of a annotation object.

Question

What is the method used to set the dimension style of a 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 (Rhino 4)

  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