Hi,
What is the easiest way to get the x and y dimensions of an 2D object using scripts?
Hi @Harold1,
Please provide an example of the object(s) or geometry you want to get it from and/or more info.
Are you wanting the overall bounding box dimensions of an object?
If so world aligned bounds or local bounds, etc.
Dimension between specific points? Etc.
here a sample of 1 part.
SD00123006.dxf (12.0 KB)
Hi @Harold1,
Essentially, you’ll want to get the object bounding box and then get the X and Y dimensions of said object.
If you are trying to automatically create dimensions then I would modify the script to Add Aligned Dimensions from/to the bounding box points that represent the “X” side you want and the “Y” side you want.
This script may help:
It is a fairly uncommon surname but I do not know of any Mark Vollrath, though my family was from Wisconsin so that’s close and could make sense that I just don’t know them personally haha
I want to store the X and Y in a variable to use later. Will that script do that?
No but you can modify it to do so.
There are different methods for storing variables.
You can set it in he object.UserText, DocumentText, within the Sticky Dictionary of the script, export it to csv, export to json, export to a database, etc.
It really depends on how you intend to access the values in the future and how you need to use them
Thanks. I will give it a try.
I got it. Below is did.
# Select a curve object
rc, rhobject = Rhino.Input.RhinoGet.GetOneObject("Select curve", False, Rhino.DocObjects.ObjectType.Curve)
if rc!=Rhino.Commands.Result.Success: return
# Validate selection
curve = rhobject.Curve()
if not curve: return
## Get the active view's construction plane
view = scriptcontext.doc.Views.ActiveView
if not view: return
plane = view.ActiveViewport.ConstructionPlane()
# Compute the tight bounding box of the curve in world coordinates
bbox = curve.GetBoundingBox(True)
if not bbox.IsValid: return
# get X and y
x1= round(bbox.Max.X, 3)
y1= round(bbox.Max.Y, 3)
#print(x1)
#print(y1)
return x1, y1
x, y = CurveBoundingBox()
print(x)
print(y)