Compare same polygones coordinate and delete them
On 20/10/2017 at 04:17, xxxxxxxx wrote:
Hi evry one !
I am Ben new member of the great familly of C4D user and un start try some work on Python.
I wanna know if it will be possible to analyse polygone coordinate of the same object and if two polygones have the same coordinate deleting them ?
Thanks a lot for your help
On 20/10/2017 at 04:48, xxxxxxxx wrote:
Why not use Optimize command?
On 20/10/2017 at 06:23, xxxxxxxx wrote:
It's not enough :/
There is it a script https://imgur.com/000caDf
But I need to set a tolerance to the comparaison of polygon's center
On 23/10/2017 at 03:01, xxxxxxxx wrote:
welcome to the Plugin Café forums
Actually I there's not much MAXON's SDK Team can do here, as it's more an algorithmic quest rather than something related to the SDKs or APIs. So we need to leave this to our community (but I'm sure, they come up with something).
I just want to add a few notes:
The referenced script does not look like a good solution to me, regardless of the missing tolerance.
First of all it's just comparing the "polygon center". Maybe ok for the intention, it's not differentiating between tris and quads. But think of it, there are completely different polygons sharing this same "polygon center". For example larger or smaller ones, or polygons with different direction. And also completely differently shaped ones... So I think, the referenced script will erroneously delete more polygons than it should.
Secondly, although this may be intentional, but it seems to delete both polygons it deems equal.
And one last tiny formal request. Actually we prefer code snippets in text form, so we can copy the code. Screenshots are really sub-optimal in that matter.
On 24/10/2017 at 04:25, xxxxxxxx wrote:
Thanks for your answer.
you're right, this approach is too uncertain. There are too many cases where this removes more polygon than expected. I tried with a tolerance it works better but does not solve all the problems.
import c4d def main() : distance = 0.05 # c4d.CallCommand(16768) #Connect Objects + Delete obj = doc.GetActiveObject() objmg = obj.GetMg() poly = obj.GetAllPolygons() PolyS = obj.GetPolygonS() centers =  for p in poly: ptA = obj.GetPoint(p.a) ptB = obj.GetPoint(p.b) ptC = obj.GetPoint(p.c) ptD = obj.GetPoint(p.d) polyCenterL = (ptA + ptB + ptC + ptD)/4 polyCenterG = polyCenterL * objmg centers.append(polyCenterG) for i in xrange(len(centers)) : for j in xrange(i + 1, len(centers)) : vec = centers[i] - centers[j] dist = abs(vec.GetLength()) if dist < distance: PolyS.Select(i) PolyS.Select(j) c4d.utils.SendModelingCommand(command=c4d.MCOMMAND_DELETE, list=[obj], mode=c4d.MODELINGCOMMANDMODE_POLYGONSELECTION, doc=doc) bc = c4d.BaseContainer() bc.SetData(c4d.MDATA_OPTIMIZE_TOLERANCE, distance) bc.SetData(c4d.MDATA_OPTIMIZE_POINTS, True) bc.SetData(c4d.MDATA_OPTIMIZE_UNUSEDPOINTS,True) c4d.utils.SendModelingCommand(c4d.MCOMMAND_OPTIMIZE, list = [obj], mode = c4d.MODIFY_ALL, bc=bc, doc = doc) c4d.EventAdd() if __name__=='__main__': main()
I keep searching. PS: OK and thank you for your request I will improve that.
On 24/10/2017 at 15:29, xxxxxxxx wrote:
why you don't do it the other way.
First optimize the object
bc = c4d.BaseContainer() bc.SetData(c4d.MDATA_OPTIMIZE_TOLERANCE, distance) bc.SetData(c4d.MDATA_OPTIMIZE_POINTS, True) bc.SetData(c4d.MDATA_OPTIMIZE_POLYGONS, False) bc.SetData(c4d.MDATA_OPTIMIZE_UNUSEDPOINTS,True) c4d.utils.SendModelingCommand(c4d.MCOMMAND_OPTIMIZE, list = [op], mode = c4d.MODIFY_ALL, bc=bc, doc = doc)
Set MDATA_OPTIMIZE_POLYGONS to False, so only the Points will be optimized.
After that you can search for polygons with the same point indices. I think that will be an easier task than searching points within a tolerance.
By the way, do you now 'c4d.utils.VectorEqual(v1, v2 [, epsilon = 0.01])'?
Pretty handy to compare two vectors with tolerance.