本帖最后由 筑梦NARUTO 于 2015-7-20 08:05 编辑
[mw_shl_code=applescript,true]#coding=utf-8
#在rhinopython中调用rhinocommon需要将其实例化才会在rhino视窗显示GUID的东西
import Rhino
import scriptcontext as sc
import math
import rhinoscriptsyntax as rs
def dimensions(tri,pos,of):
vertices=rs.PolylineVertices(tri)
ang1=rs.Angle2((vertices[1],vertices[0]),(vertices[1],vertices[2]))
ang2=rs.Angle2((vertices[0],vertices[1]),(vertices[0],vertices[2]))
ang3=rs.Angle2((vertices[2],vertices[0]),(vertices[2],vertices[1]))
rad1=math.pi/180*ang1[0]
rad2=math.pi/180*ang2[0]
rad3=math.pi/180*ang3[0]
#print(ang1,ang2,ang3)
x1=vertices[0]-vertices[1]
y1=vertices[2]-vertices[1]
pl=rs.PlaneFromFrame(vertices[1],x1,y1)
x2=vertices[1]-vertices[0]
y2=vertices[2]-vertices[0]
p2=rs.PlaneFromFrame(vertices[0],x2,y2)
x3=vertices[0]-vertices[2]
y3=vertices[1]-vertices[2]
p3=rs.PlaneFromFrame(vertices[2],x3,y3)
arc1=Rhino.Geometry.Arc(pl,rs.VectorLength(x1)/pos,rad1)
arc2=Rhino.Geometry.Arc(p2,rs.VectorLength(x2)/pos,rad2)
arc3=Rhino.Geometry.Arc(p3,rs.VectorLength(x3)/pos,rad3)
dim1=Rhino.Geometry.AngularDimension(arc1,of)
dim2=Rhino.Geometry.AngularDimension(arc2,of)
dim3=Rhino.Geometry.AngularDimension(arc3,of)
sc.doc.Objects.AddAngularDimension(dim1)
sc.doc.Objects.AddAngularDimension(dim2)
sc.doc.Objects.AddAngularDimension(dim3)
sc.doc.Views.Redraw()
trigon=rs.GetObjects("选择多个三角形",rs.filter.curve)
pos=rs.GetInteger("标注位置(距顶点几分之一的位置标注)",4)
of=rs.GetReal("标注偏移",0)
for tri in trigon:
dimensions(tri,pos,of)
[/mw_shl_code]
前几天火车回家,补上多个三角形标注的代码。。再次感谢J大解答 |