Remove NGons

On 26/12/2017 at 06:19, xxxxxxxx wrote:

I tried to remove Ngons of a polygonal object but this script has no influence over the geometry.

  1. import c4d
  2.   
  3. def main() :
  4.   
  5.     op.GetPolygonS().SelectAll(op.GetPolygonCount())
  6.     res = c4d.utils.SendModelingCommand(command = c4d.ID_NGON_REMOVE_MENU,
  7.                                         list = [op],
  8.                                         mode    = c4d.MODELINGCOMMANDMODE_POLYGONSELECTION,
  9.                                         doc = doc)
  10.     c4d.EventAdd()
  11. if __name__=='__main__':
  12.     main()

Sometimes I'm getting this error: A problem with this project has been detected: Object "Plane" - Polygon selection out of bounds. Please save and contact MAXON Support with a description of the last used commands, actions or plugins.

On 26/12/2017 at 09:33, xxxxxxxx wrote:

I never used this command but some SendModelingCommand return the object modified. Then you need to insert it into your document.

Anyway print res.

On 26/12/2017 at 10:00, xxxxxxxx wrote:

  1. import c4d
  2.   
  3. def main() :
  4.     
  5.     if op:
  6.         res = c4d.utils.SendModelingCommand(command = c4d.ID_NGON_REMOVE_MENU,
  7.                                             list = [op],
  8.                                             mode    = c4d.MODELINGCOMMANDMODE_POLYGONSELECTION,
  9.                                             doc = op.GetDocument())
  10.         **print res**
  11.         c4d.EventAdd()
  12. if __name__=='__main__':
  13.     main()

for some reason, this code returns False
I have selected polygonal object that has NGon lines.

On 26/12/2017 at 10:13, xxxxxxxx wrote:

Hi,

ID_NGON_REMOVE_MENU is a menu command ID, not a modeling command ID so it must be used with CallCommand() instead of SendModelingCommand().
Also, the command processes the selected Ngons. The code can be converted to:

import c4d
  
def main() :
    sel = c4d.BaseSelect()
    op.GetSelectedNgons(sel)
    sel.SelectAll(op.GetNgonCount())
    
    c4d.CallCommand(c4d.ID_NGON_REMOVE_MENU)
    c4d.EventAdd()
  
if __name__=='__main__':
    main()

On 26/12/2017 at 10:24, xxxxxxxx wrote:

is it possible to use CallCommand() in python generator or in generator plugins? or it can be used only as a script?

On 26/12/2017 at 10:30, xxxxxxxx wrote:

Originally posted by xxxxxxxx

is it possible to use CallCommand() in python generator or in generator plugins? or it can be used only as a script?

CallCommand() is only allowed from the main thread so it's forbidden from generators. Sorry.