Select and delete some poligons of object
-
On 13/11/2017 at 23:15, xxxxxxxx wrote:
Hi!
I have some thousands of cubes with a fillet subdivision of 3 so they contain 113 poligons each.
I thought it would be a good idea to remove the 107 poligons for the fillet and keep the 6 sides only for previewing purposes, because these thousands of cubes can make the viewport animation preview pretty damn slow.
Thanks to gr4ph0s' help I have a function which goes trough all the 113 polygons and applies a material to the poligons on the cube sides (I found out that the 3rd one is the front, 31st is right, etc - I made a dict of them) but how could I delete the remaining ones, if the SceneQuality is set to Draft?
I tried this:
def create_poly_selection(obj) :
poly_count = obj.GetPolygonCount()
tags = list()
for i in xrange(poly_count) :
CubeSideNumbers = {"3": "FRONT", "31": "RIGHT", "59": "BACK", "87": "LEFT", "112": "TOP", "113": "BOTTOM"}
if str(i) in CubeSideNumbers:
tag = c4d.SelectionTag(c4d.Tpolygonselection)
tag.SetName(str(i))
obj.InsertTag(tag)
tags.append([i, tag])
** else:**
** if SceneQuality == "Draft":**
** obj.remove()**
return tagsI got an error for the bold part: AttributeError: 'c4d.PolygonObject' object has no attribute 'remove'
(I think it's because the "obj" is the cube itself, not the poligon)
-
On 14/11/2017 at 09:46, xxxxxxxx wrote:
Here an example that should work for you.
import c4d def main() : dictPolyId = {"2": "FRONT", "5": "RIGHT"} # Get current obj selected obj = op if not op: return # Get poly id to deleted polyIdToDelete = list() for i in range(0, obj.GetPolygonCount()) : if i not in dictPolyId: polyIdToDelete.append(i) select = obj.GetPolygonS() #Get the current selection # Select all poly and deselect only interested poly select.SelectAll( obj.GetPolygonCount()) for polyID in dictPolyId: select.Deselect(int(polyID)) # Delete selected polygon c4d.utils.SendModelingCommand(c4d.MCOMMAND_DELETE, list = [obj], mode = c4d.MODELINGCOMMANDMODE_POLYGONSELECTION, bc = c4d.BaseContainer(), doc = obj.GetDocument()) # Optimize in order to remove point options = c4d.BaseContainer() options[c4d.MDATA_OPTIMIZE_TOLERANCE] = 0.001 options[c4d.MDATA_OPTIMIZE_POINTS] = True options[c4d.MDATA_OPTIMIZE_POLYGONS] = False options[c4d.MDATA_OPTIMIZE_UNUSEDPOINTS] = True c4d.utils.SendModelingCommand(c4d.MCOMMAND_OPTIMIZE, list = [obj], mode = c4d.MODELINGCOMMANDMODE_ALL, bc = options, doc = obj.GetDocument()) c4d.EventAdd() if __name__=='__main__': main()
I do not have a lot a time right now, I will explain more in detail later.
-
On 15/11/2017 at 02:29, xxxxxxxx wrote:
Originally posted by xxxxxxxx
Here an example that should work for you.
I appreciate your help really much for this and the last one!
I'm building a programmable dot-matrix display from these six-colored cubes, and it finally begins to work
-
On 15/11/2017 at 09:32, xxxxxxxx wrote:
As gr4phos is showing in his example, the polygons of an object are not objects themselves, it's rather the other way round, there is a polygon object which contains arrays of points and polygons. So you will rather delete certain polygons from an object. One way to do so is shown by gr4phos above.
Edit: Sorry, I forgot to hit reload before answering. So my comment obviously wasn't needed anymore.