"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


#5

Nexensis’s script is great and inspires me a lot, although has two problems:

  1. Does not focus on the new created polygon object split from the original object
  2. Cannot undo the operation to restore the deleted mesh on the original object

The reason of the first problem is that c4d keeps focusing on the original object so you need to select next object mannually.
The reason of the second problem is that c4d.utils.SendModelingCommand cannot be recorded by the c4d cache of “undo” and “redo”.

So I improve his codes and post here for anyone who encounters the same problems.

import c4d

def main():
    c4d.CallCommand(14046, 0) # Split
    c4d.CallCommand(12109, 0) # Delete
    doc.SetActiveObject(doc.GetActiveObject().GetNext())

if __name__=='__main__':
    main()

#6

Great script, Thanks.


#7

Which version of C4D do you use? Nexensis’ script jumps to the newly created object and can be undone in R21.


#8

http://matniedoba.de/selection-to-object-split/


#9

Nexensis, thanks for sharing that script, works great.

Here’s a quick and dirty icon for it.

Looks like this:
split%20and%20kill%20shown

splitAndKill.tif


#10

Love it, thanks!


#11

I test the scripts on R20 though.