Visual LISP, AutoLISP and General Customization
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Batch_DGN2 DWG
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi,
I want to convert my DGN files to DWG files.
So I write this code in LISP:
(defun C:Batch_DGN2DWG (/path dgnfile SDI_Mode)
(setq
path "C:\\DGN\\" ;;Default path for DGN files location.
DGNIMPORTMODE 0 ;;Imports the DGN file in a new drawing file.
SDI_Mode SDI ;;Save Current SDI MODE
SDI 1 ;;SET Single Drawing Mode for AutoCAD.
);;setq
(foreach dgnfile (vl-directory-files path "*.DGN" 1)
(progn
(command "-dgnimport" (strcat path dgnfile) "" "" "" "y" (strcat path dgnfile ".DWG"))
(delay 100)
);;progn
);;foreach
(setq SDI SDI_Mode) ;;restrore SDI Mode to previous value.
)but I can't finish it! does anybody can help me please?
I attached some DGN files for test purpose.
Thanks,
Solved! Go to Solution.
Re: Batch_DGN2 DWG
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
34 views and no comment?!
WHY!!
nobody can't help me?
Re: Batch_DGN2 DWG
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi,
There is no description of what happens (not) on your system. Also there is no AutoCAD-version given (and if you are using a vertical product like Mech or P3D or ...), that is important as DGN-import may vary then how it works.
- alfred -
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Re: Batch_DGN2 DWG
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
aqdam1978 wrote:Hi,
I want to convert my DGN files to DWG files.
So I write this code in LISP:
(defun C:Batch_DGN2DWG (/path dgnfile SDI_Mode)
I have never used any of .dgn files, so don't know a lot about it,
but you suppose to put space between slash "/" and path in the list of local variables...
(/ path dgnfile SDI_Mode)
Re: Batch_DGN2 DWG
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
aqdam1978,
I think you can not set a system variable with "setq" you need to use "setvar" or "command", so I think you should change the start of your code, the part where you make the collection of the current variables and setting the new values, the end part where restores the original variables.
perhaps something like
(defun c:Batch_DGN2DWG (/ path old_dgnIPM dgnfile SDI_Mode)
(setq path "C:\\DGN\\" ;;Default path for DGN files location.
old_dgnIPM (getvar "DGNIMPORTMODE");; save the current DGNIMPORTMODE
SDI_Mode (getvar "SDI");;Save Current SDI MODE
)
(setvar "DGNIMPORTMODE" 0);;Imports the DGN file in a new drawing file.
(setvar "SDI" 1);;SET Single Drawing Mode for AutoCAD
(foreach ...
...)
(setvar "DGNIMPORTMODE" old_dgnIPM) ;;restrore DGNIMPORTMODE to previous value.
(setvar "SDI" SDI_Mode) ;;restrore SDI Mode to previous value.
)
as to the main part of your code, I can not be much help, unfortunately the AutoCAD I have at home is a version that I can not test some variables, is old like me, but I think when you sets SDI to 1 the code should stop at the first dng to be imported, it's just a hunch, I have no way to test, and I've never worked with DGN's.
EDITED
Perhaps using a script would be easier...
Henrique
Re: Batch_DGN2 DWG
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi alfred.neswadba,
Thank you for your comment,
I updated my code due to "hmsilva" comments, so the final code is:
(defun C:Batch_DGN2DWG (/ path dgnfile DGN_Mode SDI_Mode)
(setq
path "C:\\DGN\\" ;;Default path for DGN files location.
DGN_Mode (getvar "DGNIMPORTMODE");;Imports the DGN file in a new drawing file.
SDI_Mode (getvar "SDI") ;;Save Current SDI MODE
);;setq
(setvar "Filedia" 0) ;;No visual dialogue box
(setvar "DGNIMPORTMODE" 0) ;;Imports the DGN file in a new drawing file.
(setvar "SDI" 0) ;;SET Multi Drawing Mode for AutoCAD
(foreach dgnfile (vl-directory-files path "*.DGN" 1)
(progn
(command "-dgnimport" (strcat path dgnfile) "" "" "")
(command "save" (strcat path dgnfile ".DWG") "y")
;;(command "close" "y")
);;progn
);;foreach
(setvar "DGNIMPORTMODE" DGN_Mode) ;;restrore DGNIMPORTMODE to previous value.
(setvar "SDI" SDI_Mode) ;;restrore SDI Mode to previous value.
(setvar "Filedia" 1)
)this code works but there is a problem:
when autocad opens a new drawing to import next dgn file, LISP stopping, because this LISP program does not loaded in new drawing, so I should click on the first autocad icon on the taskbar to switch and view the first autocad that has loaded lisp program, and then Lisp program continues and imported next dgn file.
so for each dgn file, I should click on the first autocad icon on the taskbar to complete all dgn files converted.
and the 2nd problem is: there are so many opened autocad icons on the taskbar and I should close them!
I think there is no solution via LISP programming, and I should prepare a script file and load it in autocad
I attached some DGN files in my first post, if you like you can test it!
sorry for my poor english.
my system is: Autocad 2013 32bit on Windows 8 32bit
THANKS,
Re: Batch_DGN2 DWG
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
aqdam1978 wrote:
...
and the 2nd problem is: there are so many opened autocad icons on the taskbar and I should close them!
...
try replacing
(command "close" "y")
by
(command "Quit")
Henrique
Re: Batch_DGN2 DWG
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
hi hmsilva,
I decided to use scrip for implementing my code as of your first suggestion to me!
so, I prepare this code:
;; DGN to DWG Batch conversion ;; (defun C:Batch_DGN2DWG (/ path dgnfile DGN_Mode SDI_Mode des tmp) (vl-load-com) (setq path "C:\\DGN\\" ;;Default path for DGN files location. DGN_Mode (getvar "DGNIMPORTMODE");;Save Current DGNIMPORTMODE value SDI_Mode (getvar "SDI") ;;Save Current SDI value );;setq (setq des (open (strcat path "t.scr") "w" )) (write-line "filedia" des) (write-line "0" des) (write-line "DGNIMPORTMODE" des) (write-line "0" des) (write-line "SDI" des) (write-line "1" des) (foreach dgnfile (vl-directory-files path "*.DGN" 1) (progn (write-line "-dgnimport" des) (write-line (strcat path dgnfile) des) (write-line "" des) (write-line "" des) (write-line "" des) (write-line "qsave" des) (setq tmp (strcat path dgnfile ".DWG")) (write-line tmp des) (if (findfile tmp) (write-line "y" des)) ;;overwrite? Y (write-line "delay" des) (write-line "100" des) );;progn );;foreach (write-line "filedia" des) (write-line "1" des) (write-line "DGNIMPORTMODE" des);;restore DGNIMPORTMODE value (write-line (rtos DGN_Mode 2 0) des) (write-line "SDI" des) ;;restore SDI value (write-line (rtos SDI_Mode 2 0) des) (close des) ;;closed script files (command "script" (strcat path "t.scr")) ;;(vl-file-delete (strcat "t.scr")) )
it works good, excellent!,
BUT!, when prosess is done, I can't close and exit AutoCAD and I should "End process" acad.exe!
So, can you guess what is the problem?
THANKS
Abbas
Re: Batch_DGN2 DWG
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Abbas,
you have to add after
(write-line "100" des) (write-line "quit" des) );;progn
Henrique
Re: Batch_DGN2 DWG
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Abbas wrote:
...
BUT!, when prosess is done, I can't close and exit AutoCAD and I should "End process" acad.exe!
...
Just a different approach, do you really need to set SDI to 1?
If not, I think it worked better if just add a "close" in the end of the "foreach", and a "quit" after you restore the DGNIMPORTMODE value.
Henrique


