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

    preset children of objects?

    Cinema 4D SDK
    2
    5
    670
    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.
    • JH23J
      JH23
      last edited by

      Hi
      I have been working on a userdata button that places a preset in the environment, I also wanted to put it inside the end of a joint, my problem is that when performing these steps, when going back the preset is outside the joint, the code generates the preset and then place it inside the board, is there a way to do it directly?

      1 Reply Last reply Reply Quote 0
      • ManuelM
        Manuel
        last edited by

        Hi,

        If i understand, you have two undo stack? Or must press twice undo to retrieve the document as it was before pressing the button?
        sharing some code would help a bit. I'm not sure how you add the object in the scene and how you create your new entry in the undo stack.

        Cheers,
        Manuel

        MAXON SDK Specialist

        MAXON Registered Developer

        JH23J 1 Reply Last reply Reply Quote 0
        • JH23J
          JH23 @Manuel
          last edited by

          @m_magalhaes

          Hi

          in itself the problem is that when performing the complete action when going back the object is outside the father, since it was first created and later placed inside the father

          import c4d
          from c4d import documents, plugins
          
          def main():
              c4d.documents.MergeDocument(doc,"file location",7) #the preset has already been added
              doc.StartUndo()
              child = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_NONE)
              for A in child:
                  doc.AddUndo(c4d.UNDOTYPE_CHANGE, A)
                  A.InsertUnder(father)#the parent would be defined by a link
              doc.EndUndo()
              c4d.EventAdd()
          

          I did this since when adding the preset it is already selected, use this to place it inside another object

          1 Reply Last reply Reply Quote 0
          • ManuelM
            Manuel
            last edited by

            Hi,

            you should start the undo before merging the "preset" you want to add, and add the document to its own undo stack. just like this

              
                doc.StartUndo()
                doc.AddUndo(c4d.UNDOTYPE_CHANGE, doc)
                
                res = c4d.documents.MergeDocument(doc,"file",c4d.SCENEFILTER_OBJECTS | c4d.SCENEFILTER_MATERIALS) 
            
            

            By the way you should never use "magic number" instead of flags. In that case SCENEFILTER_OBJECTS | SCENEFILTER_MATERIALS is the same as 3. There's no flag that have the value of 4 so 7 mean nothing more than 3.

            Cheers,
            Manuel

            MAXON SDK Specialist

            MAXON Registered Developer

            1 Reply Last reply Reply Quote 0
            • JH23J
              JH23
              last edited by

              Hi
              Thank you for solving my question, and thank you very much also for the advice.

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