SOLVED MCOMMAND_JOIN issue

Hello PluginCafe 🙂

I need to merge 2 objects in OBJECT_GENERATOR plugin and return the result but it returns only 1 object. my code looks like this. Am I doing something wrong?

import c4d, os
from c4d import plugins, utils, Vector as v

class Otest(c4d.plugins.ObjectData):
    def GetVirtualObjects(self, op, hh):
        
        virtualDoc = c4d.documents.BaseDocument()

        cube1 = c4d.BaseObject(c4d.Ocube)
        cube1.SetAbsPos(v(0,0,110))
        virtualDoc.InsertObject(cube1)

        cube2 = c4d.BaseObject(c4d.Ocube)
        cube2.SetAbsPos(v(0,0,-110))
        virtualDoc.InsertObject(cube2)

        virtualDoc.ExecutePasses(c4d.threading.GeGetCurrentThread(), True, True, True, c4d.BUILDFLAGS_INTERNALRENDERER)
        
        output = utils.SendModelingCommand(command = c4d.MCOMMAND_JOIN, doc = virtualDoc, list = [cube1,cube2])[0]
        return output

if __name__ == "__main__":
    plugins.RegisterObjectPlugin(id = 1000000, 
                                 str = "Test", 
                                 g = Otest, 
                                 description = None, 
                                 info = c4d.OBJECT_GENERATOR, 
                                 icon = None)

Hi @merkvilson; MCOMAND_JOIN have changed in R18, now objects have to be under the same hierarchy.
See Behaviour of MCOMMAND_JOIN different in R18 or [Python] SendModelingCommand().

Cheers,
Maxime.

You have to combine objects to null, for example:

import c4d
from c4d import gui

def smc(listy):
    null = c4d.BaseObject(c4d.Onull)

    for o in listy:
        o.InsertUnder(null)

    res = c4d.utils.SendModelingCommand(command = c4d.MCOMMAND_JOIN,
                                    list = [null],
                                    mode = c4d.MODELINGCOMMANDMODE_ALL,
                                    bc = c4d.BaseContainer(),
                                    doc = doc)
    return res[0]

def main():
    obs = doc.GetActiveObjects(0)
    doc.InsertObject(smc(obs))
    c4d.EventAdd()

if __name__=='__main__':
    main()

Thanks guys!
It worked!
I had to double-check this in SDK 😁

btw. is it possible to sort the search results by date? I was getting 8 years old posts when looking for this topic.

For sure go to https://plugincafe.maxon.net/search (you can also access this page by clicking on the little bolts/nuts which appears after a click on the top search bar.)

Then on this page, you can define more option to search, and you can decide which kind of sorting you prefer.

Cheers,
Maxime.

Thanks, buddy. Will take this into account 👌

Finally please do not forget to mark your topic as solved. See Q&A Functionality 😉 .

@m_adam

I was looking for "Solved" option in tags section but could not find it.

Finally, I figured this out.
Seems like this is because my browser's zoom is set to 150%

alt text

Hi,
thanks for pointing out this issue. We'll see if can get a fix for that (not all tags visible, if zooming in with browser).
In the end Maxime wasn't referring to tags at all. Instead he was talking about the Q&A Function we have in this forum. I took the freedom to mark this thread as solved (see this shiny green stamp next to the headline ☺ ).
Cheers,
Andreas