0
$\begingroup$

I am writing a addon that shows the currently available shourtcut keys.

At the moment I am filtering the availalble shortcuts via the bpy.context region and space data and comparing those to the settings for each shortcut. I then poll each one to see if it can be called in the current context. After all this I am still getting shortcuts in the list that are not actually relevant to the current context. I am thinking this is because the active object is in a different scope/context which the C code is filtering out but I can't work out how to do this filtering.

If I could find which space the active object is in and if that was the same as the current space then show those shortcuts otherwise don't. I can't seem to find out how to find the context of the active object rather than just the current context. I hope I have been clear enough here.

Thanks

Yardie

$\endgroup$
6
  • $\begingroup$ There is the concept of an active object, and of selected objects - but current context and context of active object is identical IMO. When we say "context", it's not just about the active object however. It is also the space the mouse is over, how certain properties are set and so on. What exactly do you want to know / access? $\endgroup$
    – CodeManX
    Sep 15, 2014 at 21:35
  • $\begingroup$ The problem with this is however the active object is still the active object when the context is changed to a different space. Also for some reason poll() is returning positive for some things even when the operator shouldn't and can't be run. $\endgroup$
    – Yardie
    Sep 16, 2014 at 5:03
  • $\begingroup$ if idname and eval("bpy.ops.{:}.poll()".format(idname)): is not failing as it should - then maybe that is my problem and that's not the right way to do this. It does seem to be the way that the C code works. $\endgroup$
    – Yardie
    Sep 16, 2014 at 5:11
  • $\begingroup$ Thank you CoDEmanX all your help has finally paid off. I think I have an idea of how to do the addon in a Blender UI way. You have clarified many things now all I have to work out is how to add an icon with my addon. $\endgroup$
    – Yardie
    Sep 16, 2014 at 9:55
  • $\begingroup$ Operators may return {'CANCELLED'} or {'PASS_THROUGH'} to terminate execution after poll() returned True, which is sometimes necessary, as you can't access everything from the class method poll() or the conditions are too manifold to check in advance. You can't rely on poll() only, and not all operators have one anyway. $\endgroup$
    – CodeManX
    Sep 16, 2014 at 18:59

0

You must log in to answer this question.

Browse other questions tagged .