Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Recent
    • Tags
    • Users
    • Login

    Finding multiple objects by name

    Scheduled Pinned Locked Moved SDK Help
    4 Posts 0 Posters 382 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      Helper
      last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          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(...) ?

          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

            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; \> }

            1 Reply Last reply Reply Quote 0
            • First post
              Last post