首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Grasshopper中构造Python的区间

如何在Grasshopper中构造Python的区间
EN

Stack Overflow用户
提问于 2019-05-24 09:07:27
回答 1查看 660关注 0票数 2

使用蚱蜢:如果我将一个https://rhino.github.io/components/mathematics/constructDomain.html传递给Python组件,python将其视为一个间隔。我可以对它做手术,如下所示:

代码语言:javascript
复制
print x
x.Grow(x[0]-y)
x.Grow(x[1]+y)

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

其中的指纹:

代码语言:javascript
复制
20.3596657850938,87.5596657850938
19.3596657850938,88.5596657850938
<type 'Interval'>
['CompareTo', 'EpsilonEquals', 'Equals', 'FromIntersection', 'FromUnion', 'GetHashCode', 'GetObjectData', 'GetType', 'Grow', 'IncludesInterval', 'IncludesParameter', 'IsDecreasing', 'IsIncreasing', 'IsSingleton', 'IsValid', 'Item', 'Length', 'MakeIncreasing', 'Max', 'MemberwiseClone', 'Mid', 'Min', 'NormalizedIntervalAt', 'NormalizedParameterAt', 'ParameterAt', 'ParameterIntervalAt', 'ReferenceEquals', 'Reverse', 'Swap', 'T0', 'T1', 'ToString', 'Unset', '__add__', '__class__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__ne__', '__new__', '__radd__', '__reduce__', '__reduce_ex__', '__repr__', '__rsub__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__sub__', '__subclasshook__']

然而,我想不出如何建造一个新的。它们看起来很有用,我想更多地使用它们。

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

我不知道interval是属于Python、Iron Python还是蚱蜢。

我怎么做一个新的间隔?

EN

回答 1

Stack Overflow用户

发布于 2019-05-27 09:52:28

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

代码语言:javascript
复制
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

这意味着:

代码语言:javascript
复制
x is sent in as a domain from the input to this function
0,1 <type 'Interval'>
Rhino.Geometry.Interval
C:\Program Files\Rhinoceros 5 (64-bit)\System\RhinoCommon.dll

There seem to be two types of intervals, Rhino and grasshopper. Now sure why you'd use a Grasshopper interval, but here it is anyway:
0.0 To 0.0 <type 'GH_Interval'>
Grasshopper.Kernel.Types.GH_Interval
C:\Program Files\Common Files\McNeel\Rhinoceros\5.0\Plug-ins\Grasshopper (b45a29b1-4343-4035-989e-044e8580d9cf)\0.9.76.0\Grasshopper.dll

To make a Rhino interval get it from the Rhino.Geometry module
0,1 <type 'Interval'>
Rhino.Geometry.Interval
C:\Program Files\Rhinoceros 5 (64-bit)\System\RhinoCommon.dll

z is the same as x: True

如果我们打开它:IronPython的type()函数实际上返回一个PythonType,它包装了.NET类型。.GetType()直接获取.NET类型。所以,type(x)给了<type 'Interval'>,这不是很有帮助,而x.GetType().FullName给了Rhino.Geometry.IntervalRhino.Geometry.Interval告诉了我如何做到这一点。

这是在这里的犀牛医生中讨论的,它有许多有用的属性和方法。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56289313

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档