Finding multiple objects by name
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 14/08/2009 at 01:03, xxxxxxxx wrote:
User Information:
Cinema 4D Version: R11
Platform: Windows ; Mac OSX ;
Language(s) : C++ ;---------
Hello,
is there a convenient way to get all objects with a specific name or do I have to traverse the scene graph "manually"?In my specific case I try to get the first camera with a given name.
Cheers.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 14/08/2009 at 02:39, xxxxxxxx wrote:
To elaborate on this, the following would solve my needs:
>
\> /\* helper function for SearchObject \*/ \> static BaseObject\* \_SearchObject(BaseObject\* node, const String& name, LONG type) \> { \> if (!node) \> return NULL; \> \> if (node->GetType() == type && node->GetName() == name) \> return node; \> \> BaseObject\* result = \_SearchObject(node->GetDown(), name, type); \> \> if (!result) \> result = \_SearchObject(node->GetNext(), name, type); \> \> return result; \> } \> \> \> /\* Return first object with given name and type or NULL. \*/ \> BaseObject\* SearchObject(BaseDocument\* doc, const String& name, LONG type) \> { \> return \_SearchObject(doc->GetFirstObject(), name, type); \> } \>Is this the way to go? Or has the SDK something ready to use?
Cheers.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 14/08/2009 at 04:43, xxxxxxxx wrote:
Maybe BaseDocument::SearchObject(...) ?
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 14/08/2009 at 05:27, xxxxxxxx wrote:
If you only need the first object with a specific name, BaseDocument::SearchObject() will work. Just check the type returned afterwards. The problem that I can see here is that if there is another object before the camera with the same name, this will always fail.
I tend to write my own little recursive routines for this type of thing. To save stack, a loop for GetNext() is best:
>
/\* helper function for SearchObject \*/ \> static BaseObject\* \_SearchObject(BaseObject\* node, const String& name, const LONG& type) \> { \> BaseObject\* result; \> for (; node; node = node->GetNext()) \> { \> if (node->GetType() == type && node->GetName() == name) \> return node; \> if (node->GetDown()) \> { \> result = \_SearchObject(node->GetDown(), name, type); \> if (result) return result; \> } \> } \> return NULL; \> }