mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 09:21:46 +00:00
bim.open_path - utility operator
This commit is contained in:
@@ -110,6 +110,7 @@ classes = [
|
||||
operator.EditBlenderCollection,
|
||||
operator.FileAssociate,
|
||||
operator.FileUnassociate,
|
||||
operator.OpenPath,
|
||||
operator.OpenUpstream,
|
||||
operator.OpenUri,
|
||||
operator.ReloadIfcFile,
|
||||
|
||||
@@ -93,6 +93,23 @@ class OpenUri(bpy.types.Operator):
|
||||
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):
|
||||
bl_idname = "bim.close_error"
|
||||
bl_label = "Close Error"
|
||||
|
||||
@@ -22,6 +22,7 @@ import bmesh
|
||||
import json
|
||||
import os
|
||||
import platform
|
||||
import subprocess
|
||||
from ifcopenshell import entity_instance
|
||||
import ifcopenshell.api
|
||||
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"
|
||||
|
||||
@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
|
||||
def operator_invoke_filepath_hotkeys(
|
||||
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:
|
||||
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
|
||||
if not filepath.is_absolute():
|
||||
if bpy.data.filepath:
|
||||
@@ -866,14 +864,14 @@ class Blender(bonsai.core.tool.Blender):
|
||||
if not filepath.exists():
|
||||
operator.report({"ERROR"}, f'Cannot open non-existing directory: "{filepath.as_posix()}"')
|
||||
return {"CANCELLED"}
|
||||
open_file_or_folder(filepath.as_posix())
|
||||
cls.open_file_or_folder(filepath.as_posix())
|
||||
return {"PASS_THROUGH"}
|
||||
|
||||
# holding sHIFT - open file
|
||||
if not filepath.exists():
|
||||
operator.report({"ERROR"}, f'Cannot open non-existing file: "{filepath.as_posix()}"')
|
||||
return {"CANCELLED"}
|
||||
open_file_or_folder(filepath.as_posix())
|
||||
cls.open_file_or_folder(filepath.as_posix())
|
||||
return {"PASS_THROUGH"}
|
||||
|
||||
@classmethod
|
||||
|
||||
Reference in New Issue
Block a user