The following code creates a new material, adds a primitive cylinder and assigns the new material to the new primitive by accessing the primitive using bpy.context.object:
The code runs as expected if executed from within Blender's built-in script editor.
If started and run using the Blender Development VS-Code Extension (using Blender: Start and Blender: Run Script commands from VS-Code's Command Palette), the material is created and the cylinder is created but the material is not assigned to the cylinder. Under some circumstances (not always) there is an error message saying that bpy.context.object has no materials property as it is None.
I tried to narrow the execution context using #context.area: VIEW_3D and Blender: Set Script Context without success.
I am using
Blender 3.3.1
VS Code 1.72.2
Blender Development VS-Code Extension Released on 8.6.2022, 09:56:29
The following code creates a new material, adds a primitive cylinder and assigns the new material to the new primitive by accessing the primitive using
bpy.context.object
:The code runs as expected if executed from within Blender's built-in script editor.
If started and run using the Blender Development VS-Code Extension (using
Blender: Start
andBlender: Run Script
commands from VS-Code's Command Palette), the material is created and the cylinder is created but the material is not assigned to the cylinder. Under some circumstances (not always) there is an error message saying that bpy.context.object has no materials property as it isNone
.I tried to narrow the execution context using
#context.area: VIEW_3D
andBlender: Set Script Context
without success.I am using