I've written a pair of functions for exporting the currently selected indicies to a file, then reimporting them.
There's no particular reason for this other than to get more comfortable with writing scripts for Blender.
Here's what I have:
import bmesh import bpy import json def exportSelectedIndicies(filename): mesh = bmesh.from_edit_mesh(bpy.context.active_object.data) selectedIndicies = [i.index for i in mesh.verts if i.select] with open(filename, 'w') as f: json.dump(selectedIndicies, f) def importSelectedIndicies(filename): mesh = bmesh.from_edit_mesh(bpy.context.active_object.data) with open(filename) as f: selectedIndicies = json.load(f) for i in mesh.verts: i.select = i.index in selectedIndicies mesh.select_flush_mode()
The export portion does exactly what I want. I'm happy with it.
The import portion doesn't seem to do anything when you run it at first. It's not until you click away from the console and into the 3D View that it suddenly updates your selection.
It seems to me that the import portion is just missing a little part to tell the 3D View that it needs to redraw itself. I searched around online and found some stuff saying that there's a
Blender.Redraw method that can be used, but there's no such module
Redraw that I can import. I suspect that either those functions aren't exposed to the Python API, or they're from an older version of Blender and have since been deprecated.
I see that I can access the
SpaceView3D object, but it doesn't seem to have any redraw method that I can use.
So what am I missing here? Is there some kind of
redraw method that needs to be called for it to trigger that it needs to be redrawn (and on what object, and how would I get at that object?)
Is this a bug? I am using version 2.74... do newer versions have the bug fixed? On that note, do newer versions add in a function that I need (I just haven't updated because I don't use Blender much, and because my network is slow so updating takes several hours. But I'll go ahead and update if that'll fix my problems.)
If it is a bug or something that's been overlooked... is there a workaround I can use? Maybe something to emulate clicking on the 3D View, then clicking back on the Console (so I can enter more commands afterwards...)?