在 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