"split and kill" script in R21?


#1

Hi,
the “Split”-command for polygons generates a new object containing only the selected polygons.
my little script to delete this polygons in the original object does not work anymore since in R21 the selected object is the new one.
is there a command for selecting the object above the current selected in the object manager which could be used in python?
Normally I copy the commands out of the script log but in this case it does not work.
Cheers
Simon


#2

The parent of an object can be easily obtained via:
obj.GetUp()

If you would like to have somebody, who knows a bit more about coding, take a look at your script, feel free to contact me via PM.


#3

Here’s our Split’n’Kill script:

import c4d
from c4d import utils

# Splits the current polygon selection into a new object
# and deletes it from the original object

def main():
    old = doc.GetActiveObject()
    c4d.CallCommand(14046, 14046) # Split
    new = doc.GetActiveObject()
    doc.SetActiveObject(old)
    c4d.utils.SendModelingCommand(command=c4d.MCOMMAND_DELETE,
                                  list=[old],
                                  mode=c4d.MODELINGCOMMANDMODE_POLYGONSELECTION,
                                  doc=doc)
    doc.SetActiveObject(new)

# Execute main()
if __name__=='__main__':
    main()

There’s no need to select the object above in this case, just save a reference to the currently selected (old) object into a variable before calling the split command, then you can switch between the new and old objects to do the cleanup work.


#4

That was quick.
Thank you both! I will try the script right now.
Have a nice day
S