I am working on a script to automate dimensions in layout. Attached is a work in progress…
So far I am able to get the objects showing in a detail and get the start and end point of each edge. It sort of works, but gives the dimensions of the object relative to layout space, not the dimensions of the object itself.
For example, with a 12" x 12" x 12" box in a detail showing front view projection at 1"=2" scale the dimensions show as 6".
Does anyone know what I need to change in the script to get the actual dimensions of the object, which in the example would be 12".
rhino auto dimension-tester.py (3.9 KB)
Hi @GaryC, could you please post a small Rhino file to run this with ? I’ve tried one in inches with a single layout page and 4 details showing a brep box. It prints some numbers and:
Dimensions created successfully in the layout!
but there are no dimensions added to the document for me.
thanks,
c.
Sure. Here you go. I get 6" in the horizontal dimensions. The rest are zero, which actually makes sense and I have an idea how to handle that. If I could only figure out how to get actual dimensions, ideally associative.
auto dims test.3dm (2.1 MB)
Hi @GaryC, i guess you can get required scale factor from the detail by this:
ratio = detail.DetailGeometry.PageToModelRatio
Then set it either global using your dimension style’s LengthFactor
(or AltLengthFactor
) or by modifying the attributes of each dimension object in case your details have all different ratios and you want to use same dim style for all of them :
# required for below to work
import System
dim_id = rs.AddAlignedDimension(start_point, end_point, dim_line_point, "Foot-inch Sets")
if dim_id != System.Guid.Empty:
dim_obj = rs.coercerhinoobject(dim_id, True, True)
dim_obj.Geometry.AltLengthFactor = 1.0 / ratio
dim_obj.CommitChanges()
that does show [12] here for the alternate dimension and 1` for the value above it. Is that right?
not shure what you mean with associative ?
_
c.
btw. rs.DetailScale(detail_view)
also works to get the ratio with RhinoScriptSyntax…
Thanks very much. One step closer!
What I meant by “associative” dimensions is that the dimensions are linked to the geometry so that if the geometry is changed the dimensions change. In this example, if the box is changed to 13" then the dimensions should change. This seems to be the default behavior when creating dimensions manually.
Hope this makes sense.
Hi @GaryC,
i guess it is possible for PlugIns only since history is command based. There is this method to add a dimension to the object table with history.
Fun part is you get the right dimension length values and history when picking the dimension points manually on the brep.
btw. when reading the ratio
value above using rs.DetailScale
with a non parallel view, make sure to test the returned value (if it is zero). Then set it to 1. Otherwise the LengthFactor
will be zero for perspective views.
_
c.
Yes, that’s indeed the fun part. I clicked on the link you provided but only got the main page for the RhinoCommon API.
Not an issue on perspective views. I never add dimensions in a perspective view as they are almost always wrong.
Thanks alot. That clarifies it. I’ll work over my script to make it more useful and post my results once I’ve got something worthwhile.