PDA

View Full Version : Batch translate compressed files to DXF


mambrose
02-27-2007, 11:05 AM
I need a macro that takes all files in a dir and loads them in ME10 and then store them with same name +.dxf.

clausb
02-27-2007, 01:05 PM
See the recent discussion at http://cocreateusers.org/forum/showthread.php?t=6134

mambrose
03-01-2007, 04:40 AM
What I have are directories full of compressed mi files with no mi extension, so I can not use the batch translate MI to DXF in the provided translator. I need a macro that will translate these files to the standard model interface mi file and also add the mi extension. At that point I can use the batch translation function of the translator.

ofischer
03-01-2007, 11:18 PM
Hello,
Test this macro. You must hace a repertory 'C:\temp'
Input the macro file and run the macro with a the directory of the drawing for parameter:
creerdxf 'C:\xxx\xxx\drawing_repertory'

DEFINE net_fin_lig
LOCAL LONGLIG
LOOP
LET LONGLIG (LEN(LIGNE))
LET CARACT (SUBSTR LIGNE LONGLIG 1)
EXIT_IF ((CARACT <> ' ') AND (CARACT <> ''))
IF (CARACT = ' ')
LET LIGNE (SUBSTR LIGNE 1 (LONGLIG-1))
END_IF
END_LOOP
END_DEFINE

DEFINE Menage
CLEAN_DRAWING CLEAN_CLEAN_GAPS GLOBAL 0.01 CONFIRM END
CLEAN_DRAWING CLEAN_STACKED_GEOMETRY GLOBAL 0.01 CONFIRM END
CLEAN_DRAWING CLEAN_STAGGERED_GEOMETRY GLOBAL 0.01 CONFIRM END
CLEAN_DRAWING CLEAN_DUPLICATE_GEOMETRY GLOBAL 0.01 CONFIRM END
END_DEFINE

DEFINE Change_police_cotation_et_texte
CHANGE_DIM_TEXTS DIM_ALL FONT 'hp_i3098_v' SELECT DIMENSIONS ALL CONFIRM
CHANGE_TEXT_FONTNAME 'hp_i3098_v' SELECT GLOBAL TEXTS ALL CONFIRM
END_DEFINE

DEFINE creerdxf
LOCAL Charge_dir
LOCAL Sauve_dir
LOCAL Tmp_dir
LOCAL REPBASE
LOCAL DAT
LOCAL TIM
LET Tmp_dir 'c:\temp\'
READ 'Identifiez le rÅpertoire È traiter: ' REPBASE
LET Charge_dir (REPBASE)
RUN ('mkdir ' + (Charge_dir + '\dxf'))
LET Charge_dir (Charge_dir + '\')
LET Sauve_dir (Charge_dir + 'dxf\')
RUN ('date /T > ' + (Tmp_dir + 'datetime.txt'))
OPEN_INFILE 2 (Tmp_dir + 'datetime.txt')
READ_FILE 2 DAT
RUN ('time /T >> ' + (Tmp_dir + 'datetime.txt'))
READ_FILE 2 TIM
CLOSE_FILE 2
OPEN_OUTFILE 8 APPEND (Sauve_dir + 'plan_traite.txt')
OPEN_OUTFILE 7 APPEND (Sauve_dir + 'plan_erreur_conversion.txt')
WRITE_FILE 7 '********************************************'
WRITE_FILE 7 ' '
WRITE_FILE 7 ('Traitement du: ' + DAT + ' à ' + TIM )
WRITE_FILE 7 ' '
WRITE_FILE 7 '********************************************'
WRITE_FILE 8 '********************************************'
WRITE_FILE 8 ' '
WRITE_FILE 8 ('Traitement du: ' + DAT + ' à ' + TIM )
WRITE_FILE 8 ' '
WRITE_FILE 8 '********************************************'
RUN ('DIR *.* /B ' + Charge_dir + ' > ' + Tmp_dir + 'liste.txt') {Liste courte du rep à traiter}
OPEN_INFILE 1 (Tmp_dir + 'liste.txt')
READ_FILE 1 LIGNE
IF (LIGNE = 'END-OF-FILE')
DISPLAY ('ERREUR: Aucun plan È migrer !!!!')
ELSE
CLOSE_FILE 1
OPEN_INFILE 1 (Tmp_dir + 'liste.txt')
LOOP
READ_FILE 1 LIGNE
EXIT_IF (LIGNE = 'END-OF-FILE')
IF ((LIGNE <> '') AND (LIGNE <> 'workfile') AND (LIGNE <> 'hp_catlock') AND (LIGNE <> 'hp_catfile'))
net_fin_lig
EDIT_PART TOP
DELETE ALL CONFIRM END
TRAP_ERROR
LOAD (Charge_dir + LIGNE)
INQ_SELECTED_ELEM ALL END
IF ((INQ 14) <> 0)
IF (CHECK_ERROR )
END
BEEP
WRITE_FILE 7 ('ERREUR: lecture ME10: '+ Charge_dir + LIGNE )
END
END_IF
SPLINE_CONVERSION ON
EDIT_PART TOP
TRAP_ERROR
STORE DXF ALL DEL_OLD (Sauve_dir + LIGNE){}
IF (CHECK_ERROR )
END
BEEP
WRITE_FILE 7 ('ERREUR: sauvegarde dxf : '+ Charge_dir + LIGNE )
END
ELSE
WRITE_FILE 8 ('sauvegarde dxf : '+ Charge_dir + LIGNE )
END_IF
ELSE
BEEP
WRITE_FILE 7 ('ERREUR: fichier vide: '+ Charge_dir + LIGNE )
END_IF
EDIT_PART TOP
DELETE ALL CONFIRM END
TRAP_ERROR
ELSE
WRITE_FILE 7 ('ERREUR: au chargement du fichier: '+ Charge_dir + LIGNE )
END_IF
EXIT_IF (LIGNE = 'workfile')
EXIT_IF (LIGNE = 'hp_catlock')
EXIT_IF (LIGNE = 'hp_catfile')
END_LOOP
END_IF
EDIT_PART TOP
DELETE ALL CONFIRM END
RUN ( 'del ' + (Tmp_dir + 'liste.txt'))
RUN ( 'del ' + (Tmp_dir + 'datetime.txt'))
CLOSE_FILE 1
WRITE_FILE 8 '********************************************'
CLOSE_FILE 8
WRITE_FILE 7 '********************************************'
CLOSE_FILE 7
END_DEFINE

John Scheffel
03-02-2007, 10:35 AM
Here is a macro which I think will do what you want. It will attempt to load all the files in the current directory and save them as MI with a ".mi" appended to the loaded file name. You can set the current directory by opening any file in a directory before running the macro or using the CURRENT_DIRECTORY command. Or you can replace the '.' in the CATALOG line of the macro with a directory path. If you want to convert directly to DXF then comment the STORE MI... line and uncomment the STORE DXF... line.

It is not very sophisticated. It will convert all the files it can load and does not check the type. But based on your description of what you have I think it will work. It will only convert the files in the specified directory, it will not convert any files in subdirectories under that directory.
Edit: The original macro was corrected per the discussion below.

DEFINE Convert_all_to_mi
{ Convert all files in current directory to MI files}
LOCAL Tmp_file_name
LOCAL File_name
LOCAL Fileline
LET Tmp_file_name (MAKE_TMP_NAME)
CATALOG_LAYOUT (RPT ' ' 256) END
DEFINE_CATALOG 'file_name' 1 1
CATALOG '.' SELECT 'FILE_TYPE' 'Reg' DEL_OLD Tmp_file_name

OPEN_INFILE 1 Tmp_file_name
{ Read and discard the first 4 lines which are header info }
READ_FILE 1 Fileline
READ_FILE 1 Fileline
READ_FILE 1 Fileline
READ_FILE 1 Fileline

{ Attempt to load each file in the list and save as MI if successful }
LOOP
READ_FILE 1 Fileline
EXIT_IF (Fileline='END-OF-FILE')
LET File_name (TRIM Fileline)
RESET_SYSTEM CONFIRM
TRAP_ERROR
LOAD File_name
IF (CHECK_ERROR)
DISPLAY_NO_WAIT ('Could not load file: ' + File_name)
ELSE
STORE MI ALL DEL_OLD (File_name + '.mi')
{STORE DXF V1018 ALL DEL_OLD (File_name + '.dxf')}
{ to delete the original file uncomment the following line }
{PURGE_FILE File_name CONFIRM}
END_IF
END_LOOP
CLOSE_FILE 1
PURGE_FILE Tmp_file_name CONFIRM END
END_DEFINE

Wolfgang
03-04-2007, 08:31 AM
do you really need a MACRO?


why not using a shell script / Batch_file mode


dxfdwg [-option] [-t] [-k] [-b batch_file] [-e config_file] [-f source [dest [log]]]


dxfdwg -o -f infile-without-extension out-file.dxf

just tested:
dxfdwg.exe -o -f d:\A4 d:\a4.2.dxf
works fine.

If with the -b batch_file mode its working fine.


I assume the -o option is unkown to you?

John Scheffel
03-05-2007, 09:39 AM
do you really need a MACRO?

why not using a shell script / Batch_file mode....
The problem with this suggestion is that dxfdwg.exe does not work on compressed MI files even if you specify the file name. I tried it using version 2006 and got the message below.

"Not an ascii MI file!'

mambrose
03-27-2007, 08:45 AM
I tried this macro and it loads the first file in the directory and then saves that file to every other filename in the directory if that makes sense. It never deletes the first file and load the next.

John Scheffel
03-27-2007, 10:17 AM
I tried this macro and it loads the first file in the directory and then saves that file to every other filename in the directory if that makes sense. It never deletes the first file and load the next.
I did run some quick tests on this macro but did not check the resulting MI files. The problem was that I forgot to start a new drawing before each LOAD command (RESET_SYSTEM) so loading failed after the first load. I have corrected the macro in the above post so it should work correctly now.

You did not mention that you wanted to delete the original files. I added a commented line to the macro to do that, but be aware that if the conversion does not work correctly you will still lose the original files. I would recommend against uncommenting it.

mambrose
03-27-2007, 10:26 AM
Thanks John for all of your help...I have been in an out of town the past few weeks and did not have a chance to try your previous macro until today. Where might I find the updated macro?

Thanks again,
Mark

mambrose
03-27-2007, 10:30 AM
I see that you updated the original in the previous post. I works great...Thanks again, this will save me a lot of time.

Mark