python - 如何在 Grasshopper 中用 Python 构造一个区间

标签 python ironpython grasshopper

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

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

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

打印:

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__']

但是,我不知道如何构建一个新的。它们看起来很有用,我想更多地使用它们。

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

不知道interval属于Python,Iron Python还是grasshopper。

如何创建新的间隔?

最佳答案

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

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

给出:

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()函数实际上返回一个包装 .NET 类型的 PythonType。 .GetType()直接获取 .NET 类型。所以type(x)给出 <type 'Interval'>这不是很有帮助,wheras x.GetType().FullName给出 Rhino.Geometry.Interval它告诉我如何到达它。

这包含在 Rhino docs here 中,它有很多有用的属性和方法。

关于python - 如何在 Grasshopper 中用 Python 构造一个区间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56289313/

相关文章:

javascript - 沿弧线寻找点

python - 如何根据不同的索引阈值过滤数据帧

python - 在Python中定义数组类型由C函数填充

.net - Microsoft.Scripting.Core.dll 在哪里?

c# - Alea Gpu 运行时错误在 Rhino/GrassHopper 项目中找不到文件或依赖项

python - 为什么会出现TypeError

c# - 在 VisualStudio 中创建 IronPython 项目时出错; "Exception has been thrown by the target of an invocation."

python - 如何解决 Python 和 IronPython 中的 sys.path 差异

c# - 如何导出从 Grasshopper 烘焙的顶点颜色,Rhino3d 在 Unity、Unreal 等游戏引擎中或直接在 webXr 中实时分析?

c# - 属性、索引器或动态成员访问不能作为 out 或 ref 参数传递?