Skip to content

Commit 03b9af8

Browse files
committed
mcdisplay-cad: Warn if cadquery is missing / open created file via OS hook
1 parent 313186f commit 03b9af8

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

tools/Python/mcdisplay/cad/mcdisplay.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010

1111
import sys
1212
from pathlib import Path
13+
import subprocess
1314

1415
sys.path.append(str(Path(__file__).resolve().parent.parent.parent))
1516
from mccodelib.instrgeom import Vector3d, DrawLine, DrawMultiline, DrawCircle
17+
from mccodelib import mccode_config
1618

1719

1820
def vector_to_tuple(v: Vector3d):
@@ -140,8 +142,19 @@ def instrument_to_assembly(inst):
140142

141143
def main(instr=None, dirname=None, **kwds):
142144
from logging import basicConfig, INFO
145+
import time
143146
basicConfig(level=INFO)
144147

148+
try:
149+
# Try initial import or inform to install cadquery
150+
from cadquery.occ_impl.geom import Matrix
151+
except:
152+
message="To use this display tool, please install the 'cadquery' Python package"
153+
subprocess.Popen('%s %s' % (mccode_config.configuration['MCCODE']+"_errmsg", message), shell=True)
154+
print(mccode_config.configuration['MCCODE']+": "+ message)
155+
time.sleep(3)
156+
quit()
157+
145158
# output directory
146159
if dirname is None:
147160
from datetime import datetime as dt
@@ -158,7 +171,12 @@ def main(instr=None, dirname=None, **kwds):
158171

159172
# Do the conversion to a CadQuery assembly, then save it to the desired location
160173
assembly = instrument_to_assembly(instrument)
161-
assembly.save(str(root.joinpath(f"{Path(instr).stem}.{kwds.get('format','step')}")))
174+
output = str(root.joinpath(f"{Path(instr).stem}.{kwds.get('format','step')}"))
175+
assembly.save(output)
176+
177+
# Use mccode_config / the OS to open the resulting file...
178+
if Path(output).is_file():
179+
subprocess.Popen('%s %s' % (mccode_config.configuration['BROWSER'], output), shell=True)
162180

163181
def output_format(astring):
164182
f = astring.lower()

0 commit comments

Comments
 (0)