New get_morphs usage when use other add on ?

Issue #601 resolved
engetudouiti created an issue

I noticed with commit https://bitbucket.org/Diffeomorphic/import_daz/commits/2ae192ea9aa8322f3edaa93ddc5d7afc1caedb89

you change the getMorphs function as new one then change real function directory. because now my script not work which use the function to get morphs dictionary. (return empty)

Then I have thought I only need to change the function name as new get_morphs() with use same arguments.

but it still not work. I can not catch what cause problem but, it simply said the return dic is empty.

Could you tell me, what argument is wrong, or I can not directly use the get_morphs() by

from import_daz import get_morphs

anymore?

The real code of one function which use the get_morphs() is like that

class WIF_OT_clearDazMorphs(bpy.types.Operator):
    bl_idname = "object.clear_dazmorph"
    bl_label = "Clear daz morph value"
    bl_description = "Clear current rig(obj) morph values"
    bl_options = {'UNDO'}

    flg_act:BoolProperty(
        name = "active morph only",
        description = "clear only active morphs",
        default = False)

    def execute(self, context):
        scn = context.scene
        rig = context.active_object
        print(rig.name)
        flg = rig.daz_morphset.daz_actonly
        print(flg)
        morphdic = get_morphs(rig, "ALL", activeOnly=flg) #here I get the morph dics
        print(morphdic)

        for key in morphdic.keys():
            rig[key] = 0.0

        update_props(context, rig)

        msg = "Clear morphs finished!!"
        showInfo(self, context, msg)        
        return{'FINISHED'}

After I exchange the getMorphs() to get_morphs(), now it return empty dic with this arguments. without error.

If you notice, where is wrong I hope you teach me correct usage of new functions. I check api.py soruce too, but not clear why it not worked any more (before it return all morphs as dic = I requested so)

(after all so it return none dic, then it show error ,non type object, when I get keys() when I execute the func

the log is

Genesis 3 Female
True
None
Python: Traceback (most recent call last):
  File "C:\Users\TAKE\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\wifDazBoneUtility_pe.py", line 891, in execute
    for key in morphdic.keys():
AttributeError: 'NoneType' object has no attribute 'keys'

the genesis3 female = rig (object)

True = my flag option (active only)

None = which I hope to get the discionary of all category, type morphs of rig object (UI slider visible raw propertys I believe)

I only need to know way to get activated morphs name value or all morph value and name. (generated by your add on as sliders)

I tried to use getMorphsExternal() of api.py but, it show new argument error. (one argument missing), I suppose it relate how I load the function, but hesitate to try modify it. (maybe I should not use the func but use get_morphs() I suppose)

Comments (8)

  1. engetudouiti reporter

    I supposed the category arguments, you have described, it is optional, but I afraid, I need to set it .

    if so I hope you can offer “All” option for the category too.

    in your description (old?) in the code, you described like this, then if I follow the rule, it should work .(actually worked untill this commit)

    +def getMorphs(ob, morphset, category=None, activeOnly=False):
    +    """getMorphs(ob, type, category=None, activeOnly=False)
    +    Get all morph names and values of the specified type from the object.
    +
    +    Returns:
    +    A dictonary of morph names - morph values for all morphs in the specified morphsets.
    +
    +    Arguments:
    +    ?ob: Object (armature or mesh) which owns the morphs
    +
    +    ?type: Either a string in ["Units", "Expressions", "Visemes", "Facs", "Facsexpr", "Body", "Custom", "Jcms", "Flexions"],
    +        or a list of such strings, or the keyword "All" signifying all morphset in the list.
    +
    +    ?category (optional): The category name for Custom morphs.
    +
    +    ?activeOnly (optional): Active morphs only (default False).
    +    """
    

    I afraid, if I do not set category arg add on simply use “None” value as category >> then it can not gather any morph dic now. ^^;

    I do not hesitate to customize my code (good study), but I really often use this function often. so I hope if you offer “All” for category arg. I may not need so complex thing ,,

  2. engetudouiti reporter

    Or do you offer function to get the arg category (list type I suppose) ?

    About this issue, I can not find good way to get the category list without use your module functions.

    I change to load your offered function as

    from import_daz.api import get_morphs
    

    (though I do not know, If I need it or not)

    but it still show same problem. (not return the dictionary with my set args)

    Then I test to use the function in Console, but for me even though I set the Category as the custom morph category name, or set as List, after all , the return values keep as None. (not dictype, simply None) . I miss use the function?

    >>> from import_daz.api import get_morphs
    >>> rig = C.object
    >>> rig.name
    'Genesis 3 Female'
    
    >>> get_morphs(
    get_morphs(ob, type, category=None, activeOnly=False)
    Get all morph names and values of the specified type from the object.
    Returns:
    A dictonary of morph names - morph values for all morphs in the specified morphsets.
    Arguments:
    ?ob: Object (armature or mesh) which owns the morphs
    ?type: Either a string in ["Units", "Expressions", "Visemes", "Facs", "Facsexpr", "Body", "Custom", "Jcms", "Flexions"],
        or a list of such strings, or the keyword "All" signifying all morphset in the list.
    ?category (optional): The category name for Custom morphs.
    ?activeOnly (optional): Active morphs only (default False).
    >>> get_morphs(rig, "All", category = ["face_wif"])
    >>> m = get_morphs(rig, "All", category = ["face_wif"])
    >>> type(m)
    <class 'NoneType'>
    
    >>> print(get_morphs(rig, "All", category="face_wif"))
    None
    

    So if you show, how the function work as console, with set arg, (at current I simply get all raw morphs of rig with active/non active only) Then I can easy follow it and use it in my add on.

    (I use it to save morph pose preset with render icon image,, so I hope to keep my add on functions,,)

  3. engetudouiti reporter

    So I tried to find what cause issue, then test , by get_morphs(rig, “All”)

    now console show this error, (I add some func to show each step functions return value to print out, then try get_morphs(rig, “All”)

    >>> m = get_morphs(rig, "All")
    Traceback (most recent call last):
      File "<blender_console>", line 1, in <module>
      File "C:\Users\TAKE\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\import_daz\api.py", line 83, in get_morphs
        getMorphsExternal(ob, morphset, category, activeOnly)
      File "C:\Users\TAKE\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\import_daz\morphing.py", line 146, in getMorphsExternal
        pgs = getMorphs0(ob, morphset, None, category)
      File "C:\Users\TAKE\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\import_daz\morphing.py", line 71, in getMorphs0
        pgs += getMorphs0(ob, mset, sets, category)
      File "C:\Users\TAKE\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\import_daz\morphing.py", line 87, in getMorphs0
        pg = getattr(ob, "Daz"+morphset)
    AttributeError: 'Object' object has no attribute 'DazStandard'
    

    does it relate with appended rig to new scene from library? (this rig is generated maybe in June, I suppose)

  4. Thomas Larsson repo owner

    The new get_morphs is exactly the same as the old getMorphs, its just a cosmetic change so all external functions use snake caps which is Blender standard. I should be using that internally as well, but I have been using camel caps for too long to change now.

    The problem was that I forgot to return a value. Should work now.

    The DazStandard attribute is defined when the plugin is initialized (morphing.py 2693, “Standard” is a member of theMorphSets), and has been so for quite a while. It contains the “Unclassified standard morphs” that you sometimes got a warning about. So I dont understand how you can get the last error.

  5. engetudouiti reporter

    I see. the later console output, I seems select not rig ^^; (so I tried to catch what is going on, with edit script, then notice I may better to wait your reply, the more I try something, I got new error. )

    Then do I need to change way to import your module function, as import_daz.api ,or I can still just directly import from import_daz? anyway I suppose it should work , then after quick test close this. Thanks.

  6. Log in to comment