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()
Hi,
Once you’ve positioned your dimensions in the location you want you can either adjust the extension line offset OR make the extension line a fixed length.
set ExtensionLineOffset to desired value and make sure FixedLengthExtensionOn is False (False is the default). The extension line will grow to offset value and FixedExtensionLength is be ignored.
set FixedExtensionLength to desired value and make sure FixedLengthExtensionOn is True. The extension line length will be fixed and ExtensionLineOffset is be ignored.
import rhinoscriptsyntax as rs
from scriptcontext import doc
from Rhino.Geometry import Plane
id = rs.AddLinearDimension(Plane.WorldXY, (0,0,0), (20,0,0), (10,5,0))
o = doc.Objects.FindId(id)
d = o.Geometry
# give extension lines a fixed length of 2
d.FixedLengthExtensionOn = True
d.FixedExtensionLength = 2.0
# give extension lines an offset of 1
#d.FixedLengthExtensionOn = False
#d.ExtensionLineOffset = 1
o.CommitChanges()
rs.Redraw()
Sorry for any confusion, that was a post asking how to solve (i don’t know how to code)
The expert answer is this one…
import rhinoscriptsyntax as rs
from scriptcontext import doc
from Rhino.Geometry import Plane
id = rs.AddLinearDimension(Plane.WorldXY, (0,0,0), (20,0,0), (10,5,0))
o = doc.Objects.FindId(id)
d = o.Geometry
# give extension lines a fixed length of 2
d.FixedLengthExtensionOn = True
d.FixedExtensionLength = 2.0
# give extension lines an offset of 1
#d.FixedLengthExtensionOn = False
#d.ExtensionLineOffset = 1
o.CommitChanges()
rs.Redraw()
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)
dimid = sc.doc.Objects.FindId(dim)
dimG = dimid.Geometry
dimG.FixedLengthExtensionOn = False
dimG.ExtensionLineOffset = 50.0
dimid.CommitChanges()
rs.Redraw()
note that the offset is just an arbitrary number for testing.
What offset are you trying to affect? Do note that as you change the offset it changes the textHeight.
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?",20,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)
dimid = sc.doc.Objects.FindId(dim)
dimG = dimid.Geometry
dimG.FixedLengthExtensionOn = False
dimG.ExtensionLineOffset = 5.0
dimid.CommitChanges()
rs.Redraw()
dist=rs.GetReal("Distance to offset?",20,0)
# give extension lines an offset of 1
d.FixedLengthExtensionOn = False
d.ExtensionLineOffset = 5
# give extension lines a fixed length of 2
#d.FixedLengthExtensionOn = True
#d.FixedExtensionLength = 2.0