How to change Model Space Scale value with Python Script?
Model Space Scale: 1
Hi @ska_drivers,
Review the following code and let me know if you have any questions.
import Rhino
import scriptcontext as sc
import System
def TestOverrideDimensionScale():
filter = Rhino.DocObjects.ObjectType.Annotation
rc, objref = Rhino.Input.RhinoGet.GetOneObject("Select text", False, filter)
if not objref or rc != Rhino.Commands.Result.Success:
return
text = objref.TextEntity()
if not text:
return
dim_style = text.DimensionStyle
new_name = sc.doc.DimStyles.GetUnusedStyleName(dim_style.Name)
override_style = dim_style.Duplicate(new_name, System.Guid.Empty, dim_style.Id)
override_style.DimensionScale = dim_style.DimensionScale + 1.0
override_style.SetFieldOverride(Rhino.DocObjects.DimensionStyle.Field.DimensionScale)
new_text = text.Duplicate()
new_text.SetOverrideDimStyle(override_style)
sc.doc.Objects.Replace(objref, new_text)
sc.doc.Views.Redraw()
if __name__ == "__main__":
TestOverrideDimensionScale()
β Dale
Thank you.
1 Like
Hello, what if I replace the text with annotations? Which part of the code changes will work?
Hi Dale,
How can we do this with RhinoScript instead of Python?
(VbScript)
Your code only works with text. If I want to change the model space scale for the dimension, it will not work. Is there any way to handle this issue with dimensions? Thank you.
Hi @theanhkc07,
Supporting any annotation isnβt that much different.
#! python3
import Rhino
import scriptcontext as sc
import System
def TestOverrideDimensionScale():
filter = Rhino.DocObjects.ObjectType.Annotation
rc, objref = Rhino.Input.RhinoGet.GetOneObject("Select annotation", False, filter)
if not objref or rc != Rhino.Commands.Result.Success:
return
annotation = objref.Geometry()
if not isinstance(annotation, Rhino.Geometry.AnnotationBase):
return
dim_style = annotation.DimensionStyle
new_name = sc.doc.DimStyles.GetUnusedStyleName(dim_style.Name)
override_style = dim_style.Duplicate(new_name, System.Guid.Empty, dim_style.Id)
override_style.DimensionScale = dim_style.DimensionScale + 1.0
override_style.SetFieldOverride(Rhino.DocObjects.DimensionStyle.Field.DimensionScale)
new_annotation = annotation.Duplicate()
new_annotation.SetOverrideDimStyle(override_style)
sc.doc.Objects.Replace(objref, new_annotation, False)
sc.doc.Views.Redraw()
if __name__ == "__main__":
TestOverrideDimensionScale()
β Dale
1 Like