mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 22:50:21 +00:00
bim.open_path - utility operator
This commit is contained in:
@@ -110,6 +110,7 @@ classes = [
|
|||||||
operator.EditBlenderCollection,
|
operator.EditBlenderCollection,
|
||||||
operator.FileAssociate,
|
operator.FileAssociate,
|
||||||
operator.FileUnassociate,
|
operator.FileUnassociate,
|
||||||
|
operator.OpenPath,
|
||||||
operator.OpenUpstream,
|
operator.OpenUpstream,
|
||||||
operator.OpenUri,
|
operator.OpenUri,
|
||||||
operator.ReloadIfcFile,
|
operator.ReloadIfcFile,
|
||||||
|
|||||||
@@ -93,6 +93,23 @@ class OpenUri(bpy.types.Operator):
|
|||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
|
class OpenPath(bpy.types.Operator):
|
||||||
|
bl_idname = "bim.open_path"
|
||||||
|
bl_label = "Open Path"
|
||||||
|
path: bpy.props.StringProperty()
|
||||||
|
tooltip: bpy.props.StringProperty()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def description(cls, context, properties):
|
||||||
|
if properties.tooltip:
|
||||||
|
return properties.tooltip
|
||||||
|
return f"Open path: '{properties.path}'."
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
tool.Blender.open_file_or_folder(self.path)
|
||||||
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
class CloseError(bpy.types.Operator):
|
class CloseError(bpy.types.Operator):
|
||||||
bl_idname = "bim.close_error"
|
bl_idname = "bim.close_error"
|
||||||
bl_label = "Close Error"
|
bl_label = "Close Error"
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import bmesh
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
|
import subprocess
|
||||||
from ifcopenshell import entity_instance
|
from ifcopenshell import entity_instance
|
||||||
import ifcopenshell.api
|
import ifcopenshell.api
|
||||||
import ifcopenshell.util.element
|
import ifcopenshell.util.element
|
||||||
@@ -832,6 +833,15 @@ class Blender(bonsai.core.tool.Blender):
|
|||||||
|
|
||||||
operator_invoke_filepath_hotkeys_description = "Hold Shift to open the file, Alt to browse containing directory"
|
operator_invoke_filepath_hotkeys_description = "Hold Shift to open the file, Alt to browse containing directory"
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def open_file_or_folder(cls, path: str) -> None:
|
||||||
|
if platform.system() == "Windows":
|
||||||
|
os.startfile(path)
|
||||||
|
elif platform.system() == "Darwin":
|
||||||
|
subprocess.Popen(["open", path])
|
||||||
|
else:
|
||||||
|
subprocess.Popen(["xdg-open", path])
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def operator_invoke_filepath_hotkeys(
|
def operator_invoke_filepath_hotkeys(
|
||||||
cls, operator: bpy.types.Operator, context: bpy.types.Context, event: bpy.types.Event, filepath: Path
|
cls, operator: bpy.types.Operator, context: bpy.types.Context, event: bpy.types.Event, filepath: Path
|
||||||
@@ -839,18 +849,6 @@ class Blender(bonsai.core.tool.Blender):
|
|||||||
if not event.alt and not event.shift:
|
if not event.alt and not event.shift:
|
||||||
return
|
return
|
||||||
|
|
||||||
import platform
|
|
||||||
import os
|
|
||||||
import subprocess
|
|
||||||
|
|
||||||
def open_file_or_folder(path):
|
|
||||||
if platform.system() == "Windows":
|
|
||||||
os.startfile(path)
|
|
||||||
elif platform.system() == "Darwin":
|
|
||||||
subprocess.Popen(["open", path])
|
|
||||||
else:
|
|
||||||
subprocess.Popen(["xdg-open", path])
|
|
||||||
|
|
||||||
# resolve relative filepaths with .blend path by default
|
# resolve relative filepaths with .blend path by default
|
||||||
if not filepath.is_absolute():
|
if not filepath.is_absolute():
|
||||||
if bpy.data.filepath:
|
if bpy.data.filepath:
|
||||||
@@ -866,14 +864,14 @@ class Blender(bonsai.core.tool.Blender):
|
|||||||
if not filepath.exists():
|
if not filepath.exists():
|
||||||
operator.report({"ERROR"}, f'Cannot open non-existing directory: "{filepath.as_posix()}"')
|
operator.report({"ERROR"}, f'Cannot open non-existing directory: "{filepath.as_posix()}"')
|
||||||
return {"CANCELLED"}
|
return {"CANCELLED"}
|
||||||
open_file_or_folder(filepath.as_posix())
|
cls.open_file_or_folder(filepath.as_posix())
|
||||||
return {"PASS_THROUGH"}
|
return {"PASS_THROUGH"}
|
||||||
|
|
||||||
# holding sHIFT - open file
|
# holding sHIFT - open file
|
||||||
if not filepath.exists():
|
if not filepath.exists():
|
||||||
operator.report({"ERROR"}, f'Cannot open non-existing file: "{filepath.as_posix()}"')
|
operator.report({"ERROR"}, f'Cannot open non-existing file: "{filepath.as_posix()}"')
|
||||||
return {"CANCELLED"}
|
return {"CANCELLED"}
|
||||||
open_file_or_folder(filepath.as_posix())
|
cls.open_file_or_folder(filepath.as_posix())
|
||||||
return {"PASS_THROUGH"}
|
return {"PASS_THROUGH"}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|||||||
Reference in New Issue
Block a user