NCF参数化建筑论坛
标题:
RhinoPython一键标注闭合多重直线
[打印本页]
作者:
月之眼
时间:
2018-10-19 19:29
标题:
RhinoPython一键标注闭合多重直线
前段时间在rhino官网回答一个问题,写的一键标注闭合的多重直线,分享一下代码
代码运行结果:
[attach]50664[/attach]
代码:
#coding=utf-8
#月之眼
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():
pl_IDs=rs.GetObjects("选择要标注的闭合多重直线",4,preselect=True,custom_filter=pl_filt)
if not pl_IDs: return
dist=rs.GetReal("标注偏移距离?",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 = "月之眼"+str(i)
dimStyle = rs.AddDimStyle(dimStyle_name)
dim = rs.AddAlignedDimension(verts[i],verts[i+1],opts[i],dimStyle)
rs.DimStyleTextHeight(dimStyle,30)
DimClosedPolylines2()
复制代码
作者:
蓝绝
时间:
2020-7-28 22:54
请问楼主这个能加入一个四舍五入进去吗
作者:
蓝绝
时间:
2020-7-28 23:03
请问楼主这个能加入一个四舍五入进去吗
作者:
月之眼
时间:
2020-10-17 12:37
蓝绝 发表于 2020-7-28 22:54
请问楼主这个能加入一个四舍五入进去吗
那数据生成之后,加个round()函数就行了。
欢迎光临 NCF参数化建筑论坛 (http://bbs.ncf-china.com/)
Powered by Discuz! X3.2