Dimension - Distribute dimension evenly

Hi everyone

Is there a way to distribute dimensions so they can be spaced out evenly? From the first image to the second image?

I’m able to get the control points from the dimension object and move it using:

import rhinoscriptsyntax as rs

dim = rs.GetObject("Select dimension to reposition", rs.filter.annotation)

if dim:
    rs.EnableObjectGrips(dim, True)
	newPt = rs.GetPoint("Pick new location)    
	rs.SelectObjectGrip(dim, 2)
	rs.Command("_Move {},{},{} {},{},{}".format(dimPt2.X, dimPt2.Y, dimPt2.Z, newPt.X, newPt.Y, newPt.Z), echo=False)
	rs.EnableObjectGrips(dim, False)

but I don’t know where to go from there to distribute a number of dimension evenly?

I want to mention that the dimensions in the first image is done with Elefront, so it’s automated, now I just want to automate how it looks on a page instead of dragging them around manually

Thanks in advance

Hello- I’d use rs.ObjectGripLoaction(idx,pt) for this - that way you can make an evenly spaced list of points, or a vector to increment points from the lowest one, and set the grip locations accordingly - you just need to figure out the grip index(es)for the ones on each dim that you care about - I think there are only 4 or 5.
grip indices:
image

-Pascal

Thanks Pascal, I will give that a go. Cheers!

Hi Pascal

rs.ObjectGripLocation(idx,pt) doesn’t seen to work for dimension control points, so I went back to rs.Command("_Move")

this script is not very clean, I’m just starting in Python. But it seens to work for me. There’s the before/after screen shots showing the dimensions are distributed in the X direction.

Thanks for your help! :slight_smile:

import rhinoscriptsyntax as rs

dims = rs.GetObjects("Select dimensions", rs.filter.annotation)
if dims:
    dimPtsX = []
    dimPtsY = []
    for dim in dims:
        rs.EnableObjectGrips(dim)
        dimPt = rs.ObjectGripLocation(dim, 2)
        dimPtsX.append(dimPt.X)
        dimPtsY.append(dimPt.Y)
        rs.EnableObjectGrips(dim, False)
    maxX = max(dimPtsX)
    minX = min(dimPtsX)
    maxY = max(dimPtsY)
    minY = min(dimPtsY)
    xDist = maxX - minX
    yDist = maxY - minY
    xStep = xDist / (len(dims) - 1)
    yStep = yDist / (len(dims) - 1)
    start = minX
    step = xStep
    count = len(dims)
    xPos = [start + (c * step) for c in range(count)]
    yPos = [start + (c * step) for c in range(count)]
    for i in range(0, len(dims)):
            rs.EnableObjectGrips(dims[i])
            rs.SelectObjectGrip(dims[i], 2)
            rs.Command("_Move {},{},{} {},{},{}".format(dimPtsX[i], 1000, 0, xPos[i], 1000, 0), echo=False)
            rs.EnableObjectGrips(dims[i], False)`Preformatted text