在Grasshopp中如何在Python中构造区间

2024-05-29 03:18:54 发布

您现在位置:Python中文网/ 问答频道 /正文

使用Grasshopper:如果我将一个domain传递到Python组件中,Python将其视为一个间隔。我可以对它进行操作,如下所示:

print x
x.Grow(x[0]-y)
x.Grow(x[1]+y)

print x    
print type(x)
print dir(x)

哪个打印:

^{pr2}$

但是,我不知道如何建造一个新的。它们看起来很有用,我想多用一些。在

我已经尝试导入interval模块(Runtime error (ImportException): No module named interval)。我尝试过将列表转换为一个间隔:Interval([1,2])Runtime error (UnboundNameException): name 'Interval' is not defined。在

我不知道区间是属于Python,铁蟒还是蚱蜢。在

我该怎样做一个新的间隔?在


Tags: 模块间隔domaintypedir组件errorruntime
1条回答
网友
1楼 · 发布于 2024-05-29 03:18:54

在一些帮助下,我最终得到了:

print "x is sent in as a domain from the input to this function"
print x, type(x)
print x.GetType().FullName
print x.GetType().Assembly.Location

print "\nThere seem to be two types of intervals, Rhino and grasshopper. Now sure why you'd use a Grasshopper interval, but here it is anyway:"
import Grasshopper as gh
y = gh.Kernel.Types.GH_Interval()
print y, type(y)
print y.GetType().FullName
print y.GetType().Assembly.Location

print "\nTo make a Rhino interval get it from the Rhino.Geometry module"
import Rhino.Geometry.Interval as interval
z = interval(0,1)
print z, type(z)
print z.GetType().FullName
print z.GetType().Assembly.Location

print "\nz is the same as x:", z == x

它给出了:

^{pr2}$

如果我们解压:IronPython的type()函数实际上返回一个包装.NET类型的PythonType。.GetType()直接获取.NET类型。所以type(x)给出了<type 'Interval'>,这并不是很有帮助,而{}给出了{},它告诉我如何去做。在

这在Rhino docs here中有介绍,它有许多有用的属性和方法。在

相关问题 更多 >

    热门问题