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.
The parent of an object can be easily obtained via:
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.
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.
That was quick.
Thank you both! I will try the script right now.
Have a nice day
Nexensis’s script is great and inspires me a lot, although has two problems:
- Does not focus on the new created polygon object split from the original object
- 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()
Great script, Thanks.
Which version of C4D do you use? Nexensis’ script jumps to the newly created object and can be undone in R21.
Nexensis, thanks for sharing that script, works great.
Here’s a quick and dirty icon for it.
Looks like this:
Love it, thanks!
I test the scripts on R20 though.