3838import logging
3939import numbers
4040import os
41+ import pathlib
4142import queue
4243import textwrap
4344import threading
@@ -439,18 +440,30 @@ def model(
439440 # set variables
440441 self ._model_name = name # Model class name
441442 self ._libraries = libraries # may be needed if model is derived from other model
442- if file is not None :
443- file_name = self ._session .omcpath (file ).resolve ()
444- else :
445- file_name = None
446- self ._file_name = file_name # Model file/package name
447443 self ._variable_filter = variable_filter
448444
449- if self ._file_name is not None and not self ._file_name .is_file (): # if file does not exist
450- raise IOError (f"{ self ._file_name } does not exist!" )
451-
452445 if self ._libraries :
453446 self ._loadLibrary (libraries = self ._libraries )
447+
448+ self ._file_name = None
449+ if file is not None :
450+ file_path = pathlib .Path (file )
451+ # special handling for OMCProcessLocal - consider a relative path
452+ if isinstance (self ._session .omc_process , OMCProcessLocal ) and not file_path .is_absolute ():
453+ file_path = pathlib .Path .cwd () / file_path
454+ if not file_path .is_file ():
455+ raise IOError (f"Model file { file_path } does not exist!" )
456+
457+ self ._file_name = self .getWorkDirectory () / file_path .name
458+ if (isinstance (self ._session .omc_process , OMCProcessLocal )
459+ and file_path .as_posix () == self ._file_name .as_posix ()):
460+ pass
461+ elif self ._file_name .is_file ():
462+ raise IOError (f"Simulation model file { self ._file_name } exist - not overwriting!" )
463+ else :
464+ content = file_path .read_text (encoding = 'utf-8' )
465+ self ._file_name .write_text (content )
466+
454467 if self ._file_name is not None :
455468 self ._loadFile (fileName = self ._file_name )
456469
@@ -1629,7 +1642,7 @@ def convertMo2Fmu(
16291642 properties = (f'version="{ version } ", fmuType="{ fmuType } ", '
16301643 f'fileNamePrefix="{ fileNamePrefix } ", includeResources={ includeResourcesStr } ' )
16311644 fmu = self ._requestApi (apiName = 'buildModelFMU' , entity = self ._model_name , properties = properties )
1632- fmu_path = self ._getconn .omcpath (fmu )
1645+ fmu_path = self ._session .omcpath (fmu )
16331646
16341647 # report proper error message
16351648 if not fmu_path .is_file ():
@@ -1650,13 +1663,13 @@ def convertFmu2Mo(
16501663 >>> convertFmu2Mo("c:/BouncingBall.Fmu")
16511664 """
16521665
1653- fmu_path = self ._getconn .omcpath (fmu )
1666+ fmu_path = self ._session .omcpath (fmu )
16541667
16551668 if not fmu_path .is_file ():
16561669 raise ModelicaSystemError (f"Missing FMU file: { fmu_path .as_posix ()} " )
16571670
16581671 filename = self ._requestApi (apiName = 'importFMU' , entity = fmu_path .as_posix ())
1659- filepath = self ._getconn .omcpath (filename )
1672+ filepath = self ._session .omcpath (filename )
16601673
16611674 # report proper error message
16621675 if not filepath .is_file ():
0 commit comments