上篇文章我们说了怎样自动获取犀牛空间已有的文字、文字的轮廓线及注解点,但总是还不太方便,能否直接在GH里面生成文本,然后在犀牛空间生成呢?这样我就不用在犀牛里面操作了,直接用GH搞定,为全参做进一步准备。
下面是做好的效果:
下面是完整python代码:
# -*- coding: utf-8 -*-
__author__ = "抖小腿儿,QQ:241525449"
__version__ = "2021.05.15"
from ghpythonlib.componentbase import executingcomponent as component
import Grasshopper, GhPython
import System
import Rhino as rc
import rhinoscriptsyntax as rs
class MyComponent(component):
def RunScript(self, 平面, 文本, 字体, 字高, 对齐方式):
self.Name = "文本轮廓"
self.NickName = '文本轮廓'
self.Message = '文本轮廓'
self.Description = '根据参数生成文本轮廓线'
self.Category = '公鸡'
self.SubCategory = '曲线'
align={'左对齐':rc.Geometry.TextJustification.Left,'右对齐':rc.Geometry.TextJustification.Right,'居中对齐':rc.Geometry.TextJustification.Center,'中心对齐':rc.Geometry.TextJustification.MiddleCenter}
if align.has_key(对齐方式):
align=align[对齐方式]
else:
align=rc.Geometry.TextJustification.MiddleCenter
if 字高 is None or 字高 <=0:
字高=3.5
text = rc.RhinoDoc.ActiveDoc.Objects.AddText(文本,平面,字高,字体,False,False,align)
textposition = rc.RhinoDoc.ActiveDoc.Objects.Find(text)
outline = textposition.Geometry.Explode()
rc.RhinoDoc.ActiveDoc.Objects.Delete(textposition,True)
轮廓线 = outline
对齐点=平面.Origin
return (轮廓线, 对齐点)
但在电池各个输入端口需要设置一下数据类型,方法是右键点击每个端口,弹出下图菜单:
从上至下依次设置类型为:Plane , str , str , float , str ,要不然电池会爆红出错。
小伙伴们,学会了吗? 留个作业,怎样添加 注解点文字呢?