本帖最后由 筑梦NARUTO 于 2015-7-25 17:45 编辑
前两天在gh官网看见的一个问题,我帮着写了下,我还因为这个问题发现自己写程序习惯不好,思维不够严密,写的程序不健壮。
问题:
我给他的代码改了两个地方。
第一:他的代码只支持单个物体bake,我给他改成了支持多个物体bake。
第二:我给他加了group功能 源代码:
[mw_shl_code=applescript,true]import rhinoscriptsyntax as rs
import Rhino
import scriptcontext as sc
a = []
if bake:
#create layer
sc.doc = Rhino.RhinoDoc.ActiveDoc
rs.AddLayer(name= layerText+str(diamondSize)+"mm", color=colorLayer, visible=visible, locked=False, parent=None)
#create rhino object
sc.doc = ghdoc
obj_id = obj
doc_object = [rs.coercerhinoobject(i) for i in obj_id]
attributes = [i.Attributes for i in doc_object]
geometry = [i.Geometry for i in doc_object]
#select layer to bake and add to the attributes
sc.doc = Rhino.RhinoDoc.ActiveDoc
layertable = sc.doc.Layers
layerindex = layertable.Find(layerText +str(diamondSize)+"mm",True)
for i in attributes:
i.LayerIndex = layerindex
#bake object
rhino_obj = [sc.doc.Objects.Add(geometry, attributes) for i in xrange(len(geometry))]
#create group
if group:
new_a = rs.coerceguidlist(rhino_obj)
if not gp_name:
gp_name = "NARUTO"
else:
gp_name = gp_name
c = sc.doc.Groups.GroupNames(True)
#返回rhino中组的名字
if not c:
group_name = rs.AddGroup(gp_name)
new_c = sc.doc.Groups.GroupNames(True)
else:
new_c = c
if gp_name in new_c:
group_index = sc.doc.Groups.Find(gp_name,True)
else:
group_name = rs.AddGroup(gp_name)
group_index = sc.doc.Groups.Find(group_name,True)
sc.doc.Groups.AddToGroup(group_index,new_a)[/mw_shl_code][/hide]
源文件下载链接:链接:http://pan.baidu.com/s/1o6KeGVw 密码:7xj9[/hide]
|