2
$\begingroup$

I am writing an addon popup that shows all the current shortcuts. This is context sensitive and I have it mostly done. However, I am not able to get much information from the other python addons.

Below is some of CoDEManX's code that collects a lot of the info I need. However, it does not seem to collect anything for Python addons.

Is there a way to collect the same info that the tooltips do from within python?

mod, opname = idname.split(".")
idname_c = "{!s}_OT_{!s}".format(mod.upper(), opname)
idtype = getattr(bpy.types, idname_c)
description = idtype.bl_rna.description
$\endgroup$
12
  • $\begingroup$ You might try idtype.__doc__ to get the documentation string. $\endgroup$ – pink vertex Sep 9 '14 at 12:09
  • $\begingroup$ I am unsure from which information you want to derive what.So do you have the idnames of the operators or do you want to get them ? if you have the idnames then what exactly do you want to get from the operators ? $\endgroup$ – Gaia Clary Sep 9 '14 at 18:42
  • $\begingroup$ The tool tip. ie a description of what the op does. $\endgroup$ – Yardie Sep 9 '14 at 21:39
  • $\begingroup$ thanks pink vertex that got a few more but there are still dome to go. It is very helpful I will be able to follow that lead a bit more. $\endgroup$ – Yardie Sep 9 '14 at 22:07
  • $\begingroup$ The code is here (blenderartists.org/forum/…) If you try it you'll see what's missing. $\endgroup$ – Yardie Sep 9 '14 at 22:20
2
$\begingroup$

Wow Blender/Python is really like an onion ( a rather large on at that ) and my eyes have been watering like made getting through the layers :)

Ok I finally ran grep in the scripts directory as I should have when pink vertex first sugessted it. Duh. Line 340 in bl_extract_messages.py gives it up (code below). So it looks to me that if it doesn't have a bl_rna.description (or bl_description) then it uses the __doc__ part. In the process I realised that the bulk of what I need is directly in the keymaps them selves as .name attribute of the individual keymap. This is derived from the bl_label that is in the op that is called by the new keymap definition line.

So I went round in circles when it was right under my nose. Thanks again everyone.

    if bl_rna.description:
        process_msg(msgs, default_context, bl_rna.description, msgsrc, reports, check_ctxt_rna_tip, settings)
    elif cls.__doc__:  # XXX Some classes (like KeyingSetInfo subclasses) have void description... :(
        process_msg(msgs, default_context, cls.__doc__, msgsrc, reports, check_ctxt_rna_tip, settings)
$\endgroup$
1
$\begingroup$

Tooltips appear to display the __doc__ string from the operator class. The simple operator template also hints that this is the tooltip.

There is nothing in place to force an operator to have a __doc__ string so you may want to fall back to the bl_label which must be defined. In the rare event that is an empty string I would fall back to the idname.

mod, opname = idname.split(".")
idname_c = "{!s}_OT_{!s}".format(mod.upper(), opname)
idtype = getattr(bpy.types, idname_c)

if len(idtype.__doc__) > 0:
    description = idtype.__doc__
else:
    if len(idtype.bl_label) > 0:
        description = idtype.bl_label
    else:
        description = " ".join(opname.split("_"))
$\endgroup$
0
$\begingroup$

I assume you have the operator's bl_idname at hand. Lets say your operator's bl_idname is "avastar.shape_type_bone_hint"

Now you can do this:

# I assume you got the operator's bl_idname from somewhere.

idname = "avastar.shape_type_bone_hint"
op = eval("bpy.ops."+idname)
idtype=getattr(bpy.types, op.idname())

# Now you can get the operator's bl_* declarations as follows:

bl_idname      = getattr(idtype,"bl_idname",      None)
bl_label       = getattr(idtype,"bl_label",       None)
bl_description = getattr(idtype,"bl_description", None)
bl_options     = getattr(idtype,"bl_options",     None)

I am still unsure if this is exactly what you have asked for. but this will give you the operator's bl_description. However, maybe there is a more elegant way to get the idtype from the operator.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.