I am using blender 3.2, am trying to execute the below steps using python script

s1) Import Rigged avatar (.glb) into Blender

s2) Select the mesh of upper human body

s3) Go to shade editor, delete existing material and add new material

s4) @shade editor, select "Principled BSDF" and use Hot key ctrl + shift + t to upload the image of texture (Node wrangler is already enabled)

s5) Adjust the scale parameters at the Mapping node

s6)Export the updated avatar in same glb format

I generated the below script for the above steps:

import bpy
import functools

threeD_viewport = None
bpy.ops.import_scene.gltf(filepath="C:\\Users\\ASUS\\Desktop\\stage\\STAGEGLB3.glb", files=[{"name":"STAGEGLB3.glb", 
      "name":"STAGEGLB3.glb"}], loglevel=50)
for area in bpy.context.screen.areas: 
    if area.type == 'VIEW_3D':
        for space in area.spaces: 
            if space.type == 'VIEW_3D':
                threeD_viewport = space

threeD_viewport.shading.type = 'MATERIAL'
bpy.ops.node.select(deselect_all=True, location=(420, 240))
bpy.ops.node.nw_add_textures_for_principled(filepath="C:\\Users\\brown_color.jpg", directory="C:\\Users\\ASUS\\Desktop\\", files=[{"name":"brown_color.jpg", "name":"brown_color.jpg"}], relative_path=True)
bpy.data.materials["Material.003"].node_tree.nodes["Mapping"].inputs[3].default_value[0] = 5
bpy.data.materials["Material.003"].node_tree.nodes["Mapping"].inputs[3].default_value[1] = 5
bpy.context.space_data.shading.type = 'MATERIAL'
bpy.context.space_data.system_bookmarks_active = 3
bpy.context.space_data.system_bookmarks_active = 1
bpy.context.space_data.system_bookmarks_active = 1
bpy.context.space_data.params.filename = "STAGEGLB4.glb"

The error am getting is at line 11

Python: Traceback (most recent call last): File "\Text", line 18, in AttributeError: 'SpaceView3D' object has no attribute 'material'

@marty-fouts can u pls help us in this regard

Thanks vij

  • $\begingroup$ nw_xxxx ops are from the Node Wrangler addon. Is it installed/activated? $\endgroup$
    – lemon
    Apr 8, 2023 at 7:33
  • $\begingroup$ Node Wrangler addon is activated before generating the python script $\endgroup$ Apr 8, 2023 at 10:45

1 Answer 1


After long R&D able to figure out the solution:

FYI: ensure materials of the mesh are deleted manually in shading editor before executing the script

import bpy 
import os

bpy.ops.import_scene.gltf(filepath="C:\\Users\\STAGEGLB42.glb", import_pack_images=True,import_shading='NORMALS', loglevel=50)

material_basic= bpy.data.materials.new(name="Basic")





bpy.ops.export_scene.gltf(filepath="d://assa1.glb", export_format='GLB', 
export_image_format='AUTO', export_materials='EXPORT')

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .