MastroLube Posted April 10, 2018 Share Posted April 10, 2018 Hi there! I've wrote this lisp in order to make a little bit faster the cleaning of the output of my FEM. I don't understand why I'm not able to delete the source dxf. What's wrong? (defun C:arm (/ laylist) (_SetCLayer "BORDO") ;(command "._layer" "_OFF" "*" "_YES" "") (setq laylist (list "ARMAT_INF_DIR_X" "ARMAT_INF_DIR_Y" "ARMAT_SUP_DIR_X" "ARMAT_SUP_DIR_Y" "BORDO" )) (foreach ln laylist (if (tblsearch "LAYER" ln) (progn (command "_.LAYER" "_LOCK" ln "") (princ (strcat "\nLayer " ln " Blocked")) ) ) ) (command "_.ERASE" "_ALL" "") (foreach ln laylist (if (tblsearch "LAYER" ln) (progn (command "_.LAYER" "_UNLOCK" ln "") (princ (strcat "\nLayer " ln " Now Visible")) ) ) ) (command "_.purge" "_all" "" "_no") (command "_.erase" (ssget "_A" '((420 . 85))) "") (setq filename (strcat (getvar "dwgprefix")(getvar "dwgname"))) (command "_.save" "" "_Y") (vl-file-delete filename) (command "_.close" "") ) May I ask a suggestion? I use the dwg as xref in my drawings. I import it 4 times and change the layer visualization.. There is a way to generate 4 dwg with these layers: BORDO + ARMAT_INF_DIR_X, BORDO + ARMAT_INF_DIR_Y, BORDO + ARMAT_SUP_DIR_X, BORDO + ARMAT_SUP_DIR_Y ? Thanks for your help, Dennis Quote Link to comment Share on other sites More sharing options...
rlx Posted April 10, 2018 Share Posted April 10, 2018 you cant delete a file that is in use (like an active drawing) Quote Link to comment Share on other sites More sharing options...
MastroLube Posted April 10, 2018 Author Share Posted April 10, 2018 Hi rxl, in the code I saved the file as .DWG and this is the current not the one I'm trying to delete. Look at the code: I get the name of the file before the save, i try to delete it after the save. Quote Link to comment Share on other sites More sharing options...
rlx Posted April 10, 2018 Share Posted April 10, 2018 (edited) well to use Grrr's code and assuming it is the dxf you want to delete : (setq filename (apply '(lambda (a b c) (strcat a b ".dxf")) (fnsplitl (apply 'strcat (mapcar 'getvar '(dwgprefix dwgname)))))) else you will have to first close the drawing before you can delete it. p.s. And you may want to use saveas instead of save... gr. Rlx Edited April 10, 2018 by rlx Quote Link to comment Share on other sites More sharing options...
MastroLube Posted April 10, 2018 Author Share Posted April 10, 2018 With this code I get the same as mine, anyway the vl-file-delete doesn't delete the dxf. Maybe it's something related to permissions? Quote Link to comment Share on other sites More sharing options...
rlx Posted April 10, 2018 Share Posted April 10, 2018 With this code I get the same as mine, anyway the vl-file-delete doesn't delete the dxf. Maybe it's something related to permissions? did you try saveas first? Quote Link to comment Share on other sites More sharing options...
MastroLube Posted April 10, 2018 Author Share Posted April 10, 2018 Hello! Yes, i tried: (setq filename (strcat (getvar "dwgprefix") "arm")) ;(command "_.save" "" "_Y") (vla-SaveAs (vla-get-ActiveDocument(vlax-get-acad-object)) filename ac2004_dwg) (command "_.close" "") (vl-file-delete (strcat filename ".dxf")) Unfortunately it looks like that after _.close the lisp stops to work. :S EDIT: I really don't know.. event putting the (vl-file-delete .. or the command _.del I'm not able to delete this file.. With the saveas the dxf isn't the current anymore so i don't know what to do.. Quote Link to comment Share on other sites More sharing options...
rlx Posted April 10, 2018 Share Posted April 10, 2018 (edited) Hello!Yes, i tried: (setq filename (strcat (getvar "dwgprefix") "arm")) ;(command "_.save" "" "_Y") (vla-SaveAs (vla-get-ActiveDocument(vlax-get-acad-object)) filename ac2004_dwg) (command "_.close" "") (vl-file-delete (strcat filename ".dxf")) Unfortunately it looks like that after _.close the lisp stops to work. :S just loose the close... when you open the dxf , it becomes active. When you just use save, you make a dwg but you're still in the dxf. When you saveas the dxf to dwg , the dwg becomes active and you can delete the dxf. Edited April 11, 2018 by rlx Quote Link to comment Share on other sites More sharing options...
rlx Posted April 10, 2018 Share Posted April 10, 2018 (edited) something like this : (defun c:dxf2dwg ( / dwg old-exp) (vl-load-com) ; no nagging when dwg allready exists , don't use if you don't want to overwrite existing dwg's (setq old-exp (getvar "EXPERT"))(setvar "EXPERT" 2) (setq dwg (strcat (getvar "dwgprefix")(vl-filename-base (getvar "dwgname")))) ;(vla-SaveAs (vla-get-ActiveDocument (vlax-get-acad-object)) dwg ac2004_dwg); doesn't seem to release dxf (command ".saveas" "" dwg) ; looks like this works better (gc) ; garbage collection, a little flushing after save / write never hurt anybody (vl-file-delete (strcat dwg ".dxf")) (setvar "EXPERT" old-exp) (princ) ) Edited April 11, 2018 by rlx Quote Link to comment Share on other sites More sharing options...
Jef! Posted April 11, 2018 Share Posted April 11, 2018 just loose the close... when you open the dxf , it becomes active. When you just use save, you make a dwg but you're still in the dxf. When you saveas the dxf to dwg , the dwg becomes active and you can delete the dxf. I concur. Not only that, the lisp execution is local to a specific drawing. When you close the drawing the lisp just hangs there even if the command/commands/vlcmf close / vla-quit/exit is the last thing in the lisp.. I use to use a very simple lisp, when a drawing was opened it opened it a 2nd time in read only and closed the first one. Used 31 times no more drawing could be opened in the session a popup would appear saying something like that "a maximum of 32 drawings can be opened per session". Referred by some as a bug, maybe because I seem to be able to qnew more than 32 dwgs, but it is like using close/quit/exit leave some things in a stack somewhere (like probably local variables not getting out of scope).. My guess here is that whenever you manipulate files fast (like saveas and delete previous file, or closing and deleting a file right away), depending on the action and various other things, cad could/will end up trying to delete the file before windows has released the file's handle, making the action fail. Try adding a delay before the call to delete the file. Quote Link to comment Share on other sites More sharing options...
rlx Posted April 11, 2018 Share Posted April 11, 2018 I concur. Not only that, the lisp execution is local to a specific drawing. When you close the drawing the lisp just hangs there even if the command/commands/vlcmf close / vla-quit/exit is the last thing in the lisp.. I use to use a very simple lisp, when a drawing was opened it opened it a 2nd time in read only and closed the first one. Used 31 times no more drawing could be opened in the session a popup would appear saying something like that "a maximum of 32 drawings can be opened per session". Referred by some as a bug, maybe because I seem to be able to qnew more than 32 dwgs, but it is like using close/quit/exit leave some things in a stack somewhere (like probably local variables not getting out of scope).. My guess here is that whenever you manipulate files fast (like saveas and delete previous file, or closing and deleting a file right away), depending on the action and various other things, cad could/will end up trying to delete the file before windows has released the file's handle, making the action fail. Try adding a delay before the call to delete the file. or just use a script (if not blocked haha). I'm sure I have a button somewhere to process entire folder and convert all dxf's to dwg but use it only a few times a year. Quote Link to comment Share on other sites More sharing options...
MastroLube Posted April 16, 2018 Author Share Posted April 16, 2018 Hello guys! Thanks rlx, nwo the code delete the file correctly! Thanks Jef! for the explanation of this problem!! Can I accomplish the generation of the 4 dwg using the command UNDO 4 times? Quote Link to comment Share on other sites More sharing options...
rlx Posted April 16, 2018 Share Posted April 16, 2018 Hello guys! Thanks rlx, nwo the code delete the file correctly! Thanks Jef! for the explanation of this problem!! Can I accomplish the generation of the 4 dwg using the command UNDO 4 times? you can use the layer codes from your own example (haven't tested them or anything) but if you want 4 different drawings you need 4 different dwg names so you would have to do something like : (setq dwg-suffix 0) (foreach layer ... lispy lispy ... saveas (strcat dwgname (itoa (setq dwg-suffix (1+ dwg-suffix)))) ) . . . (delete dxf) Quote Link to comment Share on other sites More sharing options...
Jef! Posted April 16, 2018 Share Posted April 16, 2018 Thanks Jef! for the explanation of this problem!! You are welcome! (setq dwg-suffix 0) (foreach layer ...[i][b][size="4"] lispy lispy[/size] [/b][/i]... ) . . lispy lispy... hahahahah. :rofl: Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.