找回密码
 注册
Simdroid-非首页
查看: 123|回复: 6

[二次开发] 求助:关于设置节点集输出的脚本有问题

[复制链接]
发表于 2010-12-20 11:33:43 | 显示全部楼层 |阅读模式 来自 广东广州
本帖最后由 lovebbtyf 于 2010-12-20 12:57 编辑

我在建立模型的时候,就建立了如下,1个节点集,但是问题在于,这个程序总是出错,我分别输出len(nSet.nodes)的大小是31的,输出这句n = nSet.nodes【i】值是我选中的最后一个节点。({'coordinates': array([12.0, -8.0, 0.0], 'd'), 'instanceName': 'PART-1-1', 'label': 931}) 我查看了是对的。  当我改变i的值, print  nSet.nodes[2],输出的是我选中的第三个节点,({'coordinates': array([12.0, 6.93333339691162, 0.0], 'd'), 'instanceName': 'PART-1-1', 'label': 63})也没有什么问题,但是,label = n.label,coord = n.coordinates怎么显示说有语法错误啊?跪求高手解答一下,下面的程序有什么问题啊?而且整个运行就是有错误的,一行一行试到label = n.label,coord = n.coordinates也出现问题了。
#p = mdb.models['Model-1'].parts['Part-1']
#n = p.nodes
#nodes = n.getSequenceFromMask(mask=(
#    '[#80000001 #40000000 #20000000 #10000000 #8000000 #4000000 #2000000',
#   ' #1000000 #800000 #400000 #200000 #100000 #80000 #40000',
#  ' #20000 #10000 #8000 #4000 #2000 #1000 #800',
# ' #400 #200 #100 #80 #40 #20 #10', ' #8 #4 ]', ), )
#p.Set(nodes=nodes, name='Set-1')


以下是程序
# -*- coding: cp936 -*-
# -------------------------
from abaqusConstants import *
from symbolicConstants import *
import odbAccess
import os
import string
vpName = session.currentViewportName
odb = session.viewports[ vpName ].displayedObject

nSet = odb.rootAssembly.instances['PART-1-1'].nodeSets['SET-1']
stepNum = -1
FrameNum = -1
# Get nodes list
nodeList = []
nLabelList = []
for i in range(len(nSet.nodes)):
   n = nSet.nodes【i】
  label = n.label
  coord = n.coordinates
  nodeList.append( [ label, coord ] )
  nLabelList.append( label )
nodeList.sort()
nLabelList.sort()
# Get steps list
stepList = []
for stepName in odb.steps.keys():
s = odb.steps[ stepName ]
stepList.append( [ s.number, stepName ] )
stepList.sort()
# Get field output and calulate the deformed coordinates
stepName = stepList[ stepNum ][1]
fo = odb.steps[ stepName ].frames[ FrameNum ].fieldOutputs['U'].getSubset( region=nSet )
Uvalue = fo.values
uNum = len( Uvalue[0].data )
nNum = len( nLabelList )
nCoord_deformed = []
for i in range( nNum ):
coord = []
for j in range( uNum ):
  coord.append( nodeList[1][j] + Uvalue.data[j] )
nCoord_deformed.append( coord )
## output .csv file
csvFileName = odb.name[0:-4]+"_COORD_NodeSet="+nSet.name+"_Step="+stepName+"_Frame="+str(FrameNum)+".csv"
csvFile = open( csvFileName, 'w' )
csvFile.write( "Node ID,COORD_x,COORD_y,COORD_z\n" )
for i in range( nNum ):
csvFile.write( str(nLabelList) )
for j in range( uNum ):
  #csvFile.write( ","+str(Uvalue.data[j]) )
  csvFile.write( ","+str(nCoord_deformed[j]) )
csvFile.write( '\n' )
csvFile.close()
发表于 2010-12-20 12:46:25 | 显示全部楼层 来自 上海
Simdroid开发平台
可以在n = nSet.nodes加个[i]试一下
回复 不支持

使用道具 举报

 楼主| 发表于 2010-12-20 12:53:57 | 显示全部楼层 来自 广东广州
本帖最后由 lovebbtyf 于 2010-12-20 12:58 编辑

2# fimltl
哦,不好意思,脚本里的就是n = nSet.nodes【i】  上面的显示有问题,程序里是有加的。
咦,为啥这个给的【i】打出来了,显示不出来呢?
回复 不支持

使用道具 举报

 楼主| 发表于 2010-12-20 16:47:05 | 显示全部楼层 来自 广东广州
上述问题解决了,又伴随有新问题,我重新输入# -*- coding: cp936 -*-
# -------------------------
from abaqusConstants import *
from symbolicConstants import *
import odbAccess
import os
import string
vpName = session.currentViewportName
odb = session.viewports[ vpName ].displayedObject

nSet = odb.rootAssembly.instances['PART-1-1'].nodeSets['SET-1']
stepNum = -1
FrameNum = -1
stepNum = -1


FrameNum = -1

# Get nodes list
nodeList = []
nLabelList = []

for i in range(len(nSet.nodes)):
     n = nSet.nodes[i]
    label=n.label
    coord=n.coordinates
    print label, coord输出了
1 [ 12.   8.   0.]
32 [ 12.          7.4666667   0.       ]
63 [ 12.          6.9333334   0.       ]
94 [ 12.          6.4000001   0.       ]
125 [ 12.           5.86666679   0.        ]
156 [ 12.           5.33333349   0.        ]
187 [ 12.           4.80000019   0.        ]
218 [ 12.           4.26666689   0.        ]
249 [ 12.           3.73333335   0.        ]
280 [ 12.           3.20000005   0.        ]
311 [ 12.           2.66666675   0.        ]
342 [ 12.           2.13333344   0.        ]
373 [ 12.           1.60000002   0.        ]
404 [ 12.           1.06666672   0.        ]
435 [ 12.           0.53333336   0.        ]
466 [ 12.   0.   0.]
497 [ 12.          -0.53333336   0.        ]
528 [ 12.          -1.06666672   0.        ]
559 [ 12.          -1.60000002   0.        ]
590 [ 12.          -2.13333344   0.        ]
621 [ 12.          -2.66666675   0.        ]
652 [ 12.          -3.20000005   0.        ]
683 [ 12.          -3.73333335   0.        ]
714 [ 12.          -4.26666689   0.        ]
745 [ 12.          -4.80000019   0.        ]
776 [ 12.          -5.33333349   0.        ]
807 [ 12.          -5.86666679   0.        ]
838 [ 12.         -6.4000001   0.       ]
869 [ 12.         -6.9333334   0.       ]
900 [ 12.         -7.4666667   0.       ]
931 [ 12.  -8.   0.]
这应该是我的nodeList 和nLabelList两链表建立成功啊,但是一输入nodeList.append( [ label, coord ] )
  nLabelList.append( label )
nodeList.sort()
nLabelList.sort()
就说是非法的语法错误,我去查了append(),sort()
这样的写法没有错误啊,还是因为我的链表没有创建成功?求高手指点一下,怎么创建啊?
回复 不支持

使用道具 举报

发表于 2010-12-20 16:59:15 | 显示全部楼层 来自 上海
print  nSet.nodes[2],输出的是我选中的第三个节点:在pythn中,list的编号是从0开始的,所以你输入2时,返回的肯定是第三个了。
回复 不支持

使用道具 举报

 楼主| 发表于 2010-12-21 10:12:07 | 显示全部楼层 来自 广东广州
问题解决了,为什么会显示那么多的语法错误。
我去查看了《简明Python教程》第四章的基本概念,缩进。就明白了~~上面的
nodeList.append( [ label, coord ] )
nLabelList.append( label )
nodeList.sort()
nLabelList.sort()
这些没有问题,问题在于,行首的空白,就是因为在逻辑行首的空白(空
格和制表符)用来决定逻辑行的缩进层次,从而用来决定语句的分组。我输入的时候,没有注意这些行首的空白,以至于这些语句找不到他所在的分组,于是,总弹出SyntaxError: invalid syntax
这个问题纠结了好些天,狂躁于我觉得没有什么问题,但总是运行不起来,希望给后学做二次开发的一些借鉴!!!
翻Python的手册,还看到C.W. Wendte写在卷首的一句话,获得人生中的成功需要的专注与坚持不懈多过天才与机会。很有感慨。因为我本身真的很怵编程,但是因为工作需要,不得不接触各种编程的语言,每次都是一知半解的,心理上也总暗示自己不会不懂,从而学习编程的过程变得消极,只要运行不成功,我总怀疑自己不是这块料。还好,坚持的试啊试,找了很多原因,也问了很多人(人都被我问烦了)深知这个二次开发,我还只是解决了一小部分问题,哎,借用那句话,和各位ABAQUS板块的达人们共勉吧。
PS:我在这论坛上也学到很多~~谢谢各位!!
回复 不支持

使用道具 举报

 楼主| 发表于 2010-12-21 13:57:51 | 显示全部楼层 来自 广东广州
本帖最后由 lovebbtyf 于 2010-12-21 13:59 编辑

6# lovebbtyf
想问下这个是什么错误啊?怎么解决?是将上述数据输出到一个excel表格中
csvFileName = odb.name[0:-4]+"_COORD_NodeSet="+nSet.name+"_Step="+stepName+"_Frame="+str(FrameNum)+".csv"
csvFile = open( csvFileName, 'w' )
csvFile.write( "Node ID,COORD_x,COORD_y,COORD_z\n" )
for i in range( nNum ):
    csvFile.write( str(nLabelList【i】) )
    for j in range( uNum ):
        #csvFile.write( ","+str(Uvalue【i】.data[j]) )
        csvFile.write( ","+str(nCoord_deformed
【i】
[j]) )
        csvFile.write( '\n' )
        csvFile.close()

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
回复 不支持

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|小黑屋|联系我们|仿真互动网 ( 京ICP备15048925号-7 )

GMT+8, 2024-4-27 18:24 , Processed in 0.057655 second(s), 12 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表