I am using blender 3.2, am trying to execute the below steps using python script
- Import Rigged avatar (.glb) into Blender
- Select the mesh of upper human body
- Go to shade editor, delete existing material and add new material
- @shade editor, select "Principled BSDF" and use Hot key ctrl + shift + t to upload the image of texture (Node wrangler is already enabled)
- Adjust the scale parameters at the Mapping node
- Export the updated avatar in same glb format
I generated the below script for the above steps:
import bpy
bpy.ops.import_scene.gltf(filepath="C:\\Users\\ASUS\\Desktop\\stage\\STAGEGLB3.glb", files=[{"name":"STAGEGLB3.glb", "name":"STAGEGLB3.glb"}], loglevel=50)
bpy.context.space_data.shading.type = 'MATERIAL'
bpy.ops.material.new()
bpy.ops.node.select(deselect_all=True, location=(420, 240))
bpy.context.space_data.system_bookmarks_active = 1
bpy.ops.node.nw_add_textures_for_principled(filepath="C:\\Users\\ASUS\\Desktop\\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 at line 3 is
AttributeError: ‘NoneType’ object has no attribute ‘space_data’
I tried with this link AttributeError: '_RestrictContext' object has no attribute 'space_data' still no luck
pls suggest the way forward.
Thanks
vij