Select folder containing dxf and save as dwg

Select folder containing dxf and save as dwg

blandb
Mentor Mentor
2,283 Views
20 Replies
Message 1 of 21

Select folder containing dxf and save as dwg

blandb
Mentor
Mentor

I have a company that has folders of dxf files, and they want me to open each dxf and save as dwg. I have the save options set to 2000 format, so I just open all the dxf's in the folder and then do a Zoom Extents > Save > Close....rinse and repeat for the remainder of the drawings open.

 

Is there a lisp routine that can be done to accomplish this? Select a folder, save the dxf's as the same name just in a dwg format into the same folder the dxf files are?

 

Thanks in advance

Autodesk Certified Professional
0 Likes
2,284 Views
20 Replies
Replies (20)
Message 21 of 21

ec-cad
Collaborator
Collaborator

You probably haven't had time to try out all the possible solutions to DXFOUT, via lisp, so here's a

working model.

Cheers

;; batch_dxf.lsp
 (vl-load-com)
;;
;; Old Version of 'BrowseForFolder' by: Tony Tanzillo (AutoLisp Forum)
;;
(defun BrowseForFolder ( Message / sh folder parentfolder folderobject result) 
 (vl-load-com) 
  (setq sh 
   (vla-getInterfaceObject 
     (vlax-get-acad-object) 
       "Shell.Application" 
     ) 
   ) 
   (setq folder 
      (vlax-invoke-method 
          sh 
          'BrowseForFolder 
          0 
          Message 
          0 
       ) 
   ) 
   (vlax-release-object sh) 

    (if folder 
      (progn 
         (setq parentfolder 
           (vlax-get-property folder 'ParentFolder) 
         ) 
        (setq FolderObject 
           (vlax-invoke-method 
              ParentFolder 
               'ParseName 
              (vlax-get-property Folder 'Title) 
           ) 
        ) 
       (setq result 
          (vlax-get-property FolderObject 'Path) 
       ) 
       (mapcar 'vlax-release-object 
         (list folder parentfolder folderobject) 
       ) 
     (if (/= (substr result (strlen result)) "\\")
       (setq result (strcat result "\\"))
       result
     )
   ) 
 ) 
); defun

;;
;; Local Functions to process each DXF to Save as a DWG
;;
 (defun save_the_drawing ( dwg )
  (if (not (findfile dwg))
  (command "_saveas" "2013" dwg); NOTE: you may need to change this line for your version
  ); if
 ); end function save_the_drawing

 (defun do_dwgs ( DXFList )
  (setq L 0)
   (command "_qsave"); save existing drawing opened..
   (repeat (length DXFList)
    (setq dx_fil (nth L DXFList)); get a file at a time
    (setq dwg_fil (substr dx_fil 1 (- (strlen dx_fil) 4))) ; remove the ".dxf" for drawing naming
    (setq dx_fil (strcat DXF_Path_Name dx_fil))
    (command "_erase" "all" "")
    (command "_purge" "ALL" "" "N")
    (command "_DXFIN" dx_fil); load the DXF
    (command "_zoom" "E"); zoom
    (command "_purge" "ALL" "" "N")
    (setq dwg_name (strcat DXF_Path_Name dwg_fil))
    (save_the_drawing dwg_name)
    (setq L (+ L 1))
   ); repeat
   (command "_qsave")
   (command)
   (princ)
 ); end function do_dwgs

 (defun get_file_lst ()
  (if (setq DXF_Path_Name (BrowseForFolder "Select Folder of DXF Files."))
   (progn
    (setq fil_lst (vl-directory-files DXF_Path_Name "*.dxf" 1))
     (if (/= fil_lst nil)
      (setq fil_lst (acad_strlsort fil_lst))
      (setq fil_lst (list ""))
     ); end if
   ); progn
  ); if
  (princ)
 ); end function get_file_list
;;
;; Begin
;;
 (setq path (getvar "dwgprefix"))
 (get_file_lst)
 (if fil_lst
   (do_dwgs fil_lst)
 ); if
 (prompt "\nAll DXF Converted to DWG's")
 (princ)

 

ECCAD

 

0 Likes