Determine object category (Generator, Deformer, etc.) via Python
-
Hi everyone, long time no see!
I'm currently using
c4d.utils.ViewportSelect.PickObject
to pick the object under the mouse cursor, and then I want to determine which category it belongs to—such as Polygon Object, Deformer, or Generator. I'm referring to the kind of classification used in the Selection Filter, not thec4d.Obase
type.I thought about manually creating Python lists containing all the IDs for Generators, Deformers, Fields, etc., but that seems cumbersome and hard to maintain.
So my question is: is there a way to determine which high-level category (like those in the Selection Filter) a given object belongs to?
-
Hey the internal function is not exposed in Python neither in C++. Sadly the function also use a function that is only exposed in C++ with no proper workaround.
Here is the C++ implementation of the function
inline cinema::OBJECTCATEGORY ObjectToCategory(const cinema::BaseObject& object) { return ObjectToCategory(object.GetType(), object.GetInfo()); } inline cinema::OBJECTCATEGORY ObjectToCategory(cinema::Int32 type, cinema::Int32 objectInfo) { cinema::OBJECTCATEGORY category = cinema::OBJECTCATEGORY::OTHER; switch (type) { case Oweighteffector: category = cinema::OBJECTCATEGORY::DEFORMER; break; // FIX[4850] case Ojoint: category = cinema::OBJECTCATEGORY::JOINT; break; // FIX[4853] case Onull: category = cinema::OBJECTCATEGORY::NULLOBJECT; break; case Opolygon: category = cinema::OBJECTCATEGORY::POLYGON; break; case Osds: category = cinema::OBJECTCATEGORY::HYPERNURBS; break; case Ocamera: case Orscamera: category = cinema::OBJECTCATEGORY::CAMERA; break; case Olight: case Orslight: category = cinema::OBJECTCATEGORY::LIGHT; break; case Oenvironment: case Oforeground: case Obackground: case Ofloor: case Osky: case Ostage: case Oselection: category = cinema::OBJECTCATEGORY::SCENE; break; case Oworkplane: category = cinema::OBJECTCATEGORY::GRID; break; case 1001414: // ID_TP_PARTICLEGEOMETRY case Ofpgroup: // new particle group case Ofpmultigroup: // new particle multi group case Oparticle: category = cinema::OBJECTCATEGORY::PARTICLE; break; case Ovolume: case Osimulationscene: // ITEM#128166 Alembic: Viewport and Selection Filter recognizes it as Spline case Oalembicgenerator: category = cinema::OBJECTCATEGORY::GENERATOR; break; // ITEM#9437 MoGraph and Spline Display Filter case Omgcloner: category = cinema::OBJECTCATEGORY::GENERATOR; break; // Omgcloner case Ohair: category = cinema::OBJECTCATEGORY::HAIR; break; // Ohair default: { // This function is not exposed in Python, so use objectInfo directly if (!cinema::C4DOS_Bo->ObjectTypeToCategory(type, category)) { // ITEM#133494 Spline filter doesn't filter splines // i gave ISSPLINE the highest priority back and added switches for alembic and cloner generators above if (objectInfo & OBJECT_ISSPLINE) category = cinema::OBJECTCATEGORY::SPLINE; else if (objectInfo & OBJECT_GENERATOR) category = cinema::OBJECTCATEGORY::GENERATOR; else if (objectInfo & OBJECT_MODIFIER) category = cinema::OBJECTCATEGORY::DEFORMER; else if (objectInfo & OBJECT_PARTICLEMODIFIER) category = cinema::OBJECTCATEGORY::PARTICLE; else if (objectInfo & OBJECT_FIELDOBJECT) category = cinema::OBJECTCATEGORY::FIELD; } break; } } return category; }
With that's said I've made a note for myself to implement this function in Python (no ETA).
Cheers,
Maxime. -
Thank you for the C++ code—it's been very helpful!
Cheers!