Notifications
Clear all

[Closed] SDK: isvalidnode equivalent??

I’ve just realized that I don’t know how to check whether a node has been deleted or not using the SDK. And it’s one of those days where I seem to be finding everything except what I need in the help and example files…

I know how to set up a callback to check when a node has been deleted, but that seems like overkill when all I am trying to do is something like

if (IsValidNode(myNode)) {
//...
}

Any tips?

16 Replies

Here’s the full MXS isDeleted() code from the SDK


 #define deletion_check_test(val)													\
 	(	(val)->ref_deleted ||														\
 		(	(val)->NumRefs() > 0 && ((val)->GetReference(0) == NULL) ) ||			\
 		(	(val)->NumRefs() > 0 &&													\
 			(val)->GetReference(0)->TestAFlag(A_IS_DELETED) &&						\
 			(	((val)->GetReference(0)->GetInterface(INODE_INTERFACE)==NULL) ||	\
 				(((INode*)(val)->GetReference(0))->GetTMController() == NULL) ||	\
 				(((INode*)(val)->GetReference(0))->GetParentNode() == NULL)			\
 			)																		\
 		)																			\
 	)
 

 

Maybe there’s an easier way to do it though? I’ve always just pulled from here for my checks.

How do I use it? When I try

if (deletion_check_test(myNode)) {
//...
}

it says

Error: class “INode” has no member “ref_deleted”

this check is for Value*

use only parts related to INode*

in short,
a INode is valid if flag A_IS_DELETED is not set and TM controller is not NULL.

if you are not taking in account max root nodes, node’s parent has not to be NULL

and of course the INode* pointer itself has to be not NULL

what does ‘valid node’ mean for you? in many situations ‘deleted’ node is still valid by the why

I guess I was thinking of IsValidNode in Maxscript terms. For my purposes here “valid” means a node which is a) not null and b) not deleted.

And I realized shortly after posting before that the example was for Value* instead of INode* … then I spent some time trying to cast or convert the node to a “Value” value, but didn’t have much luck with it.

It still seems a bit complicated to me, but at least I have it functioning now and understand how it works.

bool IsValidNode(INode* node)
{
	return (node) 
		&& !(Animatable*)node->TestAFlag(A_IS_DELETED) 
		&& node->GetTMController() 
		&& node->GetParentNode();
}



not tested! but the idea should be clear

1 Reply
(@malkalypse)
Joined: 1 year ago

Posts: 0

Well, I tested it (and it is clear), but noticed that if I create and store a node, then open a new scene in Max and run this function to check for that node, it crashes Max on the line

&& node->GetParentNode()

Translation to SDK.NET: (at least it seems working for deleted nodes)

        static public bool IsValidNode(IINode node)
        {
            //IsDeleted = 16384
            AnimatableFlags A_IS_DELETED = (AnimatableFlags)16384;
            return (node != null)
                && !(((IAnimatable)node).TestAFlag(A_IS_DELETED))
                && (node.TMController != null)
                && (node.ParentNode != null);
        }

Page 1 / 2