Dimension on a plane

Hi all,

This maybe quite basic however I don’t know how to achieve it in Python:
I have done a script which can add dimension from a point to a surface(closest distance from point to surface).
In rhino, when you try to add dimension you always have to defined a plane first, then the dimension will be on the plane however the AddAlignedDimension method in Python doesn’t seems require a plane. Is there any other method can add a dimension on a defined plane?
Or there is something missing in my script?

Here is my code:

import rhinoscriptsyntax as rs

pt_01 = rs.GetPoint(“Pick the Plane Origin”)
pt_02 = rs.GetPoint(“Pick the Plane X”)
pt_00 = (pt_01, pt_01)

srf = rs.GetObject(“Pick a Srf to pull”,8)
pt_03 = rs.PullPoints(srf, pt_00)
pt_03 = pt_03[0]

ln = rs.AddLine(pt_01,pt_03)
midPt = rs.EvaluateCurve(ln,0.5)
rs.DeleteObject(ln)

pln = rs.PlaneFromPoints(pt_01,pt_02,pt_03) #I wish it can dimension on this plane however it doesn’t
#rs.ViewCPlane(None, pln)
Dim = rs.AddAlignedDimension(pt_01,pt_03,midPt)

pt_01 = rs.AddPoint(pt_01)
pt_03 = rs.AddPoint(pt_03)
groupName = rs.AddGroup()
ids = (pt_01,pt_03,Dim)
rs.AddObjectsToGroup(ids,groupName)

Thank you in advance.

Jack

i’m pretty sure something is wrong with rs.AddAlignedDimension but it’s not what your code is illustrating…

i think a problem in your example has to do with

midPt = rs.EvaluateCurve(ln,0.5)

that’s not returning the midpoint of your temporary line… and i think the point it is returning has just enough fuzz to give a direction.

for the midpoint, you could use rs.CurveMidPoint(ln)

the problem is, if you use that point for the third option of rs.AddAlignedDimension, the dimension fails to draw… but if you add the points to the document then use _DimAligned in rhino on those points, it will succeed

realisitically, you should be able to use this: (eliminate the part about finding a third point on the dimension line)

Dim = rs.AddAlignedDimension(pt_01, pt_03, pt_01)

or, at least, using those points with _DimAligned in rhino will draw the dimension properly.

the third option is just meant to tell how far to ‘extrude’ the dimension… it’s just that rs.AddAlignedDimension seems to be failing if the extrusion is 0…

but your example will work if you do:

Dim = rs.AddAlignedDimension(pt_01, pt_03, pt_02)

or, it shows that the plane isn’t an issue as that’s putting it on the defined plane… but i assume you don’t want the dimension located there.

Hi Jeff,

Thanks for your hints.
Yes, the AddAlignedDimension is not working the same way as the rhino command “_DimAligned”.
I have revise the code a bit and seems it works as I expact:

import rhinoscriptsyntax as rs

pt_01 = rs.GetPoint(“Pick the Plane Origin”)
pt_02 = rs.GetPoint(“Pick the Plane X”)
pt_00 = (pt_01, pt_01)

srf = rs.GetObject(“Pick a Srf to pull”,8)
pt_03 = rs.PullPoints(srf, pt_00)
pt_03 = pt_03[0]
pt_03 = rs.AddPoint(pt_03)

vec = rs.VectorCreate(pt_02,pt_03)
vec = rs.VectorUnitize(vec)
vec = rs.VectorScale(vec,0.0001)
pt_02 = rs.CopyObject(pt_03,vec)

Dim = rs.AddAlignedDimension(pt_01,pt_03,pt_02)

rs.DeleteObject(pt_02)
pt_01 = rs.AddPoint(pt_01)
groupName = rs.AddGroup()
ids = (pt_01,pt_03,Dim)
rs.AddObjectsToGroup(ids,groupName)

Cheers,

Jack