mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 01:11:40 +00:00
Small fix for warnings " 'bim.cad_tool' not found for space"
Small fix to allow setting cad_tool even if operators were called not from viewport and to avoid warnings like "Warning: Tool 'bim.cad_tool' not found for space 'PROPERTIES'"
This commit is contained in:
@@ -947,7 +947,7 @@ class EnableEditingExtrusionAxis(bpy.types.Operator, tool.Ifc.Operator):
|
||||
bpy.ops.object.mode_set(mode="EDIT")
|
||||
ProfileDecorator.install(context)
|
||||
if not bpy.app.background:
|
||||
bpy.ops.wm.tool_set_by_id(name="bim.cad_tool")
|
||||
bpy.ops.wm.tool_set_by_id(tool.Blender.get_viewport_context(), name="bim.cad_tool")
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
|
||||
@@ -41,18 +41,6 @@ import json
|
||||
# https://ifc43-docs.standards.buildingsmart.org/IFC/RELEASE/IFC4x3/HTML/lexical/IfcRailingType.htm
|
||||
|
||||
|
||||
# TODO: move it out to tools
|
||||
def blender_get_viewport_context():
|
||||
"""Get viewport area context for context overriding.
|
||||
|
||||
It's a bit naive since it's just taking the first available `VIEW_3D` area
|
||||
when in real life you can have a couple of those.
|
||||
"""
|
||||
area = next(area for area in bpy.context.screen.areas if area.type == "VIEW_3D")
|
||||
context_override = {"area": area}
|
||||
return context_override
|
||||
|
||||
|
||||
def bm_split_edge_at_offset(edge, offset):
|
||||
v0, v1 = edge.verts
|
||||
|
||||
@@ -371,7 +359,7 @@ class EnableEditingRailingPath(bpy.types.Operator, tool.Ifc.Operator):
|
||||
|
||||
if bpy.context.object.mode != "EDIT":
|
||||
bpy.ops.object.mode_set(mode="EDIT")
|
||||
bpy.ops.wm.tool_set_by_id(blender_get_viewport_context(), name="bim.cad_tool")
|
||||
bpy.ops.wm.tool_set_by_id(tool.Blender.get_viewport_context(), name="bim.cad_tool")
|
||||
ProfileDecorator.install(context)
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@ import blenderbim
|
||||
import blenderbim.tool as tool
|
||||
from blenderbim.bim.helper import convert_property_group_from_si
|
||||
from blenderbim.bim.module.model.door import bm_sort_out_geom
|
||||
from blenderbim.bim.module.model.railing import blender_get_viewport_context
|
||||
from blenderbim.bim.module.model.data import RoofData, refresh
|
||||
from blenderbim.bim.module.model.decorator import ProfileDecorator
|
||||
|
||||
@@ -388,7 +387,7 @@ class EnableEditingRoofPath(bpy.types.Operator, tool.Ifc.Operator):
|
||||
|
||||
if bpy.context.object.mode != "EDIT":
|
||||
bpy.ops.object.mode_set(mode="EDIT")
|
||||
bpy.ops.wm.tool_set_by_id(blender_get_viewport_context(), name="bim.cad_tool")
|
||||
bpy.ops.wm.tool_set_by_id(tool.Blender.get_viewport_context(), name="bim.cad_tool")
|
||||
ProfileDecorator.install(context)
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
@@ -614,7 +614,7 @@ class EnableEditingExtrusionProfile(bpy.types.Operator, tool.Ifc.Operator):
|
||||
ProfileDecorator.install(context)
|
||||
# TODO: test it from properties panel?
|
||||
if not bpy.app.background:
|
||||
bpy.ops.wm.tool_set_by_id(name="bim.cad_tool")
|
||||
bpy.ops.wm.tool_set_by_id(tool.Blender.get_viewport_context(), name="bim.cad_tool")
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
|
||||
@@ -139,7 +139,7 @@ class EnableEditingArbitraryProfile(bpy.types.Operator, tool.Ifc.Operator):
|
||||
bpy.context.view_layer.objects.active = obj
|
||||
bpy.ops.object.mode_set(mode="EDIT")
|
||||
ProfileDecorator.install(context)
|
||||
bpy.ops.wm.tool_set_by_id(name="bim.cad_tool")
|
||||
bpy.ops.wm.tool_set_by_id(tool.Blender.get_viewport_context(), name="bim.cad_tool")
|
||||
|
||||
|
||||
class DisableEditingArbitraryProfile(bpy.types.Operator, tool.Ifc.Operator):
|
||||
|
||||
@@ -126,3 +126,16 @@ class Blender:
|
||||
if not clean:
|
||||
bm.from_mesh(mesh)
|
||||
return bm
|
||||
|
||||
@classmethod
|
||||
def get_viewport_context(cls):
|
||||
"""Get viewport area context for context overriding.
|
||||
|
||||
Useful for calling operators outside viewport context.
|
||||
|
||||
It's a bit naive since it's just taking the first available `VIEW_3D` area
|
||||
when in real life you can have a couple of those but should work for the most cases.
|
||||
"""
|
||||
area = next(area for area in bpy.context.screen.areas if area.type == "VIEW_3D")
|
||||
context_override = {"area": area}
|
||||
return context_override
|
||||
Reference in New Issue
Block a user