Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware 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
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Get object by active tag in Python

    Cinema 4D SDK
    python
    3
    5
    1.0k
    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.
    • S
      stanDM
      last edited by

      Hi,

      I am able to retrieve a list of all selected tags in scene via doc.GetActiveTags(), but now I need to get a list of objects linked to those active tags and because objects are not selected themselves, doc.GetActiveObject() gives you Null. Is it somehow possible in Python? I guess the must be some BaseLink relation between selected tag and its object, just could not find any real world example.

      Thanks for any help!

      1 Reply Last reply Reply Quote 0
      • CairynC
        Cairyn
        last edited by

        BaseTag.GetObject(self)

        1 Reply Last reply Reply Quote 1
        • S
          stanDM
          last edited by

          Cool, thanks!

          ferdinandF 1 Reply Last reply Reply Quote 0
          • ferdinandF
            ferdinand @stanDM
            last edited by

            Hello @stanDM,

            thank you for reaching out to us. And thank you @Cairyn for providing an answer. There is not much to add for us here, except for making the answer a bit more formal.

            Polyhierarchical scene graph information is being expressed as branches in Cinema 4D and accessible through GeListNode.GetBranchInfo(). To 'move up one level' in such polyhierarchical relation, there is the general purpose method BaseList2D.GetMain() which will return the object for a tag, the material for a shader, etc. There is also the convenience method BaseTag.GetObject() of BaseTag which returns the object the tag is attached to. It will return the same entity as BaseList2D.GetMain(). Find below a short example for a Python Programming Tag.

            Cheers,
            Ferdinand

            The output:

            op = <c4d.BaseTag object called Python/Python with ID 1022749 at 2768059772160>
            obj = <c4d.BaseObject object called Cube/Cube with ID 5159 at 2768059772416>
            branchedFrom =<c4d.BaseObject object called Cube/Cube with ID 5159 at 2768059771904>
            (obj == branchedFrom) = True
            >>> 
            

            The code:

            """Example for retrieving the object a tag is attached to.
            
            This example is designed for a Python Programming Tag. The module attribute 
            `op` is predefined in this context as the `BaseTag` that is the Programming 
            Tag calling this Python module.
            """
            
            import c4d
            
            def main():
                """Called on tag evaluation.
                """
                print (f"{op = }")
            
                # Get the attached object.
                obj = op.GetObject()
                if obj is None:
                    raise RuntimeError(f"Illegal scene state for: {op}")
                print (f"{obj = }")
            
                # The more general method to retrieve the node another node did branch
                # from. The referenced object is exactly the same as for `op.GetObject()`.
                branchedFrom = op.GetMain()
                if branchedFrom is None:
                    raise RuntimeError(f"Illegal scene state for: {op}")
                print (f"{branchedFrom =}")
            
                print (f"{(obj == branchedFrom) = }")
            
            

            MAXON SDK Specialist
            developers.maxon.net

            1 Reply Last reply Reply Quote 0
            • ferdinandF
              ferdinand
              last edited by ferdinand

              Hello @stanDM,

              without any further questions or postings, we will consider this thread as solved by Friday the 4th, February 2022.

              Thank you for your understanding,
              Ferdinand

              MAXON SDK Specialist
              developers.maxon.net

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