grasshopper | 通过图层引用线条 报错:“ Data conversion failed from Guid to Curve ”的避免方法

需求:通过 LunchBox - > layer reference 电池 可以快速选中图层所在的线条,但是选择的数据流错误 

直接选择会报错——“Data conversion failed from Guid to Curve”:

因为是通过图层电池会选择 instance 实例化的物体,物体的类型是多种的 ,所以需要剔除不符合所要的数据类型:

import rhinoscriptsyntax as rs
import Rhino.Geometry.InstanceReferenceGeometry 

# 遍历版本
curveLst = []
def judgeCurve():
    
    for i, item in enumerate(x):
#        print(item.GetType())
        
        if item.GetType() == Rhino.Geometry.Curve or item.GetType() == Rhino.Geometry.ArcCurve \
        or item.GetType() == Rhino.Geometry.Arc \
        or item.GetType() == Rhino.Geometry.PolyCurve \
        or item.GetType() == Rhino.Geometry.Polyline \
        or item.GetType() == Rhino.Geometry.PolylineCurve \
        or item.GetType() == Rhino.Geometry.Line \
        or item.GetType() == Rhino.Geometry.Circle \
        or item.GetType() == Rhino.Geometry.Ellipse \
        or item.GetType() == Rhino.Geometry.NurbsCurve \
        or item.GetType() == Rhino.Geometry.BezierCurve \
        or item.GetType() == Rhino.Geometry.LineCurve:
            curveLst.append(item)
        
    
judgeCurve()
a = curveLst

筛选出数据即可正常运行:

 

IGH_Goo 数据类型定义 

https://developer.rhino3d.com/guides/grasshopper/grasshopper-data-types/

在 C# 中的用法:

GH_Structure<IGH_Goo> tree11 = new GH_Structure<IGH_Goo>();

对数据层级进行操作 

Layer and Sublayer creation in C#

左侧有个推荐,有用就推荐下吧?☺

 
posted @ 2021-03-11 12:03  谦曰盛  阅读(1552)  评论(0编辑  收藏  举报