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

    How to replace object with another

    Scheduled Pinned Locked Moved PYTHON Development
    3 Posts 0 Posters 214 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

      On 14/10/2015 at 15:02, xxxxxxxx wrote:

      Hello,
      Once again. I need your help!
      How to replace "char" with "Not Found object" if char not exist ? **** (see image below) ****


      **
      Script :**

       import c4d  
        
      def main() :  
            
          obj_parent = doc.SearchObject("Parent")  
            
          String = "Hello World"  
          iChar = 0  
            
          if iChar < len(String) :  
                
              for char in String:  
                  newChar = doc.SearchObject(char).GetClone()  
                  newChar.SetName(newChar.GetName() + '.temp' )  
                  doc.InsertObject(newChar, parent=obj_parent)
      
      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        On 14/10/2015 at 19:30, xxxxxxxx wrote:

        Pending a solution I use this :

        if doc.SearchObject(char) == None:
           continue

        full Script:

         -----------------------------------------------  
        import c4d  
          
        def main() :  
              
            obj_parent = doc.SearchObject("Parent")  
              
            String = "Hello World"  
            iChar = 0  
              
            if iChar < len(String) :  
                  
                for char in String:  
                    if doc.SearchObject(char) == None:  
                        continue  
                    newChar = doc.SearchObject(char).GetClone()  
                    newChar.SetName(newChar.GetName() + '.temp' )  
                    doc.InsertObject(newChar, parent=obj_parent)
        
        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          On 15/10/2015 at 09:04, xxxxxxxx wrote:

          Hi,

          I'm actually not quite sure, where you are heading. I don't see a replace operation in your code. What is so bad about your solution presented in second post? In what way does it work different from what you expect?
          For the code in your second post, I'd recommend to do the SearchObject() only once, although the speed difference will probably only in very large and complex scenes.

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