I got in my mesher a button “operator” which simply cache the current frame to desk …now how to make it do this cache in a frame range …tried doing a for loop but it doesn’t do anything
you could do:
for frame in range(5, 20, 2):
bpy.context.scene.frame_set(frame)
bpy.ops.object.simple_operator()
but better would be a for-loop inside that operator
I tried this and it didn’t work … (in the execute part …did a for loop calling a function and this failed)
but what’s the error message?
well i tried again and it worked
but the problem is it doesn’t update after frame change in the viewport (so it is kinda freezing till it finish the whole loop)
should i call scene update()?
may be doing it as a modal operator which will push frames and when press escape stop?as I need it to be interactive
but I don’t know how to make this “button” modal
Remember, you are running in a single thread so when you holdup processing in a loop, Blender has to wait as well. I have done a lot of frame_change work and using bpy.ops in a frame change is just bad news. Or the user may have the interface or object in an unexpected state. Even if you get it to work in the interface it may not render correctly. The main reason is that you are relying on the context to exist and it does not exist at render time.
Convert your simple operator to a standard def then you can call it as needed when the frame changes.
import bpy
def my_update_code(scene):
print("processing on frame #%f" % scene.frame_current)
def frameChangePre(scene):
my_update_code(scene)
bpy.app.handlers.frame_change_pre.append(frameChangePre)
Now all you have to do is play the timeline to generate your cache. Which is very similar to how the particle system and other systems work in Blender.
hmmm…I see where the problem lies now
will fix this and post a tutorial on my mesher soon as this is the last part in the mesher
one last question …as there are many error ifs in the code…how to print in the top bar (next to scene name)
There was a proposal to extend the API to allow scripts to write to the progress area, however I have not seen a working example posted. If your AddOn is a RenderEngine, however, the hook does exist via update_status.
seems complicated …
you can only use those info header notifications from inside an operator, self.report(…)
I see
thanks a lot for all hints,I’m putting final touches in the addon and C++ code now