pycharm 将点导入WirePolyline

8cdiaqws  于 2022-11-08  发布在  PyCharm
关注(0)|答案(1)|浏览(314)

我正在Abaqus中创建一条线多边形线,但无法向我的线添加点。


# Define the modelname

modelname = "SpineModel"

# Define list with with partnames

PartNames = ["C7", "L1", "L2", "L3", "L4", "L5", "S1", "T1", "T2", "T3", "T4", "T5", "T6", "T7", "T8", "T9", "T10",
             "T11", "T12"]

for i in range(19):
    # Define CoG [x,y,z] coordinates of each vertebrae
    CoG_OldX = mdb.models[modelname].parts[PartNames[i]].features['CoG'].xValue
    CoG_OldY = mdb.models[modelname].parts[PartNames[i]].features['CoG'].yValue
    CoG_OldZ = mdb.models[modelname].parts[PartNames[i]].features['CoG'].zValue
    CoG_OldXYZ = [CoG_OldX, CoG_OldY, CoG_OldZ]

# Print CoG to check the values

    print(CoG_OldXYZ)

    Spline_OLD = mdb.models[modelname].parts[PartNames[i]].WirePolyLine(mergeType=IMPRINT, meshable=False,
                                                                        points=CoG_OldXYZ)

运行此代码后,收到一个错误;类型错误:点[0];找到浮点数,应为元组
但是,当我打印CoG_OldXYZ时,它确实打印了所需的坐标(x,y,z坐标的19倍)。
当我将“Spline_OLD”替换为以下内容时,代码将按照我的要求运行:

Spline_OLD = mdb.models[modelname].parts[PartNames[i]].WirePolyLine(mergeType=IMPRINT, meshable=False,
                                                                         points=(
                                                                            [12.31, -127.52, -467.5],
                                                                           [14.2, -120.15, -484.72],
                                                                          [16.52, -112.85, -502.51],
                                                                         [13.43, -107.49, -520.53],
                                                                        [3.66, -103.59, -536.55],
                                                                       [-11.15, -101.88, -551.4],
                                                                      [-24.81, -100.96, -566.95],
                                                                     [-34.72, -101.45, -585.07],
                                                                    [-38.81, -103.47, -605.76],
                                                                   [-37.71, -107.53, -627.81],
                                                                  [-27.91, -112.2, -649.67],
                                                                 [-14.15, -116.35, -670.89],
                                                                [2.91, -120.57, -691.64],
                                                               [19.53, -123.48, -716.06],
                                                              [28.89, -128.22, -745.13],
                                                             [31.48, -130.96, -777.89],
                                                            [26.69, -129.92, -810.52],
                                                           [16.55, -116.49, -838.38],
                                                          [11.82, -93.95, -853.25]))

为什么我不能使用“CoG_OldXYZ”作为WirePolyline的点?我当前做错了什么?

5anewei6

5anewei61#

如果你观察并试图理解,错误本身就说明了你在做什么错事。
不管怎样,我从Abaqus脚本参考指南中找到了这个,

点对的元组,每个点对本身由一个元组表示。
这意味着您必须提供至少2个点来创建WirePolyLine。因此,当您一次传递多个点时,代码会正确运行。
现在,在for循环中,您可以将点保存在一个列表中,在for循环之后,您可以使用WirePolyLine方法并将该列表作为参数传递。请参考以下示例:

cog_points = []
for part in PartNames:
    # Define CoG [x,y,z] coordinates of each vertebrae
    CoG_OldX = mdb.models[modelname].parts[parts].features['CoG'].xValue
    CoG_OldY = mdb.models[modelname].parts[parts].features['CoG'].yValue
    CoG_OldZ = mdb.models[modelname].parts[parts].features['CoG'].zValue
    cog_points.append([CoG_OldX, CoG_OldY, CoG_OldZ])

for part in PartNames:
    Spline_OLD = mdb.models[modelname].parts[part].WirePolyLine(mergeType=IMPRINT, meshable=False,
                                                                        points=cog_points)

相关问题