On 28/05/2014 at 03:06, xxxxxxxx wrote:
Try this in the Script Manager (select your Polygon Object) :
import c4d
is_polyselection = lambda x: x.CheckType(c4d.Tpolygonselection)
def main() :
if not op or not op.CheckType(c4d.Opolygon) :
c4d.gui.MessageDialog('Please select a Polygon Object')
selections = filter(is_polyselection, op.GetTags())
if not selections:
return
result = []
points = op.GetAllPoints()
polys = op.GetAllPolygons()
for tag in selections:
sel = tag.GetBaseSelect()
new_polys = []
for i, v in enumerate(sel.GetAll(len(polys))) :
if not v:
continue
new_polys.append(polys[i])
obj = c4d.PolygonObject(len(points), len(new_polys))
obj.SetAllPoints(points)
for i, p in enumerate(new_polys) :
obj.SetPolygon(i, p)
obj.SetName('%s - %s' % (op.GetName(), tag.GetName()))
c4d.utils.SendModelingCommand(c4d.MCOMMAND_OPTIMIZE, [obj])
result.append(obj)
root = None
if len(result) == 1:
root = result[0]
else:
root = c4d.BaseObject(c4d.Onull)
root.SetName(op.GetName())
for obj in result:
obj.InsertUnderLast(root)
doc.StartUndo()
doc.InsertObject(root)
doc.AddUndo(c4d.UNDOTYPE_NEW, root)
doc.EndUndo()
c4d.EventAdd()
if __name__ == '__main__':
main()
Note that it uses the Optimize Command to remove the points it will not need.
-Niklas