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
    The forum rollback caused push notifications and recent user data to malfunction. The problem will fix itself naturally within the next days. See the topic Broken Push Notifications for a more in detail explanation. You can fix this yourself by forcibly clearing your browser cache (for most browsers: CTRL + F5).

    My goal is to Export all the Child objects in a Cloner as individual STL files.

    Cinema 4D SDK
    2
    3
    558
    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.
    • J
      jrpmedia
      last edited by jana

      My goal is to Export all the Child objects (or the top group) in a Cloner as individual STL files.

      Here is my initial code to simply list the Child items.
      But I get syntax errors for lines 32, 29 and 4 even at this early stage 😞

      import c4d
      
      def list_cloner_children(obj):
          if obj is None or obj.GetType() != c4d.Ocloner:
              print("Please select a Cloner object.")
              return
      
          children = obj.GetChildren()
          if not children:
              print("The selected Cloner has no children.")
          else:
              print("Children of selected Cloner:")
              for child in children:
                  print("  ", child.GetName())
      
      def main():
          # Get the active document
          doc = c4d.documents.GetActiveDocument()
          if doc is None:
              return
      
          # Get the first selected object
          selection = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_SELECTIONORDER)
          if not selection:
              print("No objects selected.")
              return
      
          selected_obj = selection[0]
      
          # List the children of the selected object
          list_cloner_children(selected_obj)
      
      if __name__ == '__main__':
          main()
      

      Always ...

      1 Reply Last reply Reply Quote 0
      • ferdinandF ferdinand moved this topic from General Talk on
      • i_mazlovI
        i_mazlov
        last edited by

        Hello @jrpmedia,

        Welcome to the Plugin Café forum and the Cinema 4D development community, it is great to have you with us!

        Getting Started

        Before creating your next postings, we would recommend making yourself accustomed with our Forum and Support Guidelines, as they line out details about the Maxon SDK Group support procedures. Of special importance are:

        • Support Procedures: Scope of Support: Lines out the things we will do and what we will not do.
        • Support Procedures: Confidential Data: Most questions should be accompanied by code but code cannot always be shared publicly. This section explains how to share code confidentially with Maxon.
        • Forum Structure and Features: Lines out how the forum works.
        • Structure of a Question: Lines out how to ask a good technical question. It is not mandatory to follow this exactly, but you should follow the idea of keeping things short and mentioning your primary question in a clear manner.

        About your First Question

        Please excuse delayed answer.

        The reason for the syntax errors is in using nonexistent type constant, it should be c4d.Omgcloner.

        The way you described your goal can be interpreted in different ways resulting in different approaches. Please try to give more details to decrease the amount of ambiguity in your next postings. We've also reformatted your posting, please try using formatting "code" block for when pasting code snippets.

        If you like to export the child reference objects from your cloner, then your code snippet would work just fine. The last missing piece there would be exporting children individually. For that I can recommend an approach to create a new BaseDocument, copy your child over to there using GetClone() and then export this document using c4d.documents.SaveDocument(). You should, however, be careful with such approach as cloning objects can have side effects due to dependencies they have, AliasTrans might be something of interest for you in this scenario.

        If you on the other hand, want to export actual objects generated by cloner, then you can try making use of MCOMMAND_MAKEEDITABLE command. Please find the snippet showing this approach below. You can also find check there the usage of the aforementioned functions.

        Cheers,
        Ilia

        Cinema_4D_jacvfZnL81.gif

        Code:

        import c4d, typing, os
        
        def main(outputDirectory: str):
        	doc: c4d.documents.BaseDocument = c4d.documents.GetActiveDocument()
        
        	# Get the first selected object
        	currentSelectedObjs: list[c4d.BaseList2D] = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_SELECTIONORDER)
        	if not currentSelectedObjs:
        		return print("No objects selected.")
        	
        	# Check if active object is cloner
        	if currentSelectedObjs[0] is None or currentSelectedObjs[0].GetType() != c4d.Omgcloner:
        		return print("Please select a Cloner object.")
        	
        	# Clone document to avoid corrupting original data
        	docClone: c4d.documents.BaseDocument = doc.GetClone(c4d.COPYFLAGS_NONE)
        	selectedObjs: list[c4d.BaseList2D] = docClone.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_SELECTIONORDER)
        	if not selectedObjs or selectedObjs[0] is None or selectedObjs[0].GetType() != c4d.Omgcloner:
        		return print("Something went wrong")
        	
        	# Bake cloner objects
        	selectedObj: c4d.BaseList2D = selectedObjs[0]
        	res: list[c4d.BaseList2D] | bool = c4d.utils.SendModelingCommand(c4d.MCOMMAND_MAKEEDITABLE, [selectedObj])
        	if not isinstance(res, list) or not res:
        		return print("Couldn't execute Make Editable command")
        	
        	# Iterate over baked cloner children
        	for obj in res[0].GetChildren():
        		docTemp: c4d.documents.BaseDocument = c4d.documents.BaseDocument()
        		docTemp.InsertObject(obj.GetClone(c4d.COPYFLAGS_NONE))
        		filePath: str = os.path.join(outputDirectory, obj.GetName() + '.stl')
        		print(f'Saving object {obj.GetName()} to {filePath}')
        		c4d.documents.SaveDocument(docTemp, filePath, c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST, c4d.FORMAT_STL_EXPORT)
        
        if __name__ == '__main__':
        	main(r'D:\\temp\\')
        

        MAXON SDK Specialist
        developers.maxon.net

        1 Reply Last reply Reply Quote 0
        • J
          jrpmedia
          last edited by

          Thank you Ilia,
          Let me digest your extremely kind advice and example, learn from it, and come back tom you.
          Kind regards,
          James.

          Always ...

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