Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I added a function that can automatically translate material names according to the blender dictionary. Can add it to the code? #5

Open
chenpaner opened this issue Nov 29, 2024 · 0 comments

Comments

@chenpaner
Copy link

I added a function(trans_material_name) that can automatically translate material names according to the blender dictionary.Need to modify these two lines of code in each operator.

bpy.data.materials.get(trans_material_name("QMM Asphalt"))
bpy.data.materials.new(name=trans_material_name("QMM Asphalt"))
from bpy.app.translations import pgettext_iface as iface_

def trans_material_name(name: str) -> str:
    if "QMM" in name:
        a = name.replace("QMM", "").strip()
        translated_a = iface_(a)
        result = f"QMM {translated_a}"
    else:
        result = iface_(name)
    return result

class QMMAsphalt(bpy.types.Operator):
    """Add/Apply Tinted Asphalt Material to Selected Object (or Scene)"""
    bl_label  = "QMM Asphalt Shader"
    bl_idname = 'shader.qmm_asphalt_operator'

    def execute(self, context):
        # DOES THE MATERIAL ALREADY EXIST?
        if m_asphalt := bpy.data.materials.get(trans_material_name("QMM Asphalt")):
            #ShowMessageBox(message_text, "QMM Asphalt")
            # print(f"QMM Asphalt already exists")
            bpy.context.object.active_material = m_asphalt
            diffuse_bool = bpy.context.scene.diffuse_bool.diffuse_more
            m_asphalt.diffuse_color = (0.02, 0.02, 0.02, 1) if diffuse_bool else (0.8, 0.8, 0.8, 1)
            return {'FINISHED'}
        else:
            self.make_shader()
        return {'FINISHED'}

    def make_shader(self):
        start = time.time()

        # CreateShader
        m_asphalt = bpy.data.materials.new(name=trans_material_name("QMM Asphalt"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant