如果操作失败,则在Python-Abaqus中添加异常

时间:2015-08-14 16:22:05

标签: python exception abaqus

我正在尝试在运行" InstanceFromBooleanCut"时为我的Python代码添加一些例外。在Abaqus运作。基本上我正在切割一系列部件,如果操作失败,我不希望我的脚本停止。 假设我有一个名为" pr1" (我的切割实例)我想用它来切割零件" pr2"," pr3"和" pr4"。 让我们假设使用pr2和pr4进行切割的操作会成功,但对于pr3会失败。

我尝试使用" try-except"在我的代码中,但它没有做我想要的。基本上它成功地削减pr1和pr2,然后在切割pr1和pr3时失败,并且该过程在此处中断并且它从不尝试执行pr1和pr4的切割操作。

我该如何解决这个问题?

非常感谢!

我的代码:

pr1 = model.parts['Part-1-r']
pr2 = model.parts['Part-2-r']
pr3 = model.parts['Part-3-r']
pr4 = model.parts['Part-4-r']

#Try to cut pr2 using pr1 (success)
try:
    cut12=assy.InstanceFromBooleanCut(cuttingInstances=(assy.instances['Part-1-r'], ), instanceToBeCut=assy.instances['Part-2-r'], name='Part-1-2', originalInstances=SUPPRESS)
except ValueError:
    print "Oops! Not good" #we should not get here

#Try to cut pr3 using pr1 (cut operation fails)
try:
    cut13=assy.InstanceFromBooleanCut(cuttingInstances=(assy.instances['Part-1-r'], ), instanceToBeCut=assy.instances['Part-3-r'], name='Part-1-3', originalInstances=SUPPRESS)
except ValueError:
    print "Oops! Not good" # in this example an exception must show up

#Try to cut pr4 using pr1 (not happening at the moment due to the previous failed operation)
try:
    cut14=assy.InstanceFromBooleanCut(cuttingInstances=(assy.instances['Part-1-r'], ), instanceToBeCut=assy.instances['Part-4-r'], name='Part-1-4', originalInstances=SUPPRESS)
except ValueError:
    print "Oops! Not good" #we should not get here

0 个答案:

没有答案