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
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Limit the doc.SearchObject() on the source document?

    Cinema 4D SDK
    r20 python
    2
    5
    642
    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.
    • B
      bentraje
      last edited by

      Hi,

      On my character rig, I have a line like this:
      hips_con = doc.SearchObject('hips_con)

      It works on the source document but once I reference the file it doesn't work since the file will now have a name of
      character_name::hips_con

      I can't delete the namespace entirely since there will be several character that have the same rig set-up in a single scene.
      So, is there a way to limit the doc.SearchObject() on the source document and not on the reference document?

      Thank you for looking at the problem.

      1 Reply Last reply Reply Quote 0
      • M
        m_adam
        last edited by m_adam

        Hi @bentraje could you be more specific or link a scene file example.

        You say namespace, but so far only Xref used namespace. You also talk about referencing the file which makes me thinking of an Xref.
        But since you speak about the character object, which also uses some kind of virtual document.
        I'm not sure.

        Cheers,
        Maxime.

        MAXON SDK Specialist

        Development Blog, MAXON Registered Developer

        1 Reply Last reply Reply Quote 1
        • B
          bentraje
          last edited by

          Hi @m_adam

          Thanks for the response.
          Sorry for the confusion.
          Yes, I am talking with the Xref object when I mentioned "referenced file"
          and No, I'm not talking about character object. I just mentioned character. As in my character in general.

          Please see the illustration file below:
          https://www.dropbox.com/s/c5297hvjspal63i/c4d108_localized_python_command.rar?dl=0

          In the source file, it prints the BaseObject since it found the object
          In the reference file, it should print also the BaseObject but it finds none because of the namespace.

          That is why I am looking to limit the doc.SearchObject function on the source document and not on the file it is referenced.

          Is there a way around this?

          Thank you.

          1 Reply Last reply Reply Quote 0
          • M
            m_adam
            last edited by

            Hi @bentraje, you actually have to handle it yourself.
            Here is an example

            import c4d
            
            
            def main():
                nameToSearch = "Cube"
                
                # Retrieves the parent object of the host object
                parent = op.GetObject().GetUp()
                xref = None
                
                # Iterates overs each parent
                while parent:
                    # if it's an xref, break and store it
                    if parent.CheckType(1025766):
                        xref = parent
                        break
                    
                    parent = parent.GetUp()
                
                # If an xref is defined then retrieve the namespace
                if xref is not None:
                    namespace = xref[c4d.ID_CA_XREF_NAMESPACE]
                    nameToSearch = namespace + "::" + nameToSearch
            
                # Search the object
                Cube = doc.SearchObject(nameToSearch)
                print Cube
            

            Remember if you simply want to access the host object you can call BaseTag.GetObject from the python tag.

            If you have any question, please let me know.
            Cheers,
            Maxime.

            MAXON SDK Specialist

            Development Blog, MAXON Registered Developer

            1 Reply Last reply Reply Quote 3
            • B
              bentraje
              last edited by

              @m_adam

              I have a handful of doc.SearchObject() so I was looking for an easier route.
              I guess there is no way around it except concatenating strings.

              Anyhow, thanks for the code and confirmation.

              Will tag this thread as closed.

              Have a great day ahead!

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