• Daz 3D
  • Shop
  • 3D Software
    • Daz Studio Premier
    • Daz Studio
    • Install Manager
    • Partnerships
    • AI Training data
    • Exporters
    • Daz to Roblox
    • Daz to Maya
    • Daz to Blender
    • Daz to Unreal
    • Daz to Unity
    • Daz to 3ds Max
    • Daz to Cinema 4D
  • 3D Models
    • Genesis 9
    • Genesis 8.1
    • Free 3D Models
  • Community
    • Gallery
    • Forums
    • Blog
    • Press
    • Help
  • Memberships
    • Daz Premier
    • Daz Plus
    • Daz Base
    • Compare
  • Download Studio
ADVANCED SEARCH
  • Menu
  • Daz 3D
ADVANCED SEARCH
Add image
  • Shop
  • 3d Software
    • Daz Studio Premier
    • Daz Studio
    • Install Manager
    • Partnerships
    • AI Training data
    • Exporters
    • Daz to Roblox
    • Daz to Maya
    • Daz to Blender
    • Daz to Unreal
    • Daz to Unity
    • Daz to 3ds Max
    • Daz to Cinema 4D
  • 3D Models
    • Genesis 9
    • Genesis 8.1
    • Free 3D Models
  • Community
    • Our Community
    • Gallery
    • Forums
    • Blog
    • Press
    • Help
  • Memberships
    • Daz Premier
    • Daz Plus
    • Daz Base
    • Compare

Notifications

You currently have no notifications.

Loading...
    • Categories
    • Recent Discussions
Daz 3D Forums > 3rd Party Software > Blender Discussion

Helpful Blender Scripts - shapekey transfer and material slot combiner

UpL8RenderingUpL8Rendering Posts: 129
January 2020 edited January 2020 in Blender Discussion

Below are a couple of Blender scripts I put together to help speed up my workflow while working with Daz3d characters.

They are set up for Genesis 8 characters but can be modified to fit your needs. They should work with 2.80 or 2.81

The first combines all the material slots that use the same texture, removes the unused material slot names, renames pupils to eyes, and shortens long names like Genesis8FemaleEyelashes_EyeMoisture to Eyelash_Moisture

The second script can be used to transfer shapekeys from one object to another (Object have to have the same poly count as usual)
It is also set up to remove the "Genesis8Female__" or "Genesis8Male__" from the beginning of the shapekey names.

No need to install these anywhere. In Blender click on the Scripting tab, under Text, select New, and paste the code in.

Make any changes in the script for your character and hit Run Script

To see the progress of the script click on the Blender Window menu, and select Toggle System Console

If you have any questions, feedback or ways the script could be improved please let me know.

Post edited by UpL8Rendering on January 2020

Comments

  • UpL8RenderingUpL8Rendering Posts: 129
    January 2020 edited February 2021
    # Program to combine character material slots, remove unused ones and rename long ones.# Note: Character mesh must be selected first and in Object Mode in Blender before running scriptimport bpycontext = bpy.contextob = context.object#Functions#Function to select multiple material slots from a list and assign them to first material in that listdef select_and_assign (material_list):      bpy.ops.object.mode_set(mode='EDIT')    bpy.ops.mesh.select_all(action='DESELECT')    i = 0    j = 0    # Find matching material slots names and select them    for slots in ob.material_slots:        j = 0        while j < len(material_list):          if slots.material.name == material_list[j]:                ob.active_material_index = i                bpy.ops.object.material_slot_select()                print (slots.material.name, " - Selected")          j += 1        i += 1    j = 0    #Assign selected materials to material slot matching the first name in the list    for slots in ob.material_slots:          if slots.material.name == material_list[0]:             ob.active_material_index = j             bpy.ops.object.material_slot_select()             bpy.ops.object.material_slot_assign()             bpy.ops.object.material_slot_deselect()             print ("Assigned to ",slots.material.name)             print ('\n')          j += 1#Function to remove material slots def remove_slots (material_list):         bpy.ops.object.mode_set(mode='OBJECT')    i = len(ob.material_slots)-1    print (i)    j = 0    # Find matching material slots names and remove them    for slots in reversed(ob.material_slots):        j = 0        while j < len(material_list):          if slots.material.name == material_list[j]:                print (slots.material.name," - Material Slot Removed",)                print ('\n')                ob.active_material_index = i                bpy.ops.object.material_slot_remove()                j += i          else:                      j += 1        i -= 1 #Function to rename material slots def rename_slots (material_list):        bpy.ops.object.mode_set(mode='OBJECT')    i = 0    j = 0    for slots in ob.material_slots:          if slots.material.name == material_list[0]:                print (slots.material.name," - Renamed")                ob.active_material_index = i                ob.active_material.name = material_list[1]                print (slots.material.name)                print ('\n')          i += 1# Start of Main Program #Selecting and assigning material slots.#Set up list of material slots that can be combined:  The 2nd, 3rd, 4th etc material in each row will be assigned to the 1st in the row.m_listA = ["Face", "Lips", "Ears", "EyeSocket"]m_listB = ["Mouth", "Teeth"]m_listC = ["Legs", "Toenails"]m_listD = ["Arms", "Fingernails"]m_listE = ["Pupils", "Irises", "Sclera"]m_listF = ["EyeMoisture", "Cornea"]#Run - select and assign functionsselect_and_assign(m_listA)select_and_assign(m_listB)select_and_assign(m_listC)select_and_assign(m_listD)select_and_assign(m_listD)select_and_assign(m_listE)select_and_assign(m_listF)#Removing material slots #Set up list of materials slots that are no longer used:remove_m_list = ["Lips", "Ears", "EyeSocket", "Teeth", "Toenails", "Fingernails", "Irises", "Sclera", "Cornea" ]#Run - Remove Slots Function remove_slots(remove_m_list)#Renaming material slots#Set up list: 1st material name in each row will be renamed using 2nd rename_m_listA = ["Pupils","Eyes"]rename_m_listB = ["Genesis8MaleEyelashes_Eyelashes","Eyelashes"]rename_m_listC = ["Genesis8MaleEyelashes_EyeMoisture","Eyelash_Moisture"]rename_m_listD = ["Genesis8FemaleEyelashes_Eyelashes","Eyelashes"]rename_m_listE = ["Genesis8FemaleEyelashes_EyeMoisture","Eyelash_Moisture"]#Run - Rename Slots Function rename_slots(rename_m_listA)rename_slots(rename_m_listB)rename_slots(rename_m_listC)rename_slots(rename_m_listD)rename_slots(rename_m_listE)print ("Done!")

     

    Post edited by UpL8Rendering on February 2021
  • UpL8RenderingUpL8Rendering Posts: 129
    January 2020
    # Program to:#   1: Shorten name of shapekeys#   2: Transfer shapekeys from source object to target objectimport bpycontext = bpy.context######### Change for your character here ###########Character with shapekeys you want to transfersource_object = 'Genesis8Female.Shape.001'source_key = "Key.001" # formatting note: last three digits must match character shape last 3 digits#Character you want to transfer shapekeys totarget_object = 'Genesis8Female.Shape'target_key = "Key" # formatting note: no 3 digits if character doesn't have 3 digits #Part of shapekey name you want to removestr_to_remove = 'Genesis8Female__'###################################################def transfer_shapekeys():    bpy.data.objects[source_object].select_set (True)    context.view_layer.objects.active  = bpy.data.objects[target_object]    SK_Slot = 1        for shapekey in bpy.data.shape_keys:         i = len (shapekey.key_blocks)-1         for keyblock in (shapekey.key_blocks):            context.view_layer.objects.active  = bpy.data.objects[source_object]            bpy.context.object.active_shape_key_index = SK_Slot            current_morph = bpy.data.shape_keys[source_key].key_blocks[SK_Slot].name            print (current_morph,"Transfered")            bpy.data.objects[source_object].select_set (True)            context.view_layer.objects.active  = bpy.data.objects[target_object]            bpy.ops.object.shape_key_transfer()            if SK_Slot == i:                return            SK_Slot += 1def shorten_shapekey_name():    SK_Slot = 0    for shapekey in bpy.data.shape_keys:         for keyblock in shapekey.key_blocks:            current_morph = bpy.data.shape_keys[source_key].key_blocks[SK_Slot].name            print ("renamed",current_morph.replace(str_to_remove, ''))            bpy.data.shape_keys[source_key].key_blocks[SK_Slot].name = (current_morph.replace(str_to_remove, ''))            SK_Slot += 1# Start of Main Program# Deselect allbpy.ops.object.select_all(action='DESELECT')#Shorten shapekey namesshorten_shapekey_name() #Transfer shapekeys from source to targettransfer_shapekeys()# Deselect allbpy.ops.object.select_all(action='DESELECT')print ("Done!")

     

  • andya_b341b7c5f5andya_b341b7c5f5 Posts: 694
    January 2020

    Thanks for sharing your scripts.  As they are designed for your own workflow, could you expand on what that is, in particular how you transfer your Daz characters into Blender, and where the scripts fit into your workflow?  That would be useful in understanding how and when these scripts will help the rest of us.

  • TheMysteryIsThePointTheMysteryIsThePoint Posts: 3,217
    January 2020

    Hi, thanks for this contribution. If I understand correctly, the first script would be extremely useful with the way that the Diffeomorphic plugin works, which sometimes results in many identical materials with the same same, e.g. material.001, .002, etc...

    Will you put this somewhere like GitHub? I have some scripts I use to re-texture objects imported via Alembic; we could grow this into a suite of useful Daz-To-Blender tools...

  • UpL8RenderingUpL8Rendering Posts: 129
    January 2020 edited January 2020
    andya_b341b7c5f5 said:

    Thanks for sharing your scripts.  As they are designed for your own workflow, could you expand on what that is, in particular how you transfer your Daz characters into Blender, and where the scripts fit into your workflow?  That would be useful in understanding how and when these scripts will help the rest of us.

    Sorry for the post and ghost. I wanted to put together a quick overview of my workflow and where these scripts fit in. It took longer than I thought.
    I should probably make another whole post just for details if anyone is interested. It's has been a little while since I did these from start to finish, details are a bit rusty.

    I start with the Basic Male or Female character and add any geografts I might need,
    I save copies with default UVs, and 2nd UVs if available. Then I use the Diffeomorphic Daz to Blender plugin to export and save a copy too.
    I then merge fitted figure's geometry, delete the extra meshes that are created and convert the character back to SubD if needed.
    In 4.11 and 4.12 there is a bug that makes the eyelashes disappear. I did submit the bug, hopefully it will get fixed.
    I export the character as an FBX file 4 times
    1 Base resolution UV1 no morphs (Base Poly)
    2 Base resolution UV2 no morphs (Base Poly)
    3 Subdivision 1, UV1, with Mouth Open, and Eyes Closed Morphs (1Subdivision Poly)
    4 Subdivision 1, UV2, no morphs (1Subdivision Poly)

    In Blender
    I import the 1Sub Poly first then the Base Poly next.
    I remove the eyes from both ( I think i used a script for this too)
    I apply a subdivision modifier on the Base Poly mesh, then transfer mesh data - vertex groups - to copy weight paints to the 1Sub Poly mesh.
    There is a lot of cleanup to do after this as some of the weight paint get copied to the wrong vertex if they are too close.
    Mostly around the mouth and eyelids, but also around the toes. Having the mouth open and eyes closed morphs helps when the rigging isn't working right.
    Once I am happy with the cleanup efforts I import the 2nd uv character and transfer UV's to the one with UV1
    I now have a 1 Subdivided Poly Daz model, fully rigged, with multiple UV channels.


    Back in Daz Studio I start exporting my purchased characters.
    I will dial in Aiko and click Currently Used in the shaping tab to see what morphs are applied to her.
    I will dial out the Aiko Character morph and reapply the Body and Head morphs. This will make the head and body the correct shape but not adjust the size. Important for animations.
    Can be resized later with math and stuff)
    Add geografts, Save file and export and save using the Diffeomorphic Plugin
    I Merge fitted figures like before, remove extra geometry, convert back to SubD if needed
    Export FBX 2 times. 1Sub Poly with no morphs and one with any morphs you want to have.
    Then I open the 1 Sub Poly Basic Character file was working with and import the 1Sub Poly -no morph Aiko. Remove Eyes, Join as shape to apply Aiko Morph to Basic Female character then remove the Basis Shapekey.
    I now have Aiko with all the 1Sub Poly, with Weight Paint and 1st and 2nd UV info.

    Import Aiko into Blender using the Diffeomorphic plugin and run the Bone uitility to orientate the bone rolls correctly. Save Blender file.
    Back in the 1Sub Poly Aiko file, append the Rig from the Diffeomorphic file and parent the 1Sub Poly Aiko mesh to her correctly sized and orientated rig.

    Almost done. I Import Aiko 1Sub Poly with all her morphs, remove eyes then (here it is!!!!) run the transfer shapekeys script to copy all the shapekeys to your characters and shorten the names to remove the "Genesis8Female__" part

    Save a file as backup.

    I will usually run the Material Script last and save as a separate "finished" file as it cannot be easily undone. It merges together material slots that are using the same texture.

    Why is this important? In Blender and Unreal Engine 4 it is not necessary to have a separate material slots for the the Face, Lips, Ears, and EyeSocket especially if they are using the same texture. You can still achieve the same results of being able to change the lip colors or even textures applied to the ears by using masks instead. Also in Unreal Engine there is a cost per material slot you have in as scene so keeping the amount of slots to a minimum can help performance.

    As always I look forward to any feedback or ideas.

    Post edited by UpL8Rendering on January 2020
  • UpL8RenderingUpL8Rendering Posts: 129
    January 2020
    TheMysteryIsThePoint said:

    Hi, thanks for this contribution. If I understand correctly, the first script would be extremely useful with the way that the Diffeomorphic plugin works, which sometimes results in many identical materials with the same same, e.g. material.001, .002, etc...

    That's great! The original idea of the script was to just combine material slots, remove the unused ones, and rename some annoying long ones, but you are right. You should be able to enter the names of the material slots with the .002 on them and instruct the script what you would like them to be named instead. Save and run the script anytime you need these changed.

    TheMysteryIsThePoint said:

    Will you put this somewhere like GitHub? I have some scripts I use to re-texture objects imported via Alembic; we could grow this into a suite of useful Daz-To-Blender tools...

    I was originally thinking Github but I wasn't sure anyone would bother going there, downloading or copying the scripts, and trying them so I put it right in the forum to make it as easy as possible.

    Having a central place for these little helpful little scripts and fixes would be great, maybe with a link back to the Daz forums for discussion and updates.

  • andya_b341b7c5f5andya_b341b7c5f5 Posts: 694
    January 2020
    UpL8Rendering said:
    andya_b341b7c5f5 said:

    Thanks for sharing your scripts.  As they are designed for your own workflow, could you expand on what that is, in particular how you transfer your Daz characters into Blender, and where the scripts fit into your workflow?  That would be useful in understanding how and when these scripts will help the rest of us.

    Sorry for the post and ghost. I wanted to put together a quick overview of my workflow and where these scripts fit in. It took longer than I thought.
    I should probably make another whole post just for details if anyone is interested. It's has been a little while since I did these from start to finish, details are a bit rusty.

    I start with the Basic Male or Female character and add any geografts I might need,
    I save copies with default UVs, and 2nd UVs if available. Then I use the Diffeomorphic Daz to Blender plugin to export and save a copy too.
    I then merge fitted figure's geometry, delete the extra meshes that are created and convert the character back to SubD if needed.
    In 4.11 and 4.12 there is a bug that makes the eyelashes disappear. I did submit the bug, hopefully it will get fixed.
    I export the character as an FBX file 4 times
    1 Base resolution UV1 no morphs (Base Poly)
    2 Base resolution UV2 no morphs (Base Poly)
    3 Subdivision 1, UV1, with Mouth Open, and Eyes Closed Morphs (1Subdivision Poly)
    4 Subdivision 1, UV2, no morphs (1Subdivision Poly)

    In Blender
    I import the 1Sub Poly first then the Base Poly next.
    I remove the eyes from both ( I think i used a script for this too)
    I apply a subdivision modifier on the Base Poly mesh, then transfer mesh data - vertex groups - to copy weight paints to the 1Sub Poly mesh.
    There is a lot of cleanup to do after this as some of the weight paint get copied to the wrong vertex if they are too close.
    Mostly around the mouth and eyelids, but also around the toes. Having the mouth open and eyes closed morphs helps when the rigging isn't working right.
    Once I am happy with the cleanup efforts I import the 2nd uv character and transfer UV's to the one with UV1
    I now have a 1 Subdivided Poly Daz model, fully rigged, with multiple UV channels.


    Back in Daz Studio I start exporting my purchased characters.
    I will dial in Aiko and click Currently Used in the shaping tab to see what morphs are applied to her.
    I will dial out the Aiko Character morph and reapply the Body and Head morphs. This will make the head and body the correct shape but not adjust the size. Important for animations.
    Can be resized later with math and stuff)
    Add geografts, Save file and export and save using the Diffeomorphic Plugin
    I Merge fitted figures like before, remove extra geometry, convert back to SubD if needed
    Export FBX 2 times. 1Sub Poly with no morphs and one with any morphs you want to have.
    Then I open the 1 Sub Poly Basic Character file was working with and import the 1Sub Poly -no morph Aiko. Remove Eyes, Join as shape to apply Aiko Morph to Basic Female character then remove the Basis Shapekey.
    I now have Aiko with all the 1Sub Poly, with Weight Paint and 1st and 2nd UV info.

    Import Aiko into Blender using the Diffeomorphic plugin and run the Bone uitility to orientate the bone rolls correctly. Save Blender file.
    Back in the 1Sub Poly Aiko file, append the Rig from the Diffeomorphic file and parent the 1Sub Poly Aiko mesh to her correctly sized and orientated rig.

    Almost done. I Import Aiko 1Sub Poly with all her morphs, remove eyes then (here it is!!!!) run the transfer shapekeys script to copy all the shapekeys to your characters and shorten the names to remove the "Genesis8Female__" part

    Save a file as backup.

    I will usually run the Material Script last and save as a separate "finished" file as it cannot be easily undone. It merges together material slots that are using the same texture.

    Why is this important? In Blender and Unreal Engine 4 it is not necessary to have a separate material slots for the the Face, Lips, Ears, and EyeSocket especially if they are using the same texture. You can still achieve the same results of being able to change the lip colors or even textures applied to the ears by using masks instead. Also in Unreal Engine there is a cost per material slot you have in as scene so keeping the amount of slots to a minimum can help performance.

    As always I look forward to any feedback or ideas.

    Wow, that is quite some workflow!  Thanks for writing it all up.  I do use the Daz Importer ('Diffeomorphic') plug-in, but i am not targeting Unreal so have found the plugin's 'Merge Materials' option adequate for my purposes thus far.  However, I will bookmark your scripts for possible future use.

  • JQPJQP Posts: 520
    July 2020
    UpL8Rendering said:

     

    The first combines all the material slots that use the same texture, removes the unused material slot names, renames pupils to eyes, and shortens long names like Genesis8FemaleEyelashes_EyeMoisture to Eyelash_Moisture

     

    I have needed this in pretty much every 3d package I've ever used, so thank you very much.

  • UpL8RenderingUpL8Rendering Posts: 129
    July 2020

    I'm glad you found that script helpful.  I have started dabbling in Daz scripting and have been wondering if this can be done in Daz Studio. That way it could be helpful in whatever 3d program you are exporting to.

    If I figure it out I will post the script.

     

  • andreiboscoandreibosco Posts: 0
    January 2021

    Thank you so much for sharing your scripts, they have been very useful.

  • UpL8RenderingUpL8Rendering Posts: 129
    February 2021

    You're welcome.

    I found an issue with the Material Slot combiner. If the last material slot is removed it causes the script to fail. I fixed it above.

    I'm finally getting around to getting these and other scripts to my Github repositories and adding documentation.

    Material Slot Combiner
    https://github.com/GNVR-Dev/BlenderScripts-Daz-Material-Slot-Combiner

    Shapekey Transfer
    https://github.com/GNVR-Dev/BlenderScripts-Daz-Shapekey-Transfer

  • Krys KryngleKrys Kryngle Posts: 311
    February 2021

    Awesome tools, thanks so much for sharing!

Sign In or Register to comment.
Adding to Cart…

Daz 3D is part of Tafi

Connect

DAZ Productions, Inc.
7533 S Center View Ct #4664
West Jordan, UT 84084

HELP

Contact Us

Tutorials

Help Center

Sell Your 3D Content

Affiliate Program

Documentation Center

Open Source

Consent Preferences

JOIN DAZ

Memberships

Blog

About Us

Press

Careers

Bridges

Community

In the Studio

Gallery

Forum

DAZ STORE

Shop

Freebies

Published Artists

Licensing Agreement | Terms of Service | Privacy Policy | EULA

© 2025 Daz Productions Inc. All Rights Reserved.