I use ‘Add Aligned Dimension’ in python script but text height so small. I change text height i but not.
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino
def GetOffsetMidpoints(pl_ID,dist,plane):
#get offset figure and offset points
bb=rs.BoundingBox(pl_ID)
xform=rs.XformScale(1.1,(bb[0]+bb[2])/2)
bb=rs.PointArrayTransform(bb,xform)
pl=rs.coercecurve(pl_ID)
sharp=Rhino.Geometry.CurveOffsetCornerStyle.Sharp
off_pl=pl.Offset(bb[2],plane.Normal,dist,sc.doc.ModelAbsoluteTolerance,sharp)
if off_pl:
segs=off_pl[0].DuplicateSegments()
mids=[(seg.PointAtStart+seg.PointAtEnd)/2 for seg in segs]
return mids
#closed planar polyline filter
def pl_filt(rhino_object, geometry, component_index):
return rs.IsPolyline(geometry) and rs.IsCurveClosed(geometry) and rs.IsCurvePlanar(geometry)
def DimClosedPolylines2():
msg="Select polylines to dimension"
pl_IDs=rs.GetObjects(msg,4,preselect=True,custom_filter=pl_filt)
if not pl_IDs: return
dist=rs.GetReal("Distance to offset?",5,0)
if dist is None: return
rs.EnableRedraw(False)
for pl_ID in pl_IDs:
verts=rs.PolylineVertices(pl_ID)
opts=GetOffsetMidpoints(pl_ID,dist,rs.CurvePlane(pl_ID))
if opts:
#checksum in case offset went wrong
if len(opts)+1==len(verts):
for i in range(len(verts)-1):
rs.AddAlignedDimension(verts[i],verts[i+1],opts[i])
DimClosedPolylines2()
Hi xiix
You need to create DimStyle,like this:
dimStyle_name = "Dim"+str(i)
dimStyle = rs.AddDimStyle(dimStyle_name)
dim = rs.AddAlignedDimension(verts[i],verts[i+1],opts[i],dimStyle)
rs.DimStyleTextHeight(dimStyle,30)
code:
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino
def GetOffsetMidpoints(pl_ID,dist,plane):
#get offset figure and offset points
bb=rs.BoundingBox(pl_ID)
xform=rs.XformScale(1.1,(bb[0]+bb[2])/2)
bb=rs.PointArrayTransform(bb,xform)
pl=rs.coercecurve(pl_ID)
sharp=Rhino.Geometry.CurveOffsetCornerStyle.Sharp
off_pl=pl.Offset(bb[2],plane.Normal,dist,sc.doc.ModelAbsoluteTolerance,sharp)
if off_pl:
segs=off_pl[0].DuplicateSegments()
mids=[(seg.PointAtStart+seg.PointAtEnd)/2 for seg in segs]
return mids
#closed planar polyline filter
def pl_filt(rhino_object, geometry, component_index):
return rs.IsPolyline(geometry) and rs.IsCurveClosed(geometry) and rs.IsCurvePlanar(geometry)
def DimClosedPolylines2():
msg="Select polylines to dimension"
pl_IDs=rs.GetObjects(msg,4,preselect=True,custom_filter=pl_filt)
if not pl_IDs: return
dist=rs.GetReal("Distance to offset?",5,0)
if dist is None: return
rs.EnableRedraw(False)
for pl_ID in pl_IDs:
verts=rs.PolylineVertices(pl_ID)
opts=GetOffsetMidpoints(pl_ID,dist,rs.CurvePlane(pl_ID))
if opts:
#checksum in case offset went wrong
if len(opts)+1==len(verts):
for i in range(len(verts)-1):
#
dimStyle_name = "Dim"+str(i)
dimStyle = rs.AddDimStyle(dimStyle_name)
dim = rs.AddAlignedDimension(verts[i],verts[i+1],opts[i],dimStyle)
rs.DimStyleTextHeight(dimStyle,30)
DimClosedPolylines2()
I hope this help you.
————NARUTO
I’m trying edit like this but not ok. When dim auto select default but don’t change height text. The Script create many option but ‘command dim’ don’t use it
My rhino version number: 6.0SR10
No problem with me,like this
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino
def GetOffsetMidpoints(pl_ID,dist,plane):
#get offset figure and offset points
bb=rs.BoundingBox(pl_ID)
xform=rs.XformScale(1.1,(bb[0]+bb[2])/2)
bb=rs.PointArrayTransform(bb,xform)
pl=rs.coercecurve(pl_ID)
sharp=Rhino.Geometry.CurveOffsetCornerStyle.Sharp
off_pl=pl.Offset(bb[2],plane.Normal,dist,sc.doc.ModelAbsoluteTolerance,sharp)
if off_pl:
segs=off_pl[0].DuplicateSegments()
mids=[(seg.PointAtStart+seg.PointAtEnd)/2 for seg in segs]
return mids
#closed planar polyline filter
def pl_filt(rhino_object, geometry, component_index):
return rs.IsPolyline(geometry) and rs.IsCurveClosed(geometry) and rs.IsCurvePlanar(geometry)
def DimClosedPolylines2():
msg="Select polylines to dimension"
pl_IDs=rs.GetObjects(msg,4,preselect=True,custom_filter=pl_filt)
if not pl_IDs: return
dist=rs.GetReal("Distance to offset?",5,0)
if dist is None: return
rs.EnableRedraw(False)
dimStyle = CreateDimStyle(dist)
#Create a DimStyle
for pl_ID in pl_IDs:
verts=rs.PolylineVertices(pl_ID)
opts=GetOffsetMidpoints(pl_ID,dist,rs.CurvePlane(pl_ID))
if opts:
#checksum in case offset went wrong
if len(opts)+1==len(verts):
for i in range(len(verts)-1):
dim = rs.AddAlignedDimension(verts[i],verts[i+1],opts[i],dimStyle)
def CreateDimStyle(textHeight):
dimStyle_name = "MyDim"
dimStyle = rs.AddDimStyle(dimStyle_name)
rs.DimStyleTextHeight(dimStyle,textHeight)
rs.DimStyleArrowSize(dimStyle,textHeight)
return dimStyle
DimClosedPolylines2()
I modified the code.
DimClosedPolylines.py (1.7 KB)
2 Likes
Thank you! i’m reinstall rhino and trying it!
Wow. Great little script, was hard to track this one down when searching for automatic dimensions in python script. Would be good to collate in a common github repo… wink wink.