mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-21 14:23:53 +00:00
Let users set their own app to open SVGs and PDFs
This commit is contained in:
@@ -5,6 +5,7 @@ import time
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import webbrowser
|
import webbrowser
|
||||||
|
import subprocess
|
||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
import ifcopenshell.util.selector
|
import ifcopenshell.util.selector
|
||||||
import ifcopenshell.util.geolocation
|
import ifcopenshell.util.geolocation
|
||||||
@@ -63,6 +64,15 @@ def set_active_camera_resolution(scene):
|
|||||||
bpy.ops.bim.activate_view(drawing_index=scene.DocProperties.current_drawing_index)
|
bpy.ops.bim.activate_view(drawing_index=scene.DocProperties.current_drawing_index)
|
||||||
|
|
||||||
|
|
||||||
|
def open_with_user_command(user_command, path):
|
||||||
|
if user_command:
|
||||||
|
commands = eval(user_command)
|
||||||
|
for command in commands:
|
||||||
|
subprocess.run(command)
|
||||||
|
else:
|
||||||
|
webbrowser.open('file://' + path)
|
||||||
|
|
||||||
|
|
||||||
class ExportIFC(bpy.types.Operator):
|
class ExportIFC(bpy.types.Operator):
|
||||||
bl_idname = "export_ifc.bim"
|
bl_idname = "export_ifc.bim"
|
||||||
bl_label = "Export IFC"
|
bl_label = "Export IFC"
|
||||||
@@ -2094,9 +2104,9 @@ class OpenView(bpy.types.Operator):
|
|||||||
view: bpy.props.StringProperty()
|
view: bpy.props.StringProperty()
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
webbrowser.open('file://' + os.path.join(
|
open_with_user_command(
|
||||||
bpy.context.scene.BIMProperties.data_dir, 'diagrams',
|
bpy.context.preferences.addons['blenderbim'].preferences.svg_command,
|
||||||
self.view + '.svg'))
|
os.path.join(bpy.context.scene.BIMProperties.data_dir, 'diagrams', self.view + '.svg'))
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
|
||||||
@@ -2295,9 +2305,11 @@ class OpenSheet(bpy.types.Operator):
|
|||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
props = bpy.context.scene.DocProperties
|
props = bpy.context.scene.DocProperties
|
||||||
webbrowser.open('file://' + os.path.join(
|
open_with_user_command(
|
||||||
bpy.context.scene.BIMProperties.data_dir, 'sheets',
|
bpy.context.preferences.addons['blenderbim'].preferences.svg_command,
|
||||||
props.sheets[props.active_sheet_index].name + '.svg'))
|
os.path.join(
|
||||||
|
bpy.context.scene.BIMProperties.data_dir, 'sheets',
|
||||||
|
props.sheets[props.active_sheet_index].name + '.svg'))
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
|
||||||
@@ -2330,8 +2342,9 @@ class CreateSheets(bpy.types.Operator):
|
|||||||
sheet_builder.build(name)
|
sheet_builder.build(name)
|
||||||
|
|
||||||
svg2pdf_command = bpy.context.preferences.addons['blenderbim'].preferences.svg2pdf_command
|
svg2pdf_command = bpy.context.preferences.addons['blenderbim'].preferences.svg2pdf_command
|
||||||
|
svg2dxf_command = bpy.context.preferences.addons['blenderbim'].preferences.svg2dxf_command
|
||||||
|
|
||||||
if svg2pdf_command:
|
if svg2pdf_command:
|
||||||
import subprocess
|
|
||||||
path = os.path.join(bpy.context.scene.BIMProperties.data_dir, 'build', name)
|
path = os.path.join(bpy.context.scene.BIMProperties.data_dir, 'build', name)
|
||||||
svg = os.path.join(path, name + '.svg')
|
svg = os.path.join(path, name + '.svg')
|
||||||
pdf = os.path.join(path, name + '.pdf')
|
pdf = os.path.join(path, name + '.pdf')
|
||||||
@@ -2341,9 +2354,7 @@ class CreateSheets(bpy.types.Operator):
|
|||||||
for command in commands:
|
for command in commands:
|
||||||
subprocess.run(command)
|
subprocess.run(command)
|
||||||
|
|
||||||
svg2dxf_command = bpy.context.preferences.addons['blenderbim'].preferences.svg2dxf_command
|
|
||||||
if svg2dxf_command:
|
if svg2dxf_command:
|
||||||
import subprocess
|
|
||||||
path = os.path.join(bpy.context.scene.BIMProperties.data_dir, 'build', name)
|
path = os.path.join(bpy.context.scene.BIMProperties.data_dir, 'build', name)
|
||||||
svg = os.path.join(path, name + '.svg')
|
svg = os.path.join(path, name + '.svg')
|
||||||
eps = os.path.join(path, name + '.eps')
|
eps = os.path.join(path, name + '.eps')
|
||||||
@@ -2357,9 +2368,11 @@ class CreateSheets(bpy.types.Operator):
|
|||||||
|
|
||||||
|
|
||||||
if svg2pdf_command:
|
if svg2pdf_command:
|
||||||
webbrowser.open('file://' + os.path.join(pdf))
|
open_with_user_command(bpy.context.preferences.addons['blenderbim'].preferences.pdf_command, pdf)
|
||||||
else:
|
else:
|
||||||
webbrowser.open('file://' + os.path.join(bpy.context.scene.BIMProperties.data_dir, 'build', name, name + '.svg'))
|
open_with_user_command(
|
||||||
|
bpy.context.preferences.addons['blenderbim'].preferences.svg_command,
|
||||||
|
os.path.join(bpy.context.scene.BIMProperties.data_dir, 'build', name, name + '.svg'))
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
|
||||||
@@ -3504,7 +3517,7 @@ class ExecuteBIMTester(bpy.types.Operator):
|
|||||||
os.chdir(bpy.context.scene.BIMProperties.features_dir)
|
os.chdir(bpy.context.scene.BIMProperties.features_dir)
|
||||||
bimtester.run_tests({'feature': filename, 'advanced_arguments': None, 'console': False})
|
bimtester.run_tests({'feature': filename, 'advanced_arguments': None, 'console': False})
|
||||||
bimtester.generate_report()
|
bimtester.generate_report()
|
||||||
webbrowser.open(os.path.join(
|
webbrowser.open('file://' + os.path.join(
|
||||||
bpy.context.scene.BIMProperties.features_dir,
|
bpy.context.scene.BIMProperties.features_dir,
|
||||||
'report', bpy.context.scene.BIMProperties.features_file + '.feature.html'))
|
'report', bpy.context.scene.BIMProperties.features_file + '.feature.html'))
|
||||||
os.chdir(cwd)
|
os.chdir(cwd)
|
||||||
@@ -3934,7 +3947,9 @@ class BuildSchedule(bpy.types.Operator):
|
|||||||
bpy.context.scene.BIMProperties.data_dir, 'schedules',
|
bpy.context.scene.BIMProperties.data_dir, 'schedules',
|
||||||
schedule.name + '.svg')
|
schedule.name + '.svg')
|
||||||
schedule_creator.schedule(schedule.file, outfile)
|
schedule_creator.schedule(schedule.file, outfile)
|
||||||
webbrowser.open('file://' + outfile)
|
open_with_user_command(
|
||||||
|
bpy.context.preferences.addons['blenderbim'].preferences.svg_command,
|
||||||
|
outfile)
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1825,6 +1825,8 @@ class BIM_ADDON_preferences(bpy.types.AddonPreferences):
|
|||||||
bl_idname = 'blenderbim'
|
bl_idname = 'blenderbim'
|
||||||
svg2pdf_command: StringProperty(name="SVG to PDF Command")
|
svg2pdf_command: StringProperty(name="SVG to PDF Command")
|
||||||
svg2dxf_command: StringProperty(name="SVG to DXF Command")
|
svg2dxf_command: StringProperty(name="SVG to DXF Command")
|
||||||
|
svg_command: StringProperty(name="SVG Command")
|
||||||
|
pdf_command: StringProperty(name="PDF Command")
|
||||||
|
|
||||||
def draw(self, context):
|
def draw(self, context):
|
||||||
layout = self.layout
|
layout = self.layout
|
||||||
@@ -1838,6 +1840,10 @@ class BIM_ADDON_preferences(bpy.types.AddonPreferences):
|
|||||||
row.prop(self, 'svg2pdf_command')
|
row.prop(self, 'svg2pdf_command')
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
row.prop(self, 'svg2dxf_command')
|
row.prop(self, 'svg2dxf_command')
|
||||||
|
row = layout.row()
|
||||||
|
row.prop(self, 'svg_command')
|
||||||
|
row = layout.row()
|
||||||
|
row.prop(self, 'pdf_command')
|
||||||
|
|
||||||
|
|
||||||
class BIM_PT_ifcclash(Panel):
|
class BIM_PT_ifcclash(Panel):
|
||||||
|
|||||||
Reference in New Issue
Block a user