Try using MObjectHandle. Unfortunately, I believe (though haven't confirmed) that this means you will have to get an MObjectHandle for your MObject at some point before it is deleted... but this is probably a good idea, anyway, as MObjectHandles are intended to be used for any situation in which you need to hold onto objects "longer term" and / or they might be deleted.
Once you have an MObjectHandle, you can try using it's isValid() or isAlive() methods. Hopefully those will give you what you need. On Wed, Jan 3, 2018 at 1:43 AM Marcus Ottosson <[email protected]> wrote: > Hi all, > > I’m trying to figure out convert a crash into an exception. > > The crash is coming from use of a function set when the MObject it’s > managing is pointing to a node I’ve just deleted. Here’s the shortest I > could make of it (Maya 2018). > > from maya.api import OpenMaya as om > fn = om.MFnDagNode() > mobj = fn.create("transform")fn.name()# u'transform3' > mod = om.MDGModifier() > mod.deleteNode(mobj); > mod.doIt();del modfn.name() > > Which throws this.. > > Stack trace: > Foundation.dll!TmtRefCounter::add > Foundation.dll!Tstring::operator= > OpenMaya.dll!Autodesk::Maya::OpenMaya20180000::MString::operator= > OpenMaya.dll!Autodesk::Maya::OpenMaya20180000::MFnDependencyNode::name > OpenMaya.dll!MPyMFnDependencyNode_Type::addToModule > python27.dll!PyEval_GetFuncDesc > python27.dll!PyEval_EvalFrameEx > python27.dll!PyEval_EvalCodeEx > python27.dll!PyRun_FileExFlags > python27.dll!PyRun_InteractiveOneFlags > python27.dll!PyRun_InteractiveLoopFlags > python27.dll!PyRun_AnyFileExFlags > python27.dll!Py_Main > KERNEL32.DLL!BaseThreadInitThunk > ntdll.dll!RtlUserThreadStart > > Result: untitled > Fatal Error. Attempting to save in > C:/Users/marcus/AppData/Local/Temp/marcus.20180103.0935.ma > > The fact that it crashes isn’t a problem, it makes sense. But what I’d > like to try and do is instead of having it crash raise an exception. > > I went for MObject.isNull() > <http://help.autodesk.com/view/MAYAUL/2017/ENU/?guid=__py_ref_class_open_maya_1_1_m_object_html> > at first, but that seems to always return False. > > Any ideas? > > Best, > Marcus > > > -- > You received this message because you are subscribed to the Google Groups > "Python Programming for Autodesk Maya" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOBw42L51ULyNjOCmKGMOJTcnw44w-r5VjPMocLbpj%2BhfA%40mail.gmail.com > <https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOBw42L51ULyNjOCmKGMOJTcnw44w-r5VjPMocLbpj%2BhfA%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAAssL7bFoewtSBQo%2B9kzNwbSo9YOKJ_ftZp5L_qzHHi0YBSX1Q%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
