How can I copy the statics info text in blender (in status bar)?
Because I need to write down the vertices and faces counts for about 100 objects.
I would be very happy if there could be a way to copy all the statics data.
There is not a way to do this without scripting, but you can do it very easily with scripting. For example:
import bpy
st = ''
for ob in bpy.context.selected_objects:
me = ob.data
s = ''.join(ob.name,
'Vertices: ', len(me.vertices),
'Edges: ', len(me.edges),
'Faces: ', len(me.polygons))
st = ''.join(st, s, '\n')
with open('data.txt', 'w') as f:
f.write(st)
You can copy and paste that in the text editor and click the Play button, and you’ll have a file called data.txt with the object names, vertices counts, face counts, and edge counts.
That code is super messy, it could be better, but I wrote it on my phone
If you’d rather not leave Blender at all to store or view the saved data, you can 1-click generate and store the data as a new text data-bock.
Code
import bpy
clipboard = bpy.context.window_manager.clipboard = str(bpy.context.scene.statistics(bpy.context.view_layer))
clipboard.encode("utf8")
bpy.ops.text.new()
bpy.ops.text.paste()
The one limitation for this that the received data is copied to the clipboard. At the moment it doesn’t auto delete the copied data after saving it (still working on that), but I should find a way in a few minutes or tomorrow.
Basically what this script does is get the scene statistics data that you can see in the 3D Viewport or global Blender footer.
thank you very much! This helped me so much.
Is it possible to display it without commas? (because they delay the time when copying. Bc of the commas i can’t click the whole number at once and copy. I have to click the number before the comma and after the comma to select the full number in the text editor.)
What commas? Do you mean the | ? If so yes, you can remove them.
Screenshot
Code
import bpy
c1 = bpy.context.window_manager.clipboard = str(bpy.context.scene.statistics(bpy.context.view_layer))
c1.encode("utf8")
c2 = c1.replace(" | ", "_")
bpy.context.window_manager.clipboard = c2
bpy.ops.text.new()
bpy.ops.text.paste()
In the new version of the script I replace the | with _ - but you can replace the original | with anything that you want, including a empty space.
Ah, my bad. I didn’t have any commas originally because I had a small scene.
Fixed the script to remove commas on 1k+ numbers.
Screenshot
Code
import bpy
c1 = bpy.context.window_manager.clipboard = str(bpy.context.scene.statistics(bpy.context.view_layer))
c1.encode("utf8")
c2 = c1.replace(",", "")
bpy.context.window_manager.clipboard = c2
bpy.ops.text.new()
bpy.ops.text.paste()
Thank you so much!
You’re welcome, glad I could help!
Thanks to @josephhansen by the way for making that other cool script as well (it looks really cool).
It’s a more customizable version of yours but it also adds a lot of extra complications yours works better for this use case for sure, I have a tendency to do more detailed snippets instead of simple ones and I forget that most Blender users aren’t coders
To be honest, I’ve found in some cases that Blender doesn’t allow the creation of external files if the user has disallowed it, whether for Blender itself, all applications or because some OS security blocker disabled it automatically.
Ah yeah there’s another thing I forget, I always run Blender as an administrator so I never have those issues
Hello,
do you know how to display only the faces and vertices numbers?
Also, is it possible to copy it automatic after ,run script"?
Hello,
do you know how to display only the faces and vertices numbers?
Also, is it possible to copy it automatic after ,run script"?
Vertices and faces only. Automatically saves on run
interesting code snippets
you forgot to close your file at the end and free it !
is it possible to add the edges index too ?
thanks
happy bl
If you use
with open('data.txt', 'w') as f:
it auto-closes your file
You can get the number of edges from my earlier snippet: How to copy the statistics info? - #2 by josephhansen
Thank you, but i meant in combination with this code:
import bpy
c1 = bpy.context.window_manager.clipboard = str(bpy.context.scene.statistics(bpy.context.view_layer))
c1.encode(“utf8”)
c2 = c1.replace(",", “”)
bpy.context.window_manager.clipboard = c2
bpy.ops.text.new()
bpy.ops.text.paste()
Well… no, if you’re just using the statistics straight from Blender, there’s not much you can do with that unless you want to dive into some fairly comprehensive string parsing. It’s going to take a a lot more work to adapt that code to your need, instead of just using the snippet I wrote for you that does exactly what you want Here, I’ll even make it copy to the clipboard for you:
import bpy
st = ''
for ob in bpy.context.selected_objects:
me = ob.data
s =''.join(ob.name,
'Vertices: ', len(me.vertices),
'Faces: ', len(me.polygons))
st = ''.join(st, s, '\n')
bpy.context.window_manager.clipboard = st
bpy.ops.text.new()
bpy.ops.text.paste()
How can I run the script? I use blender 2.81, I think it doesnt work in this version. There is an error in the text editor.