+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 14
  1. #1
    Senior Member
    Using
    AutoCAD 2015
    Join Date
    Jan 2015
    Posts
    131

    Default vl-file-delete returns always nil + suggestion

    Registered forum members do not see this ad.

    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?
    Code:
    (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

  2. #2
    Super Member rlx's Avatar
    Computer Details
    rlx's Computer Details
    Operating System:
    W10
    Computer:
    i74ghz/ssd500/2tbhdd
    Discipline
    Electrical
    rlx's Discipline Details
    Occupation
    electrical designer dragon
    Discipline
    Electrical
    Details
    I dont excel in anything but I rearly give up
    Using
    AutoCAD 2016
    Join Date
    Nov 2014
    Location
    Bergen op Zoom , Netherlands
    Posts
    943

    Default

    you cant delete a file that is in use (like an active drawing)

  3. #3
    Senior Member
    Using
    AutoCAD 2015
    Join Date
    Jan 2015
    Posts
    131

    Default

    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.

  4. #4
    Super Member rlx's Avatar
    Computer Details
    rlx's Computer Details
    Operating System:
    W10
    Computer:
    i74ghz/ssd500/2tbhdd
    Discipline
    Electrical
    rlx's Discipline Details
    Occupation
    electrical designer dragon
    Discipline
    Electrical
    Details
    I dont excel in anything but I rearly give up
    Using
    AutoCAD 2016
    Join Date
    Nov 2014
    Location
    Bergen op Zoom , Netherlands
    Posts
    943

    Default

    well to use Grrr's code and assuming it is the dxf you want to delete :


    Code:
     (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
    Last edited by rlx; 10th Apr 2018 at 12:15 pm.

  5. #5
    Senior Member
    Using
    AutoCAD 2015
    Join Date
    Jan 2015
    Posts
    131

    Default

    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?

  6. #6
    Super Member rlx's Avatar
    Computer Details
    rlx's Computer Details
    Operating System:
    W10
    Computer:
    i74ghz/ssd500/2tbhdd
    Discipline
    Electrical
    rlx's Discipline Details
    Occupation
    electrical designer dragon
    Discipline
    Electrical
    Details
    I dont excel in anything but I rearly give up
    Using
    AutoCAD 2016
    Join Date
    Nov 2014
    Location
    Bergen op Zoom , Netherlands
    Posts
    943

    Default

    Quote Originally Posted by MastroLube View Post
    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?

  7. #7
    Senior Member
    Using
    AutoCAD 2015
    Join Date
    Jan 2015
    Posts
    131

    Default

    Hello!
    Yes, i tried:
    Code:
      (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..

  8. #8
    Super Member rlx's Avatar
    Computer Details
    rlx's Computer Details
    Operating System:
    W10
    Computer:
    i74ghz/ssd500/2tbhdd
    Discipline
    Electrical
    rlx's Discipline Details
    Occupation
    electrical designer dragon
    Discipline
    Electrical
    Details
    I dont excel in anything but I rearly give up
    Using
    AutoCAD 2016
    Join Date
    Nov 2014
    Location
    Bergen op Zoom , Netherlands
    Posts
    943

    Default

    Quote Originally Posted by MastroLube View Post
    Hello!
    Yes, i tried:
    Code:
      (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.
    Last edited by rlx; 11th Apr 2018 at 06:21 am.

  9. #9
    Super Member rlx's Avatar
    Computer Details
    rlx's Computer Details
    Operating System:
    W10
    Computer:
    i74ghz/ssd500/2tbhdd
    Discipline
    Electrical
    rlx's Discipline Details
    Occupation
    electrical designer dragon
    Discipline
    Electrical
    Details
    I dont excel in anything but I rearly give up
    Using
    AutoCAD 2016
    Join Date
    Nov 2014
    Location
    Bergen op Zoom , Netherlands
    Posts
    943

    Default

    something like this :

    Code:
    (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)
    )
    Last edited by rlx; 11th Apr 2018 at 06:29 am.

  10. #10
    Senior Member Jef!'s Avatar
    Using
    AutoCAD 2008
    Join Date
    Sep 2010
    Posts
    274

    Default

    Registered forum members do not see this ad.

    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.
    Different goal also quite often means different path...

Similar Threads

  1. Delete layers of a linked DWG file
    By halam in forum Revit Structure
    Replies: 19
    Last Post: 22nd Jan 2016, 04:11 pm
  2. how to delete useless .dwg file when using .dwt
    By dunno790 in forum AutoCAD Beginners' Area
    Replies: 10
    Last Post: 11th Nov 2015, 08:56 pm
  3. Assembly File Delete.
    By Jake8090 in forum Autodesk Inventor
    Replies: 2
    Last Post: 4th Jun 2014, 09:09 pm
  4. Delete a script file thru lisp after running
    By svorgodne in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 4th Jun 2013, 12:07 am
  5. *.AC$ file - okay to delete huge files?
    By tzframpton in forum CAD Management
    Replies: 15
    Last Post: 18th May 2011, 01:41 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts