我在从搅拌机插件中的 json 文件加载数据时遇到问题,这给我带来了致命错误,我不知道如何修复它。我多次查找错误,但问题从未适用于我的代码,谁能帮我解决它?
这是 json 文件(default.json)
{
"viewport": "solid",
"lighting": {
"type": "studio",
"lighting file": "Basic",
"world space lighting": {
"enabled": false
}
},
"color": "OBJECT",
"background": "THEME",
"backface culling": false,
"x-ray": {
"enabled": false
},
"shadow": {
"enabled": false
},
"cavity": {
"enabled": true,
"type": "world",
"ridge": "${BindValue: RIDGE}",
"valley": "${BindValue: VALLEY}"
},
"depth of field": false,
"outline": {
"enabled": false
},
"specular lighting": false
}
这是加载它的功能
def loadPreset(location):
with open(location) as json_file:
print(json.load(json_file))
data = json.load(json_file)
with data["lighting"] as lighting:
if lighting["type"] == "studio":
bpy.context.space_data.shading.light = 'STUDIO'
bpy.context.space_data.shading.studio_light = lighting["lighting file"]
with lighting["world space lighting"] as world_space_lighting:
bpy.context.space_data.shading.use_world_space_lighting = world_space_lighting
if world_space_lighting:
bpy.context.space_data.shading.studiolight_rotate_z = world_space_lighting["rotation"]
bpy.context.space_data.shading.color_type = data["color"]
bpy.context.space_data.shading.background_type = data["background"]
bpy.context.space_data.shading.show_backface_culling = data["backface culling"]
bpy.context.space_data.shading.show_xray = data["x-ray"]["enabled"]
if data["x-ray"]["enabled"]:
bpy.context.space_data.shading.xray_alpha = data["x-ray"]["alpha"]
和这个运营商来称呼它
class VPM_DP_DEFAULT(bpy.types.Operator):
bl_label = "default"
bl_idname = "view.default_display"
def execute(self, context):
data.currentViewport = "default"
import pathlib
loadPreset(str(pathlib.Path(__file__).parent.absolute()) + "\\viewportPresets\\basic\\default.json")
return {'FINISHED'}
但是当我单击链接到操作员的按钮时,它给了我这个错误......
我环顾四周看看如何解决这个问题,问题通常是检查一个不存在的键,但我的代码从不检查一个名为“预设”的键