Python-Abaqus如果操作发生失败,添加例外

2024-10-03 13:23:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在Abaqus中运行“InstanceFromBooleanCut”操作时向Python代码添加一些异常。基本上,我正在剪切一系列的部分,我不希望我的脚本停止,如果操作碰巧失败。 假设我有一个名为“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

Tags: toinstances代码modelpartstrycutpart