Hello @Kantronin,
Thank you for reaching out to us. Your script does not work because it does not follow the conditions of MCOMMAND_JOIN.
Joins the objects that are parented to the passed null object. Passing multiple objects into SMC will not join them.
edit: Moved this into the correct forum and added a small example.
Cheers,
Ferdinand
Here is how I would write that in modern Cinema 4D. I have seen that your screenshot is from an older version such as S26, or even older, but I cannot write code examples for such old versions. There are multiple things that wont work in such old version such as type hinting and the mxutils lib, but you will be able to copy the general approach - move everything under a null while preserving the transforms.
Code """Demonstrates how to join all objects in a document. """ import c4d import mxutils doc: c4d.documents.BaseDocument # The currently active document. op: c4d.BaseObject | None # The primary selected object in `doc`. Can be `None`. def main() -> None: """Called by Cinema 4D when the script is being executed. """ # There is no super good way to do this in the manner you implied, joining everything in a # document. I clone here the whole document, which is not the cheapest operation (but also # not as expensive as it may sound like). When we do not have to join everything, it is better # just to clone the things you want to join. En even better way could be to not clone anything # and instead use undos to revert the transform and hierarchy changes we have to make. temp: c4d.documents.BaseDocument = doc.GetClone(c4d.COPYFLAGS_NONE) firstObject: c4d.BaseObject | None = temp.GetFirstObject() if firstObject is None: c4d.gui.MessageDialog("No object selected.") return # Get all objects in the document, and move them under a null object. We must record and # restore their global matrices, when we deconstruct the scene and move it all under one null # object. allObjects: list[c4d.BaseObject] = list(mxutils.IterateTree(firstObject, True)) null: c4d.BaseObject = mxutils.CheckType(c4d.BaseObject(c4d.Onull)) for obj in allObjects: mg: c4d.Matrix = obj.GetMg() # save the transform of the object obj.Remove() # Technically not necessary in the Python API, as it will do it for you when # you call things like InsertUnderLast. But C++ will not do that and a node # cannot be inserted more than once in a document, otherwise the fireworks # will start. obj.InsertUnderLast(null) obj.SetMg(mg) # restore the transform of the object under the null # Insert the null object into the temporary document and then join all objects under it. temp.InsertObject(null) result: list[c4d.BaseObject] = c4d.utils.SendModelingCommand( command=c4d.MCOMMAND_JOIN, list=[null], doc=temp, mode=c4d.MODELINGCOMMANDMODE_ALL, ) if not result: c4d.gui.MessageDialog("Failed to join objects.") return # Now insert the joined object into the original document. joinedObject: c4d.BaseObject = result[0] joinedObject.SetName("Joined Object") joinedObject.Remove() doc.InsertObject(joinedObject) c4d.EventAdd() if __name__ == '__main__': main()