@@ -1631,7 +1631,7 @@ def convertMo2Fmu(
16311631 fmuType : str = "me_cs" ,
16321632 fileNamePrefix : Optional [str ] = None ,
16331633 includeResources : bool = True ,
1634- ) -> str :
1634+ ) -> OMCPath :
16351635 """Translate the model into a Functional Mockup Unit.
16361636
16371637 Args:
@@ -1658,15 +1658,19 @@ def convertMo2Fmu(
16581658 properties = (f'version="{ version } ", fmuType="{ fmuType } ", '
16591659 f'fileNamePrefix="{ fileNamePrefix } ", includeResources={ includeResourcesStr } ' )
16601660 fmu = self ._requestApi (apiName = 'buildModelFMU' , entity = self ._model_name , properties = properties )
1661+ fmu_path = self ._session .omcpath (fmu )
16611662
16621663 # report proper error message
1663- if not os . path . exists ( fmu ):
1664- raise ModelicaSystemError (f"Missing FMU file: { fmu } " )
1664+ if not fmu_path . is_file ( ):
1665+ raise ModelicaSystemError (f"Missing FMU file: { fmu_path . as_posix () } " )
16651666
1666- return fmu
1667+ return fmu_path
16671668
16681669 # to convert FMU to Modelica model
1669- def convertFmu2Mo (self , fmuName ): # 20
1670+ def convertFmu2Mo (
1671+ self ,
1672+ fmu : os .PathLike ,
1673+ ) -> OMCPath :
16701674 """
16711675 In order to load FMU, at first it needs to be translated into Modelica model. This method is used to generate
16721676 Modelica model from the given FMU. It generates "fmuName_me_FMU.mo".
@@ -1675,13 +1679,24 @@ def convertFmu2Mo(self, fmuName): # 20
16751679 >>> convertFmu2Mo("c:/BouncingBall.Fmu")
16761680 """
16771681
1678- fileName = self ._requestApi (apiName = 'importFMU' , entity = fmuName )
1682+ fmu_path = self ._session .omcpath (fmu )
1683+
1684+ if not fmu_path .is_file ():
1685+ raise ModelicaSystemError (f"Missing FMU file: { fmu_path .as_posix ()} " )
1686+
1687+ filename = self ._requestApi (apiName = 'importFMU' , entity = fmu_path .as_posix ())
1688+ filepath = self ._work_dir / filename
16791689
16801690 # report proper error message
1681- if not os .path .exists (fileName ):
1682- raise ModelicaSystemError (f"Missing file { fileName } " )
1691+ if not filepath .is_file ():
1692+ raise ModelicaSystemError (f"Missing file { filepath .as_posix ()} " )
1693+
1694+ self .model (
1695+ name = f"{ fmu_path .stem } _me_FMU" ,
1696+ file = filepath ,
1697+ )
16831698
1684- return fileName
1699+ return filepath
16851700
16861701 def optimize (self ) -> dict [str , Any ]:
16871702 """Perform model-based optimization.
0 commit comments