【问题标题】:How to import CSV file to Rhino using Python and connect the points using interpCRV command如何使用 Python 将 CSV 文件导入 Rhino 并使用 interpCRV 命令连接点
【发布时间】:2016-03-05 18:33:26
【问题描述】:

我有一个程序可以在不同的预定义几何图形之间进行插值,并输出一个 CSV 文件,其中包含由 X Y Z 列定义的点。例如:

1,5,0.2

3,4,0.2

1,5,0.3

3,4,0.3

我正在尝试将该文件导入 Rhino,并通过 _interpCRV 连接任何具有共同 Z 值的点 按照它们的导入顺序最终结果是我将拥有相似的形状(像一个圆圈)在不同的 Z 值。在那之后我将不得不进一步操纵几何,但我很难开始这第一步。提前致谢!

【问题讨论】:

  • 如果您能向我们展示您的尝试,我们会在正确的方向上帮助您!

标签: python csv rhino rhinoceros


【解决方案1】:

您可以使用以下命令从 txt 导入点:

def ReadPointsDef(filename):

if not filename: return

#read each line from the file
file = open(filename, "r")
#list of lines
contents = file.readlines()
#contents = [line.rstrip('\n') for line in file]
file.close()

# points=[]
points3d = Rhino.Collections.Point3dList()
for text in contents:
    items = text.strip("()\n").split(",")    
    if len(items)==3:
        x = float(items[0])
        y = float(items[1])
        z = float(items[2])
        points3d.Add(x,y,z)

#contents = [__point_from_string(line) for line in contents]
#return points
return points3d

然后在任何你想要的地方使用,比如这个示例:

points = ReadPointsDef("C:/Users/UsuarioStd/Documents/points.txt")
interCurve = rs.AddInterpCurve(points,3,4) 
rs.ObjectColor(interCurve, [255,0,0])#rojo

您必须按 Z 分组并使用这些组来构建曲线。 您必须提供有关您想要的输出的更多信息,图表会很好。 问候

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-31
    • 2020-08-23
    • 2014-03-26
    • 2017-07-15
    • 2013-01-13
    • 2011-08-30
    • 1970-01-01
    • 2021-04-03
    相关资源
    最近更新 更多