Object is not alive/ufs.Obj.AskStatus(tag)

Hello,

I am tired of dealing with "Attempt to use an object that is not alive - at NXOpen.TaggedObject.get_Tag()" as an exception while working with NXOpen. I don't want to use try-catch blocks, and I'd like to try and find a way to check if an object is not alive.

I found this forum post linked below:

https://community.sw.siemens.com/s/question/0D54O000061xR89SAE/object-th...

For a specific example, I fetch a unloaded component's object that removed from a subassembly, but the structure of the parent assembly wasn't updated to reflect that removal. The subassembly is then loaded, I now have a dead tag of a component that no longer exists (as the parent assembly's structure was updated when the subassembly is loaded). I want to check the blanked status of that "dead" component, but I can't since I run into the "object not alive" exception.

The only way I've found to check a Tag's alive status is through:

m_UFSession.Obj.AskStatus(comp.Tag) == NXOpen.UF.UFConstants.UF_OBJ_ALIVE

However, fetching the component's tag with the .Tag property, throws the "Object is not alive" exception. Is there a non-UFsession way of checking if an NXObject is still alive?

This is an example with a component, but I've encountered this exception with multiple types of NXObjects, and I don't want to have to pair an NXObject with its associated tag (to avoid using the .Tag property).

I don't suggest doing anything with components until they are at least minimally loaded. Can you re-order your code to load the necessary component information before querying them? In my own code, I find that collecting the desired objects (components, bodies, curves, whatever) and querying/using them right away cuts down on a lot of issues.

I know you mentioned not wanting to use "Try-Catch" blocks, but there might not be a good alternative here. Why are you reluctant to use them?

Basically, my code is fetching all unloaded components that should load (I've been developing an alternative to bookmarks). I have been considering loading layer by layer (all grandparents, then all parents, then all children, etc...), but that really slows down the loading process for some unknown reason. I've encountered this "is not alive" exception outside of components, but I can't immediately remember where else, I just know it's been a thorn in my side.

As for Try-Catch blocks, I've been learning to adhere to my company's standards and practices of software development. They'd really like to avoid Try-Catches as they're known to degrade performance and are a bandaid solution (in their words). I already have a class that holds all of the information for a desired component (to be transferred with .json files). I could add a Tag property myself, then when I got to call a component from a class instance, I can have the instance check its own Tag property before returning a component to pass into a method. Basically, I'd create my own Get_Tag() method.