[Closed] getClassInstances but in SDK??
does anyone know the equivalent of*getClassInstances in the SDK?
Thanks
There is a function in the class Animatable that you can use to get all the animatables, then you can iterate in those animatables comparing the Class_ID with the one that you are looking for to get all the instances of that class, you could use the Super_Class_ID too just to make sure (because there could be animatables with same class_ID but different Super_Class_ID, although i think the probabilities of that happening are almost zero).
This is the function:
Animatable::EnumerateAllAnimatables
There is also this function:
Animatable::EnumAnimTree
You can find those in the reference for more details.
I’m a bit lost on this looking though “Animatable class” to find class instances? I have looked though the samples forAnimatable::EnumerateAllAnimatables and*Animatable::EnumAnimTree but not much there. *
I’m basically looking for a fast way to traverse a scene to fetch class objects to find missing links…*
missingXmesh = for i in (getClassInstances XMeshLoader) where (not(doesFileExist i.renderSequence)) and (i.renderSequence != “”) collect (missingFile asset:i filenameFieldPropertyName:“renderSequence”)
i dont find a similar function of getClassInstances in the SDK, but reading the reference of maxscript that function uses the Animatable::EnumAnimTre function to do its job, and probably using the function Animatable::EnumerateAllAnimatables when the parameter processAllAnimatables is on.
Until3ds Max 2011, the function was looking for the class instances by enumerating the animatable tree. There are many cases where the subAnims of an object are a subset of the references held by an object, so instances present in the scene were being missed.
Starting with3ds Max 2011,*getClassInstances()*can search for class instances in a variety of ways depending on its arguments, including the two new ones:processAllAnimatables:andprocessChildren:.
so yes that seems to be the only way to get all the instances of a class, first retrieve all the animatables using Animatable::EnumAnimTree. If you want to get all the instances, not only the ones in the scene but also others stored in maxscript variables for example you have to use Animatable::EnumAllAnimatables.
Then iterate in the animatables comparing the classid to get the one you looking for. So in your case you are looking for instances of XMeshLoader, so you have to get the classid of that first, you can do that with in maxscript *like so:
XMeshLoader.classid
i dont have XMesh installed in my machine so i can’t see which classid is. but you have to have in mind that the format of the classid in maxscript is different than in C++
for example:
maxscript: #(12345678,12345678) – in some versions of max the numbers come with an L at the end which has to be removed in C++
C++: Class_ID(12345678,12345678)
then when you have the animatables of all *the XMeshLoaders in the scene the only way to access the parameters that you need is using the parameter blocks directly, i don’t think there is a C++ interface that you can use, so that is the way to go.
i leave you with this basic explanation because giving you all the code doing this can take me a while, sorry.
Thanks for your input. *This is what I was using to traverse my scene nodes. *I will go through and check out the Animatable::EnumAllAnimatables *options
void SplineTools::TraverseGroups(INode* node, TimeValue t) {
int n;
Object* obj = node->EvalWorldState(t).obj;
if (obj) {
GroupTab.AppendNode(node);
}
n = node->NumberOfChildren();
for (int i = 0; i < n; i++) {
TraverseGroups(node->GetChildNode(i), ip->GetTime());
}
}
void SplineTools::SortNodes() {
int MyCount = 0;
for (int i = 0; i < AllNodes.Count(); i++) {
GroupTab.Delete(0, GroupTab.Count());
INode* node = AllNodes[i];
const ObjectState& os = node->EvalWorldState(t);
Object* obj = os.obj;
Object* BaseObj = obj->FindBaseObject();
if (obj->SuperClassID() == GEOMOBJECT_CLASS_ID) {
if (BaseObj->ClassID() == VRAYPROXY_CLASS_ID) {
MyCount++;
}
}
}
MCHAR Debug[256];
mprintf(_T("VrayProxy Count: %i
"), MyCount);
mflush();
}
void SplineTools::Si_Test() {
TraverseNode(ip->GetRootNode(), t);
SortNodes();
}
thanks again
Si
Hi*phoelix,
There is not a lot on this in the samples? *Could you give a little inside on how you use this?
ReferenceMaker* scene = GetCOREInterface()->GetScenePointer();
AnimEnum *a = ?
scene->EnumAnimTree(&a, NULL, 0);
You have to create a class derived from AnimEnum, and use the proc function to collect the classes.
Here is an example but i used the Animatable::EnumerateAllAnimatables with the class EnumAnimList, because it was easier to use and i am 100% sure i am getting everything, a class instance can be in the scene but it could be hidden from the anim tree, and also with the EnumAnimTree i had to iterate through all the nodes using the function (too much of a hassle).
Also i included the super class ID, it’s better to be 100% sure. so if you want to get the super class id of the XMeshLoader, in the maxscript listener execute XMeshLoader.superclassid
//Function to retrieve all the animatables in the scene with the provided super class id and class id
Tab<Animatable*> GetClassInstances(SClass_ID theSClassID, Class_ID theClassID)
{
//a class derived from EnumAnimList has to be created to be used with the Animatable::EnumerateAllAnimatables
//function, this class will collect the animatables that have the same super class id and class id
//as the ones provided
class ClassEnum : public Animatable::EnumAnimList
{
SClass_ID theSClassID;
Class_ID theClassID;
public:
Tab <Animatable*> theAnims;
ClassEnum(SClass_ID sClassID, Class_ID classID)
{
theSClassID = sClassID;
theClassID = classID;
}
//the collect is done here
bool proc(Animatable *theAnim)
{
if (theAnim->SuperClassID() == theSClassID && theAnim->ClassID() == theClassID)
theAnims.Append(1, &theAnim);
return ANIM_ENUM_PROCEED;
}
};
//initialize the Enumerator with the super class id and class id
ClassEnum theClassEnum(theSClassID, theClassID);
//start the enumeration
Animatable::EnumerateAllAnimatables(theClassEnum);
//return the found animatables
return theClassEnum.theAnims;
}
you do know the source code for getClassInstances is in the sdk don’t you ?
Lol
that’s right, it’s in the avg_dlx.cpp and yes it uses the same animatable functions to do the job