Skip to content

Commit

Permalink
reinstitute nargout for matlab and earlier octave support
Browse files Browse the repository at this point in the history
  • Loading branch information
Rostislav V. Rjabow committed Dec 6, 2022
1 parent 5bad46a commit 09cd00b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
11 changes: 10 additions & 1 deletion blender2mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,12 @@ def func(self):
try:
if bpy.context.scene.blender_photonics.backend == "octave":
import oct2py as op
from oct2py.utils import Oct2PyError as OcError1
OcError2 = OcError1
oc = op.Oct2Py()
else:
import matlab.engine as op
from matlab.engine import MatlabExecutionError as OcError1, RejectedExecutionError as OcError2
oc = op.start_matlab()
except ImportError:
raise ImportError(
Expand All @@ -180,7 +183,13 @@ def func(self):

oc.addpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'script'))

oc.feval('blender2mesh', os.path.join(outputdir, 'blendermesh.jmsh'), nout=0)
try:
oc.feval('blender2mesh', os.path.join(outputdir, 'blendermesh.jmsh'), nargout=0)
except OcError1 as e:
if 'too many outputs' in e.args[0]:
oc.feval('blender2mesh', os.path.join(outputdir, 'blendermesh.jmsh'), nout=0)
else:
raise

# import volume mesh to blender(just for user to check the result)
bpy.ops.object.select_all(action='SELECT')
Expand Down
11 changes: 10 additions & 1 deletion nii2mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,26 @@ def vol2mesh(self):
try:
if bpy.context.scene.blender_photonics.backend == "octave":
import oct2py as op
from oct2py.utils import Oct2PyError as OcError1
OcError2 = OcError1
oc = op.Oct2Py()
else:
import matlab.engine as op
from matlab.engine import MatlabExecutionError as OcError1, RejectedExecutionError as OcError2
oc = op.start_matlab()
except ImportError:
raise ImportError(
'To run this feature, you must install the `oct2py` or `matlab.engine` Python module first, '
'based on your choice of the backend')

oc.addpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'script'))
oc.feval('nii2mesh', os.path.join(outputdir, 'niipath.json'), nout=0)
try:
oc.feval('nii2mesh', os.path.join(outputdir, 'niipath.json'), nargout=0)
except OcError1 as e:
if 'too many outputs' in e.args[0]:
oc.feval('nii2mesh', os.path.join(outputdir, 'niipath.json'), nout=0)
else:
raise

# import volum mesh to blender(just for user to check the result)
bpy.ops.object.select_all(action='SELECT')
Expand Down
11 changes: 10 additions & 1 deletion obj2surf.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,12 @@ def func(self):
try:
if bpy.context.scene.blender_photonics.backend == "octave":
import oct2py as op
from oct2py.utils import Oct2PyError as OcError1
OcError2 = OcError1
oc = op.Oct2Py()
else:
import matlab.engine as op
from matlab.engine import MatlabExecutionError as OcError1, RejectedExecutionError as OcError2
oc = op.start_matlab()
except ImportError:
raise ImportError(
Expand All @@ -133,7 +136,13 @@ def func(self):

oc.addpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'script'))

oc.feval('blender2surf', os.path.join(outputdir, 'blendersurf.jmsh'), nout=0)
try:
oc.feval('blender2surf', os.path.join(outputdir, 'blendersurf.jmsh'), nargout=0)
except OcError1 as e:
if 'too many outputs' in e.args[0]:
oc.feval('blender2surf', os.path.join(outputdir, 'blendersurf.jmsh'), nout=0)
else:
raise

# import volum mesh to blender(just for user to check the result)
if len(bpy.context.selected_objects) >= 1:
Expand Down
14 changes: 12 additions & 2 deletions runmmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,12 @@ def preparemmc(self):
try:
if bpy.context.scene.blender_photonics.backend == "octave":
import oct2py as op
from oct2py.utils import Oct2PyError as OcError1
OcError2 = OcError1
oc = op.Oct2Py()
else:
import matlab.engine as op
from matlab.engine import MatlabExecutionError as OcError1, RejectedExecutionError as OcError2
oc = op.start_matlab()
except ImportError:
raise ImportError(
Expand All @@ -109,8 +112,15 @@ def preparemmc(self):

oc.addpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'script'))

oc.feval('blendermmc', os.path.join(outputdir, 'mmcinfo.json'), os.path.join(outputdir, 'meshdata.mat'),
nout=0)
try:
oc.feval('blendermmc', os.path.join(outputdir, 'mmcinfo.json'), os.path.join(outputdir, 'meshdata.mat'),
nargout=0)
except OcError1 as e:
if 'too many outputs' in e.args[0]:
oc.feval('blendermmc', os.path.join(outputdir, 'mmcinfo.json'), os.path.join(outputdir, 'meshdata.mat'),
nout=0)
else:
raise

# remove all object and import all region as one object
bpy.ops.object.select_all(action='SELECT')
Expand Down

0 comments on commit 09cd00b

Please sign in to comment.