Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
blender 2.92 python重写_Python_Blender - Fatal编程技术网

blender 2.92 python重写

blender 2.92 python重写,python,blender,Python,Blender,关于这个问题,我已经看到了不少问题,但我还不能完全理解 这里有一个具体的例子 我创建一个立方体,并在编辑模式下添加环切。不用担心 我从“信息”窗口复制代码,然后在脚本中尝试,结果出现了不祥的运行时错误:操作符bpy.ops.mesh.loopcut\u slide.poll()应显示view3d region&editmesh错误消息 我现在明白了,这是关于首先通过重写为python提供正确的上下文。唉,我不知道该怎么做 代码如下: import bpy import os os.syste

关于这个问题,我已经看到了不少问题,但我还不能完全理解

这里有一个具体的例子

我创建一个立方体,并在编辑模式下添加环切。不用担心

我从“信息”窗口复制代码,然后在脚本中尝试,结果出现了不祥的运行时错误:操作符bpy.ops.mesh.loopcut\u slide.poll()应显示view3d region&editmesh错误消息

我现在明白了,这是关于首先通过重写为python提供正确的上下文。唉,我不知道该怎么做

代码如下:


import bpy
import os

os.system("cls")

# remove the default cube...
objs = bpy.data.objects
for obj in objs:
    if obj.name.find("Cube") == 0:
        bpy.data.objects.remove(obj, do_unlink=True)

# add a cube!
bpy.ops.mesh.primitive_cube_add(size=2, enter_editmode=True, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1))
# do something to it to be sure that we have it...
bpy.data.objects['Cube'].scale[0] = 10

# THE CODE BELOW GIVES THE RuntimeError: Operator bpy.ops.mesh.loopcut_slide.poll() expected a view3d region & editmesh error message.

# What is the override code I have to use to fix it????????

bpy.ops.mesh.loopcut_slide(MESH_OT_loopcut={"number_cuts":16, "smoothness":0, "falloff":'INVERSE_SQUARE', "object_index":0, "edge_index":4, "mesh_select_mode_init":(True, False, False)}, TRANSFORM_OT_edge_slide={"value":0, "single_side":False, "use_even":False, "flipped":False, "use_clamp":True, "mirror":True, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "correct_uv":True, "release_confirm":False, "use_accurate":False})

请您详细说明您对OP的代码片段做了哪些更改,以及为什么这些更改解决了问题?vcleanall,您知道您可以对自己的帖子和它们发表评论吗?谢谢您的回答。同一天,我也在blenderartists上发布了这个问题,在那里我很快得到了相同的答案,现在我相信我已经理解了它的含义。
import bpy      
import os

os.system("cls")


objs = bpy.data.objects
for obj in objs:
    if obj.name.find("Cube") == 0:
        bpy.data.objects.remove(obj, do_unlink=True)

# add a cube!
bpy.ops.mesh.primitive_cube_add(size=2, enter_editmode=True, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1))
# do something to it to be sure that we have it...
bpy.data.objects['Cube'].scale[0] = 10



for area in bpy.context.screen.areas:
        if area.type == 'VIEW_3D':
            for region in area.regions:
                if region.type == 'WINDOW':
                    override = {'area': area, 'region': region, 'edit_object':bpy.context.edit_object}


                    bpy.ops.mesh.loopcut_slide(override,MESH_OT_loopcut={"number_cuts":16, "smoothness":0, "falloff":'INVERSE_SQUARE', "object_index":0, "edge_index":4, "mesh_select_mode_init":(True, False, False)}, TRANSFORM_OT_edge_slide={"value":0, "single_side":False, "use_even":False, "flipped":False, "use_clamp":True, "mirror":True, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "correct_uv":True, "release_confirm":False, "use_accurate":False})