How To Set Dimension Text/Value?


How can I take an existing dimension and update it’s value text to a new value?

Essentially I just want to update the value of the dimension via a “Get String” prompt without opening the full Edit Dimension dialog.

Here’s my code attempt:

import rhinoscriptsyntax as rs
import Rhino.Geometry as rg

def EditDimension(dim_id):
    # Get current value of the dimension
    value = rs.DimensionText(dim_id)
    print("Current Value:", value)
    # Prompt the user for a new value
    new_value = rs.GetString("Enter new value for dimension", value)
    print("New value:", new_value)
    # Update the dimension with the new value
    if new_value:
        # rs.DimensionText(dim_id, new_value)
        print("Dimension updated successfully")
        rg.Dimension.UpdateDimensionText(dim_id, new_value)

# Select a Dimension
dim_id = rs.GetObject("Select a Dimension", rs.filter.annotation, preselect=True)
if dim_id:

Thank you for your response!


Looks like longer term what I am after is actually just a linear dimension constraint. I saw in a gif that @Joshua_Kennedy posted here as a gif that the user can have a dimension constraint and then update the value and it of course updates the dimension and the object accordingly.

@Joshua_Kennedy are the constraints going to be returning as a Rhino 9 WIP feature?

Thanks for your response!

Hi @michaelvollrath, below seems to do it:

#! python 2
import Rhino
import scriptcontext
import rhinoscriptsyntax as rs

def dim_filter(rhino_object, geometry, component_index):
    return isinstance(rhino_object, Rhino.DocObjects.DimensionObject)

def EditDimensionText():
    dim_id = rs.GetObject("Select Dimension", 512, True, True, dim_filter)
    if not dim_id: return
    dim_obj = rs.coercerhinoobject(dim_id, True)
    old_val = dim_obj.AnnotationGeometry.PlainText 
    new_val = rs.GetString("Enter new value", old_val, ["ComputedValue"])
    if not new_val: return
    if new_val == "ComputedValue": new_val = "<>"
    dim_obj.AnnotationGeometry.PlainText = new_val


To reset it to the computed value <> click on the option ComputedValue.


1 Like

Sorry @clement, somehow I am just getting to this now.

Thank you so much, the script works perfectly!