Retarget mesh driver cause error (blender 2.92)

Issue #224 resolved
engetudouiti created an issue

I only use this option, when I append mesh object in another blend file. then change rig to curren scene one.

Today I tried this option,,

  1. append tops in anoterh blend file rig (it usually come with rig etc)
  2. I change rig target to current scene rig, then now it deformed as same as other clothing items.
  3. I can find custom morphs and jcms now lost dirver link (because rig changed ) then select the Tops object and select current scene rig, use the option “retarget mesh dirver)
  4. Now it show these error message.

Error: Python: Traceback (most recent call last):
File "C:\Users\TAKE\AppData\Roaming\Blender Foundation\Blender\2.92\scripts\addons\import_daz\error.py", line 247, in execute
self.run(context)
File "C:\Users\TAKE\AppData\Roaming\Blender Foundation\Blender\2.92\scripts\addons\import_daz\driver.py", line 734, in run
self.retargetRna(ob, rig)
File "C:\Users\TAKE\AppData\Roaming\Blender Foundation\Blender\2.92\scripts\addons\import_daz\driver.py", line 747, in retargetRna
prop = trg.data_path.split('"')[1]
IndexError: list index out of range

after that sometimes the driver prop of rig change parameter inclemetns value.

(eg I can only change the value as integer, (can not set float anymore9

or simply no change (so do not retarget driver for the mesh shape key (morphs) of the Top for current rig.

Comments (14)

  1. engetudouiti reporter

    Fortunately I can still transfer jcms and transfer custom morphs from merged actor mesh to the tops, (so the item work as same as original scene file)

    But the retarget mesh driveroption was useful, when I append some items from another scene.

    About current scene, I use rigi-fy converted rig , but I do not think it cause problem.

  2. engetudouiti reporter

    No unfortunatelly if I try to transfer custom morphs from merged mesh to appended tops item, now it can not transfer (I see some new error message)

    When I tarnsfered morphs for the top from actor mesh in original scene, it worked without problem, so I do not know if recent version cause this issue. or if there is reason to failed to ransfer.. I may test with other blender version and report again for both case.

    (Retarget mesh driver failed, and can not transfer morphs from merged mesh to appended item)

  3. engetudouiti reporter

    OK though I still miss when I try to use transfer custom morphs, for merged mesh (attached to rigi-fy) to appended mesh,

    But now I make custom scripts which can Retarget all selected mesh shape keys driver for active rig,

    It need to check many condition, (or it may change user custom driver)

    So I make it when driver target daz rig-type = same as current active rig,

    shape key value driver change target for Active rig.

    I do not know all detail which Thomas had offered, so if you can take time check pelase. (if it worked, include your add on function as you like)

    To it work, there should be old rig which we exchange shape key target in the blender scene. (Usually if we append mesh from another blend file, then it is attached armature modifier, it come with armature,,)

    If delete old rig which come with mesh,, mesh shape key lost driver target. (blender seems auto-remove I suppose). and the old rig need to check actually the shape key driven by the DAZ improter rig. to avoid to exchange un-necessary shape key driver target. (like camera, or light etc)

    But I suppose, we can make some option only re-target shape key driver with some conditions. (eg when driver broken try to re-target etc)

    import bpy
    import import_daz
    
    def get_driver(mesh, name):
        drvs = mesh.shape_keys.animation_data.drivers
        drv = False
        for tdrv in drvs:
            if tdrv.data_path[12: -8] == name:
                drv = tdrv
                break
        return drv
    
    
    def set_target(drv, amt):
        vbs = drv.driver.variables
        for vb in vbs:
            if hasattr(vb, "targets"):
                for tg in vb.targets:
                    if hasattr(tg.id, "DazRig") and tg.id["DazRig"] == amt["DazRig"]:
                        tg.id = amt
    
    tamt = bpy.context.active_object
    objs = bpy.context.selected_objects
    sobjs = []
    
    for obj in objs:
        if obj.name == tamt.name:
            continue
        sobjs.append(obj)
    
    print("selected objs", sobjs)
    
    for sobj in sobjs:
        smesh = sobj.data
        kblocks = smesh.shape_keys.key_blocks
        drvs = smesh.shape_keys.animation_data.drivers
        for sk in kblocks:
            tdrv = get_driver(smesh, sk.name)
            if hasattr(tdrv, "data_path"):
                print(sk.name + " - " + tdrv.data_path)
                if tdrv.driver.type == "SCRIPTED":
                    set_target(tdrv, tamt)
    

  4. engetudouiti reporter

    So there seems some new problem, I think they are more important, so hope Thomas solve those issue first please.

    At same time, I hope one small change for driver expression style to work “retarget driver” more stable.

    I edit my script, even though there is no old rig in the scene, still force to change driver target.id

    (when you append obj, (armature attached) in current scene, but remove rig,

    now it lost old target ID, so I add it in condition to change target.id to current active rig.

    But ideally,, most stable way is check the driver is generated by add on.

    I suppose there are many way, but if expression variable are somehow unique,

    it make us easy to check, the driver is generated by this add on or not.

    I do not hope to mess up current add on, but if Thomas can take time, cosider it please.

    That means, A or B expression variable name change as more unique variable name. so we can detect, the driver (when broken), if it is generated by importer or not easy. if it is generated by importer,, (so variable = DazA etc),

    I can force those variable target as current selected rig.

    Or I suppose if there is more stable way to detect, broken linked shape key driver is generated by importer or not. (maybe change expression cause issue to load old scene etc,, I afraid it,,

    I tried if I can detect from current active armature propertys, (or ID , labell)

    check armature daz_morphs and serch if there is daz_morph which controll shape keys, but I think it not work for jcms.

    (then jcms must need to re-target correctly, when it had been transfered) for wearable mesh objs.

  5. Thomas Larsson repo owner

    Most of the issues should be gone now. New rig properties are also created to drive the morphs, and are show in the Custom morphs panel.

    The reason for the variable names is that the driver expression must not exceed 256 characters. This was a real problem before the plugin used property groups to store morphs, and using the shortest names possible has stuck since then.

  6. engetudouiti reporter

    Thanks^^ , I can remember the problem, so we can not change variable name.. Then I want to know how your srcipt filter each “ sahpe key” drv was made by add on or not, and custom morph or jcm?

    eg I transfer jcm pJCMaaa (shape keys) to the tops mesh from default rig with your add on, so now pJCMaaa of top will be driven by the defualt rig bones

    then append the mesh in another scene character rig, the shape key driver variable target will be removed but usually keep variable name, target rig bone ID, and condtions. I suppose new commit can re-target the rig name, but can you detect, the shape keys are generated by your add on or not?

    Though I suppose it is rare case, but I often add some new shape keys then there is case, it is driven by other properties. then can your script keep these user custom made shape key driver target, as same as before?

    ===
    I will test with new import scene, and will test apend later. then if I still see some issue or question, I may ask again. thanks .

  7. engetudouiti reporter

    No . I keep test scene for re-target. then select append mesh with current scene armature (rigi-fy), then try re-target with recent version (script update)

    location: <unknown location>:-1
    Error: Python: Traceback (most recent call last):
    File "C:\Users\TAKE\AppData\Roaming\Blender Foundation\Blender\2.92\scripts\addons\import_daz\error.py", line 247, in execute
    self.run(context)
    File "C:\Users\TAKE\AppData\Roaming\Blender Foundation\Blender\2.92\scripts\addons\import_daz\driver.py", line 734, in run
    self.retargetRna(ob, rig)
    File "C:\Users\TAKE\AppData\Roaming\Blender Foundation\Blender\2.92\scripts\addons\import_daz\driver.py", line 755, in retargetRna
    trg.id = rig
    TypeError: bpy_struct: item.attr = val: DriverTarget.id expected a Text type, not Object

    cause this new error. About the append mesh item, I already removed old rig witch mesh attached before. (so most of shape keys variables driver target = empty, but remain target bone , and formulas (for jcm).

    About custom morph shape-key, it only remain variables. (but rig have same property witch can drive the shape key)

    If I use my edit script , it can re-target object as current rig correctly.

  8. Thomas Larsson repo owner

    So you have created a driver which is driven by a text rather than an object? That is certainly not something that the plug-in should touch. In the latest commit it doesn’t

  9. engetudouiti reporter

    Though I undersatnd what you means, (because erroer log discribe so)

    but I do not do such thing.

    I just import custom morphs for the actor mesh, then use trnasfer shape keys with driver with your offered option,

    Then append the tops to another scene , then exchange rig.

    I do not make any custom driver for test mesh, though there is some new shape key which I tried to deform well, but it is no driver as default.

    I serched the erroer with google, then there seems some exceptional case,

    blender script show the erroer, but I can not detect why it cause erroer.

    Maybe there is case, if target object is None, blender miss treat it etc.

    I remove the default rig which come with already. so if it cause issue, I may re-consider, everytime keep old rig untill re-target for append mesh.

    Anyway thanks I may try again, with recent commits versions.

  10. Log in to comment