@@ -187,9 +187,11 @@ export async function readObjFilesContent(
187187}
188188
189189/**
190- * Finds the .*med files corresponding to a given .comm file by reading .export files in the same folder.
190+ * Finds med files corresponding to a given .comm file by reading .export files in the same folder.
191+ * Looks for F lines whose type field ends with "med" (e.g. mmed, rmed) and ioFlag is "D".
192+ * The med file may have any extension (e.g. .med, .21, .17).
191193 * @param commFilePath Path to the .comm file
192- * @returns Paths to the .* med files if found, [] otherwise
194+ * @returns Paths to the med files if found, [] otherwise
193195 */
194196export function findMedFiles ( commFilePath : string ) : string [ ] {
195197 try {
@@ -218,34 +220,36 @@ export function findMedFiles(commFilePath: string): string[] {
218220
219221 const lines = content . split ( / \r ? \n / ) ;
220222 for ( const line of lines ) {
221- if ( ! / \b D \b / . test ( line ) ) {
223+ const cleanLine = line . split ( "#" ) [ 0 ] . trim ( ) ;
224+ const tokens = cleanLine . split ( / \s + / ) ;
225+
226+ if ( tokens . length !== 5 || tokens [ 0 ] !== "F" ) {
222227 continue ;
223228 }
224229
225- const match = line . match ( / ( [ \w \- . / \\ ] + \. [ a - z ] ? m e d ) \b / i) ;
226- if ( match ) {
227- const medFileName = path . basename ( match [ 1 ] ) ;
228- const medPath = path . join ( dir , medFileName ) ;
229-
230- if ( fs . existsSync ( medPath ) ) {
231- console . log ( `[findMedFiles] found med file: ${ medFileName } ` ) ;
232- foundMedFiles . push ( medPath ) ;
233- } else {
234- vscode . window . showErrorMessage (
235- `The file "${ medFileName } " mentioned in "${ exportFile } " does not exist in the current directory (${ path . basename (
236- dir ,
237- ) } /).`,
238- ) ;
239- }
230+ const [ , type , name , ioFlag ] = tokens ;
231+
232+ if ( ! type . endsWith ( "med" ) || ioFlag !== "D" ) {
233+ continue ;
234+ }
235+
236+ const medFileName = path . basename ( name ) ;
237+ const medPath = path . join ( dir , medFileName ) ;
238+
239+ if ( fs . existsSync ( medPath ) ) {
240+ console . log ( `[findMedFiles] found med file: ${ medFileName } ` ) ;
241+ foundMedFiles . push ( medPath ) ;
242+ } else {
243+ vscode . window . showErrorMessage (
244+ `The file "${ medFileName } " mentioned in "${ exportFile } " does not exist in the current directory (${ path . basename ( dir ) } /).` ,
245+ ) ;
240246 }
241247 }
242248 }
243249
244250 if ( foundMedFiles . length === 0 ) {
245251 vscode . window . showErrorMessage (
246- `No .export file in "${ path . basename (
247- dir ,
248- ) } /" references any entry .med file associated with ${ commFileName } .`,
252+ `No .export file in "${ path . basename ( dir ) } /" references any input med file associated with ${ commFileName } .` ,
249253 ) ;
250254 }
251255
@@ -350,18 +354,36 @@ async function generateObjFromMed(
350354 ) ;
351355
352356 let stderr = "" ;
357+ let settled = false ;
353358
354359 process . stderr . on ( "data" , ( data ) => {
355360 stderr += data . toString ( ) ;
356361 console . log ( `[generateObjFromMed] stderr: ${ data } ` ) ;
357362 } ) ;
358363
359- process . on ( "error" , ( err ) => {
364+ process . on ( "error" , ( err : NodeJS . ErrnoException ) => {
365+ if ( settled ) {
366+ return ;
367+ }
368+ settled = true ;
360369 console . error ( `[generateObjFromMed] Process error: ${ err . message } ` ) ;
361- reject ( new Error ( `Failed to generate .obj file: ${ err . message } ` ) ) ;
370+ if ( err . code === "ENOENT" ) {
371+ reject (
372+ new Error (
373+ `Python executable not found: "${ pythonExecutablePath } ". ` +
374+ `Please update the "vs-code-aster.pythonExecutablePath" setting.` ,
375+ ) ,
376+ ) ;
377+ } else {
378+ reject ( new Error ( `Failed to generate .obj file: ${ err . message } ` ) ) ;
379+ }
362380 } ) ;
363381
364382 process . on ( "close" , ( code ) => {
383+ if ( settled ) {
384+ return ;
385+ }
386+ settled = true ;
365387 if ( code === 0 ) {
366388 console . log (
367389 `[generateObjFromMed] Successfully generated: ${ objFilePath } ` ,
0 commit comments