call operator from Python Scripts
MatthiasThDs opened this issue · comments
Hi,
I really love your addon. I use it for a long time :) In fact I am writing Python scripts for my company to speed up the modelling process. Kinda like procedural modelling. Therefore UV Magic and especially bpy.ops.uv.muv_uvw_box_map() would be key to make it all work.
But, it seems that your script is not callable from a Python script? What would it take to enable that feature?
The poll operator seems to disallow it:
@classmethod
def poll(cls, context):
# we can not get area/space/region from console
if common.is_console_mode():
return True
return _is_valid_context(context)
I kinda tried to just return true in the poll, it seems to work, but sometimes i get wrong results :)
Thanks for your feedback!
I think you didn't satisfy the context to execute this operation.
Magic-UV/src/magic_uv/op/uvw.py
Lines 43 to 59 in 91b575b
What is your context you try to execute?
Hi,
I think my context should be right. Just in the "Layout" workspace in Editmode.
I also have an issue using one of your functions in the console (Windows 10, Blender 2.83.5):
Are you saying that it should technically already work in console and scripts? Could the space.type VIEW_3D be the issue? Here is what I get, when I write into the Blender console:
Although it wonders me, because there should be a VIEW_3D right? Also your "console mode" check doesnt seem to work for me.
OK, I understood the issue.
# only 'VIEW_3D' space is allowed to execute
for space in context.area.spaces:
if space.type == 'VIEW_3D':
break
else:
return False
I think current context.area is CONSOLE
.
Currently, all features of Magic UV must be executed from VIEW_3D
.
Do you want to execute this feature from other areas?
Yes. I would like to run the functions in a Python Script, which sadly don't have View_3D as current context area.
Btw. here is my edited poll function:
@classmethod
def poll(cls, context):
return True
# we can not get area/space/region from console
#if common.is_console_mode():
# return True
#return _is_valid_context(context)
This works :D
And forget what I said about "strange results" above. They were coming from an outdated BMesh. So once i can execute the operator, it always works.
I think all things we have to do with is deleting below checks in _is_valid_context
function.
Other checks are still needed to prevent from the execution in unexpected condition.
# only 'VIEW_3D' space is allowed to execute
for space in context.area.spaces:
if space.type == 'VIEW_3D':
break
else:
return False
What do you think?
Yes I agree.
That would be nice.
by the way: There is the variable: bpy.context.screen.areas, which can help to detect if there is any window with VIEW_3D currently available. I dont know if you need a VIEW_3D.
bpy.context.screen.areas
looks better to me.
BTW, are you interested in contributing to this project about this?
I think all we have to do is change context.area.spaces
to like for area in context.screen.areas: for area.spaces:
.
I'm now tackling to other issue before releasing v6.4.
So, I will accept your change if you want.
@nutti
Yes, i can try to work my way into this github. Never did before, so give me some days.
Awesome!
I will wait your work.
If you have any trouble to complete this work, please feel free to tell me.