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

    Create Cloner with Effector inside InExcludeData

    Scheduled Pinned Locked Moved PYTHON Development
    14 Posts 0 Posters 1.8k 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 18/12/2017 at 02:41, xxxxxxxx wrote:

      I tried this with Tracer object but it's not working.

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

        On 18/12/2017 at 09:31, xxxxxxxx wrote:

        Hello,

        the MoGraph system is highly complex and interconnected. In this case the tracer object expects a full initiated matrix object. But this matrix object cannot be fully set up in the cache of a generator, only in a BaseDocument. With this generator the matrix object is re-created all over again and in this case that's bad.

        The only solution I see right now is to create a virtual BaseDocument, copy all needed objects into that BaseDocument, execute it and get he objects in their final state from that document.

        best wishes,
        Sebastian

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

          On 18/12/2017 at 12:11, xxxxxxxx wrote:

          How can I create virtual document? are there any examples in docs?

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

            On 18/12/2017 at 12:59, xxxxxxxx wrote:

            virtualDoc = c4d.documents.BaseDocument()
            virtualDoc.InsertObject(finalResult)
            

            Then Execute pass and in your data simply return a clone of your object, since object will be owned by your virtual (tempory,buffer) document and it will be free at the end of your scope, so all objects will be deleted that belong to this document will be deleted (aka object not alive).

            Hope its help 😉

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

              On 18/12/2017 at 13:17, xxxxxxxx wrote:

              Thank you again 🙂
              I'm getting this error. Am I doing something wrong?

              Traceback (most recent call last) :
                File "'Python Generator'", line 4, in main
              AttributeError: 'module' object has no attribute 'BaseDocument'

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

                On 18/12/2017 at 14:01, xxxxxxxx wrote:

                Sorry I'm on phone. Use c4d.documents.BaseDocument()

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

                  On 18/12/2017 at 14:17, xxxxxxxx wrote:

                  Thank buddy! you helped as always 🙂 Now I'm a bit closer to the desired result.

                  just getting this error.
                  ReferenceError: the object 'c4d.BaseObject' is not alive

                    
                    1. import c4d
                    2.   
                    3.   
                  
                  
                  1 Reply Last reply Reply Quote 0
                  • H Offline
                    Helper
                    last edited by

                    On 18/12/2017 at 14:30, xxxxxxxx wrote:

                    Originally posted by xxxxxxxx

                    Then Execute pass and in your data simply return a clone of your object, since object will be owned by your virtual (tempory,buffer) document and it will be free at the end of your scope, so all objects that belong to this document will be deleted (aka object not alive).

                    tracer[c4d.MGTRACEROBJECT_OBJECTLIST] = inexclude
                      
                    virtualDoc.ExecutePasses(c4d.threading.GeGetCurrentThread(), True, True, True, c4d.BUILDFLAGS_INTERNALRENDERER)
                    finalResult = finalResult.GetClone()
                    return finalResult
                    

                    Still on phone so there may still have some issues. if yes I will fix them tomorow.

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

                      On 18/12/2017 at 15:12, xxxxxxxx wrote:

                      It's not working but at least I learned something new from your code 😄
                      I appreciate your help!
                      Cheers! 🙂

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

                        On 19/12/2017 at 05:55, xxxxxxxx wrote:

                        For me everythings is working fine

                        import c4d
                          
                        def CurrentStateToOBject(doc, objList) :
                            if not doc:
                                raise ValueError("Document is not valid")
                            
                            returnValue = c4d.utils.SendModelingCommand(
                                 command = c4d.MCOMMAND_CURRENTSTATETOOBJECT,
                                 list = objList,
                                 mode=c4d.MODELINGCOMMANDMODE_ALL,
                                 bc=c4d.BaseContainer(),
                                 doc = doc)
                            
                            if returnValue:
                                return returnValue
                            else:
                                return None
                          
                        def main() :
                            # Create object
                            virtualDoc = c4d.documents.BaseDocument()
                            nullMaster = c4d.BaseObject(c4d.Onull)
                            matrix = c4d.BaseObject(1018545)
                            tracer = c4d.BaseObject(1018655)
                            downClone = op.GetDown().GetClone()
                            
                            # Insert all objects
                            virtualDoc.InsertObject(nullMaster)
                            virtualDoc.InsertObject(downClone)
                            matrix.InsertUnder(nullMaster)
                            tracer.InsertUnder(nullMaster)
                            
                            # Set options
                            matrix[c4d.ID_MG_MOTIONGENERATOR_MODE] = 0
                            matrix[c4d.MG_OBJECT_LINK] = downClone
                            
                            tracer[c4d.MGTRACEROBJECT_MODE] = 2
                            inexclude = c4d.InExcludeData()
                            inexclude.InsertObject(matrix,15)
                            tracer[c4d.MGTRACEROBJECT_OBJECTLIST] = inexclude
                            
                            virtualDoc.ExecutePasses(c4d.threading.GeGetCurrentThread(), True, True, True, c4d.BUILDFLAGS_INTERNALRENDERER)
                          
                            # Convert the Tracer to spline
                            finalResult = CurrentStateToOBject(virtualDoc, [tracer])
                            if finalResult is None: return
                          
                            # Insert spline under a null and return it
                            nullFinal = c4d.BaseObject(c4d.Onull)
                            finalResult[0].InsertUnder(nullFinal)
                          
                            return nullFinal
                        

                        LinkField can work only if both objects (the one that got the linkField and the one that is pointed by this link) are on the same document. If they are on different doc, c4d will automaticly set them the LinkField to None.
                        Matrix object is just some matrix, not an object, basicly you need a cloner in top of a matrix object if you want to see some geometry. And of course make editable doesn't have so much sense into a matrix.

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

                          On 20/12/2017 at 19:44, xxxxxxxx wrote:

                          Thanks gr4ph0s!
                          It's working 🙂
                          I learned lots of new stuff from these codes.

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