Getting the Nodes that Reference an Object
Every object is referenced by one or more INode
s. To find the first INode
in the dependency graph that references an object by sending a reference message REFMSG_GET_NODE_HANDLE
to its dependents using ReferenceTarget::NotifyDependents()
. This will retrieve a handle of the first node that references the object. Using the method Interface::GetINodeByHandle()
a node can then be retrieved.
INode* GetNodeFromObject(BaseObject* obj) {
ULONG handle = 0;
rm->NotifyDependents(FOREVER, (PartID)&handle, REFMSG_GET_NODE_HANDLE);
INode *node = GetCOREInterface()->GetINodeByHandle(handle);
return node;
}
ITo find all of the nodes that reference an object use the instancemanager's IInstanceMgr::GetInstances()
method passing it the INode
thatyou have acquired. A pointer to a global instance of IInstanceMgr
can be retrieved using the static member function: IInstanceMgr::GetInstanceMgr()
.
void GetAllReferencingNodes(BaseObject* obj, INodeTab& nodes) {
INode* node = GetNodeFromObject(obj);
DbgAssert(node != NULL); // should never be NULL
IInstanceMgr::GetInstanceMgr()->GetInstamces(*node, nodes);
}