How to assign texture map to material in Python

# Assign a normal map texture to the prim (material)
def fixNormalMap(prim):    
    materialPath = prim.GetPath()
    materialName = prim.GetPath().name

    # Assign Normal Map
    omni.kit.commands.execute('ChangeProperty',
        prop_path=Sdf.Path(str(materialPath) + '/' + materialName + '.inputs:normalmap_texture'),
        value=Sdf.AssetPath('D:/Assets/Geometry/Trees/Ulvenwald/textures/Scottish Alder/AlderLeaf2_N.dds'),
        prev=None)
    print(Sdf.Path(str(materialPath) + '/' + materialName + '.inputs:normalmap_texture'))

Through Python, I’m trying to assign a texture to a currently empty normal map input in an mdl that was generated from converting an obj to usd. I’ve pretty much copied the code from the ‘Commands’ window after assigning it manually, but I can’t get it to assign through code, even if I leave the default path. I think the problem lies with ‘.inputs:normalmap_texture’
An example of printing the path I’m using would look like this (material and shader are both named Material_000001):

/World/AlderLarge_01_autumn/Looks/Material_000001/Material_000001.inputs:normalmap_texture

I’ve been looking everywhere (for days) to find some documentation for Python texture assignments in Omniverse specifically, but I’ve found nothing.

I’m fairly confident the error isn’t because of some logic outside this function, because immediately after I call it, I also call a function to enable opacity on the mdl which works just fine.

# Enable opacity
def fixOpacityMap(prim):    
    materialPath = prim.GetPath()
    materialName = prim.GetPath().name    
    
    # Enable Opacity
    omni.kit.commands.execute('ChangeProperty',
        prop_path=Sdf.Path(str(materialPath) + '/' + materialName + '.inputs:enable_opacity'),
        value=True,
        prev=None,

Edit: I’ve opened up the AlderLarge_01_autumn.usda file and it looks like there are a list of inputs that can be controlled (like inputs:enable_opacity), however, there’s no sign of normal map inputs, which I’m guessing is why the code doesn’t work.
I’m guessing Omniverse creates the normalmap_texture input automatically when manually assigning the texture file in the editor, however, that code is not traced in the ‘Commands’ window. Anyone know how to do this? I’m trying to do this for 800+ files.

Edit 2: I’ve created an attribute just before I assign the texture:

# Create the attribute
prim.CreateAttribute("inputs:normalmap_texture", Sdf.ValueTypeNames.Asset)

The ‘Normal’ dropdown window in the properties panel has now moved from around the bottom to basically the top after adding that code, so I’m guessing I successfully assigned the attribute, however, I still can’t get the texture to assign.

Hi @drkuzmick. Arter you create the attribute can you try .Set() on the attribute object that CreateAttribute() returns. Maybe it’s an issue with ChangeProperty command.