1

I need to do a loop cut on a mesh I've generated, so I found some code that works when I run Blender normally then the script. The catch is, I need it to work when I launch Blender from the command line and currently it causes an EXCEPTION_ACCESS_VIOLATION that crashes blender :(

Here is the code I'm using:

        bpy.ops.object.select_all(action='DESELECT')
        bpy.context.view_layer.objects.active = argObject
        argObject.select_set(True)
        bpy.ops.object.editmode_toggle()
    # setup a bunch of context for the loop cut operation
    region, rv3d, v3d, area = self.view3d_find(True)
    override = {
        'scene' : bpy.context.scene,
        'region': region,
        'area':area,
        'space':v3d
    }

    # perform the loop cut operation
    bpy.ops.mesh.loopcut_slide(
        override,
        MESH_OT_loopcut = {
            "number_cuts":loopNumber,
            "smoothness":0,
            "falloff":'INVERSE_SQUARE',
            "object_index": 0,
            "edge_index": 2,
            "mesh_select_mode_init":(True, False, False)
        },
        TRANSFORM_OT_edge_slide = {
            "value": 0,
            "mirror": False,
            "snap": False,
            "snap_target": 'CLOSEST',
            "snap_point": (0,0,0),
            "snap_align": False,
            "snap_normal": (0,0,0),
            "correct_uv": False,
            "release_confirm": False,
            "use_accurate": False
        }
    )

Here's the error message I get in the command line:

Error : EXCEPTION_ACCESS_VIOLATION Address : 0x00007FF7193BE4C3 Module : blender.exe Thread : 00007ec0 Writing: C:\Users\Me\AppData\Local\Temp\MyBlend.crash.txt

I had a look in the crash log above for a thread with the id listed, but there was none :/

ioflow
  • 11
  • 2
  • not sure why you have different properties in your override (like scene and space). but try to use these four (4) properties: window, screen, area, region as shown in this answer https://blender.stackexchange.com/a/270716/142292 . This one makes your code work. – Harry McKenzie Aug 01 '22 at 06:19
  • use override ={'window':bpy.context.window,'screen':bpy.context.window.screen,'area':area,'region': region}. and try to print(type(area), type(region)) and make sure they really are classes bpy.types.Area and bpy.types.Region – Harry McKenzie Aug 01 '22 at 06:35
  • and kindly share a link of your crash.txt log or paste the last few lines of the error in that crash.txt log. – Harry McKenzie Aug 01 '22 at 06:44
  • Hey Harry,

    Thanks for all your help :)

    Unfortunately, after making the changes it's still crashing :/

    
    
    area = <bpy_struct, Area at 0x0000021813C0AE08>
    
    
    Error   : EXCEPTION_ACCESS_VIOLATION
    
    
    Address : 0x00007FF7193BE4C3
    
    
    Module  : blender.exe
    
    
    Thread  : 0000307c
    
    
    Writing: C:\Users\simon\AppData\Local\Temp\SituVanity.crash.txt```
    
    – ioflow Aug 01 '22 at 06:59
  • may I know how you run the script? from the Text Editor in blender or directly from the terminal or command line? and what is the command your running? please also share the crash.txt log – Harry McKenzie Aug 01 '22 at 07:00
  • It won't let me post more than a couple of lines sorry, and the comments don't seem to "support" line breaks (???)

    Is there a way to add the crash log as a file?

    – ioflow Aug 01 '22 at 07:04
  • use http://pastie.org/ and paste the log there then share the link it generates – Harry McKenzie Aug 01 '22 at 07:06
  • fwiw, here's the line from the batch file that calls blender:

    "Bin\blender-3.2.1-windows-x64\blender" -b Blends\Vanity.blend -P Scripts\RenderParametricVanity.py -- --cycles-device OPTIX --vanityConfig marquis_bay_wall_1200 --themeConfig florentine_walnut --outputPath ..\Output --optionsConfigFilePath Data\Company\Configs\Options\ExampleOptions01.json

    – ioflow Aug 01 '22 at 07:07
  • http://pastie.org/p/1LcRediuQz7jkurZXjxNRF – ioflow Aug 01 '22 at 07:08
  • Is there another way to do a loopcut apart from bpy.ops? I noticed you said in the other post it's best to avoid bpy.ops... – ioflow Aug 01 '22 at 07:09
  • ok so i see it is in Scripts\Parametric\box.py", line 215 in addVerticalBanding, are the contents exactly that snippet you posted in the question? so if you just do a pass inside the function addVerticalBanding will it still crash? – Harry McKenzie Aug 01 '22 at 07:11
  • There's other bits around it, but if I remove the bpy.ops.mesh.loopcut_slide command it runs without crashing – ioflow Aug 01 '22 at 07:17
  • try to see if this one helps, the other answer does not use bpy.ops https://blender.stackexchange.com/questions/196367/how-to-use-loopcut-slide-operation-without-any-ui – Harry McKenzie Aug 01 '22 at 07:18
  • 1
    Awesome, I reckon that'll do it! I'll let you know how I go... – ioflow Aug 01 '22 at 07:24
  • 1
    Awesome work Harry, it's going :) – ioflow Aug 03 '22 at 12:56
  • awesome! happy it worked out for you! feel free to post the answer and i will upvote :) – Harry McKenzie Aug 03 '22 at 12:57

0 Answers0