Jandals / HairNet

HairNet addon for Blender
223 stars 37 forks source link

Context error when using python script #54

Open hujunh opened 1 year ago

hujunh commented 1 year ago

Greetings,

I am new to blender and I am trying to use the addon by calling 'bpy.ops.hairnet.operator('INVOKE_DEFAULT')' without any change(just simply import things), so that it can be used in the script. However, I had the issue 'RuntimeError: Operator bpy.ops.particle.brush_edit.poll() failed, context is incorrect'.

It seems that the problem raised in the method createHair with the following line: 'bpy.ops.particle.brush_edit(stroke=[{'name':'','location':(0, 0, 0), 'mouse':(0, 0), 'mouse_event':(0, 0), 'pressure':0, 'size':0, 'pen_flip':False, "x_tilt":0, "y_tilt":0, 'time':0, 'is_start':False}])'

I did find some discussion here https://developer.blender.org/T64805, but I still cannot figure it out. If you could help me out, I will be appreciated it. Thanks.

Jandals commented 1 year ago

I expect that the error is being caused by calling the operator directly rather than using the buttons in the Tools panel. There's some error-checking that happens there that the addon is probably missing.

Maybe I misunderstand what you're doing.

hujunh commented 1 year ago

I expect that the error is being caused by calling the operator directly rather than using the buttons in the Tools panel. There's some error-checking that happens there that the addon is probably missing.

Maybe I misunderstand what you're doing.

Yes, I was trying to call the operator directly instead of pressing the button. It seems that everything works fine except brush_edit function. It keeps raising the context error. I have tried to change the viewport to "3D_VIEW" or change the screen to "LAYOUT" but it just kept throwing that error. Therefore, I want to know that is there any way to prevent that error by changing some addon codes or is it a blender problem, and cannot be solved at this time?

Jandals commented 1 year ago

I see. I think the hang-up is that the operator itself depends of getting some information from other code in the addon. Without that information, you'll have to provide it in the script you're writing.