Is there a way code the Decimate modifier to target a specific face count and be destructive?

First time learning to code in Python. I wanted to try to make a destructive decimator for Sculpt Mode that targets specifically 150k faces or vertices. However, I don’t really understand how to use the webpage explaining the bpy code for Decimate:

Another problem I am having is that if I try to code the modifier to apply itself after use, the script completely fails. On the 10th row the script of some reason breaks. Everything else works before adding that line of code using copy paste by hovering the apply button.

I managed to fix the last problem on my own. The copy paste added “ml_” in the code, which of some reason broke it. Strange.

Still need some help with finding a way to decimate so that the model always reach 150k faces or vertices. :slight_smile:

If you can get how many faces your model has. Then you can divide 150000 by that number and get the ratio you need to decimate.

Example: 150 000 / 400 000 = 0.375

That’s a pretty good solution! Now I just need to learn how to create that formula in code. Does face_count on the Blender webpage actually calculate the mesh number, or do I have to look elsewhere?

Any idea on how to actually write down the examples on that webpage into actual code? I find the descriptions pretty vague.

Sorry, I suck at coding. I just like images more than text. :smile:

1 Like

Found this after a quick google search.
So if you use this to get the polycount you can the just do the division to get the ratio to put into the decimator.

1 Like