# Weird dimension python script

Hi, I want to add the dimension on "front"plane, the height from the center(center of gravity) to the left bottom corner(basepoint) of the box. I used the following python script.

``````centerofgravity = x, y, z+gz  #the coordinate of the center of gravity
basepoint = x,y,z                  #the coordinate of the basepoint
Dimpoint = x,y,z+0.5*gz  #let the dimension in the middle of the height.
``````

#since the dimension will be inserted on YZ plane, I try to rotate it to XZ plane
obj = rs.AddLinearDimension( centerofgravity, basepoint, Dimpoint )
if obj:
point = Dimpoint
if point: rs.RotateObject(obj, point, 90, (0,0,1), copy=False)

But it appears to be 0, like in the picture. Does anyone know why this happens?

Hi Yang,

The `rs.AddLinearDimension` function could really take an input plane, not just dimension locations. I’ll add this to the “to-do” list. In the mean time, try using this special version of `rs.AddLinearDimension`.

``````import Rhino
import rhinoscriptsyntax as rs
import scriptcontext
import System

def MyLinearDimension(view_plane, start_point, end_point, point_on_dimension_line):
# Coerce input
plane = rs.coerceplane(view_plane)
start = rs.coerce3dpoint(start_point, True)
end = rs.coerce3dpoint(end_point, True)
onpoint = rs.coerce3dpoint(point_on_dimension_line, True)
# Set origin of plane
plane.Origin = start
# Calculate 2d dimension points
success, s, t = plane.ClosestParameter(start)
start = Rhino.Geometry.Point2d(s,t)
success, s, t = plane.ClosestParameter(end)
end = Rhino.Geometry.Point2d(s,t)
success, s, t = plane.ClosestParameter(onpoint)
onpoint = Rhino.Geometry.Point2d(s,t)
ldim = Rhino.Geometry.LinearDimension(plane, start, end, onpoint)
if not ldim: return scriptcontext.errorhandler()
if rc==System.Guid.Empty: raise Exception("unable to add dimension to document")
scriptcontext.doc.Views.Redraw()
return rc
``````

You can use the above method as follows:

``````# World Top plane
view_plane = rs.PlaneFromFrame([0,0,0], [1,0,0], [0,1,0])
start_point = (5,5,0)
end_point = (15,5,0)
point_on_dimension_line = (15,7,0)
MyLinearDimension(view_plane, start_point, end_point, point_on_dimension_line)

# World Front plane
view_plane = rs.PlaneFromFrame([0,0,0], [1,0,0], [0,0,1])
start_point = (5,0,5)
end_point = (15,0,5)
point_on_dimension_line = (15,0,7)
MyLinearDimension(view_plane, start_point, end_point, point_on_dimension_line)

# World Right plane
view_plane = rs.PlaneFromFrame([0,0,0], [0,1,0], [0,0,1])
start_point = (0,5,5)
end_point = (0,15,5)
point_on_dimension_line = (0,15,7)
MyLinearDimension(view_plane, start_point, end_point, point_on_dimension_line)
``````

Does this help?