Hi
I am trying to write a script that bakes linear dimensions directly to a layout.
I’ve managed to get it working so far as when the layout is active the dimension appears. But, I can’t figure out a way to get the length value of the dimension to scale according to the drawing. The linear dimension class does not seem to allow access to this? Or maybe I am missing something or I need a different strategy?
Attaching the work so far in the hope someone here can help.
layoutScriptRhFile.3dm (37.2 KB)
Make-dimensions-in-layout_rev1.gh (9.0 KB)
Best regards,
Jacob
Found the answer myself. Apparently overlooked the property Rhino.Geometry.LinearDimension.DistanceScale where I can just use the ratio I get from the layout boundary
import rhinoscriptsyntax as rs
import Rhino
import scriptcontext as sc
if bake:
sc.doc = Rhino.RhinoDoc.ActiveDoc
layoutBoundary = rs.coercerhinoobject(layoutBoundaryID)
wtpTransf = layoutBoundary.WorldToPageTransform
detailView = layoutBoundary.DetailGeometry
ratio = detailView.PageToModelRatio
vec = Rhino.Geometry.Vector3d(dimPtB.X - dimPtA.X, dimPtB.Y - dimPtA.Y, 0)
vecPerp = Rhino.Geometry.Vector3d(-(dimPtB.Y - dimPtA.Y), dimPtB.X - dimPtA.X, 0)
vecPerp.Unitize()
vecPerp *= -dimOffset
ptOnDim = Rhino.Geometry.Point3d((dimPtA+dimPtB)*.5)
ptOnDim += vecPerp
dimPlane = Rhino.Geometry.Plane(dimPtA, vec, vecPerp)
rc, uA, vA = dimPlane.ClosestParameter(dimPtA)
rc, uB, vB = dimPlane.ClosestParameter(dimPtB)
rc, uM, vM = dimPlane.ClosestParameter(ptOnDim)
linearDim = Rhino.Geometry.LinearDimension(dimPlane, Rhino.Geometry.Point2d(uA, vA), Rhino.Geometry.Point2d(uB, vB), Rhino.Geometry.Point2d(uM, vM))
linearDim.Transform(wtpTransf)
linearDim.DistanceScale = 1/ratio
Rhino.Geometry.LinearDimension.SetUserString
rhino_obj = sc.doc.Objects.Add(linearDim)
sc.doc = ghdoc
1 Like