Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Lisp to determine directory of active open drawings

  1. #1
    Active Member
    Join Date
    2007-02
    Posts
    61
    Login to Give a bone
    0

    Question Lisp to determine directory of active open drawings

    I am trying to run a small routine that will determine the current directory of the active drawing and then run my routine within that directory.

    I have three files a .bat, a .scr and a .lsp.

    The files when run all together will open a drawing in the designated directory (designated within the programming), purge it, save over the exisitng file, and then move to the next file in the directory.

    I want to run a lisp in here somehow that will first determine the directory of the active file and then run the routine on that particular directory. I do not want to have specific directories indicated within the actual program. I want to apply the program to any project directory, it needs to be versitile. It also will need the capability to open files in sub-directories and write over them in those same sub-directories.

    Right now I have the program create a folder called "check" so that I can have the pootential of having drawing files saved in there as a safety precaution for more complicated routines in the future.

    The routine runs well and does what i'd like with the exception of accessing the files in the sub-directory and inserting whatever the current direcory may be.

    Here are my three bits of code, you might find them a bit clumsy.(it's my first time branching out beyond script files, and my first time sharing code! - although quite embarassingly simple)

    The .BAT file:

    md c:\testpurge\check
    FOR %%f in (c:\testpurge\*.dwg) do start/wait c:\"program files"\"AutoCAD 2010"\acad.exe "%%f" /b c:\testpurge\tpurge.scr

    The .SCR file:

    (load"c:\\testpurge\\tpurge.lsp")
    zoom all
    tpurge
    quit
    y



    The .LSP file:

    (defun c:tpurge(/ dn pa pacheckdn)
    (setq dn (getvar "dwgname"))
    (setq pa (getvar "dwgprefix"))
    (setq pacheckn (strcat pa "check\\"dn))
    (command "-purge" "a" "*" "n" "save" "" "y"pacheckdn)
    )

    Hope this made sense

    Any ideas?

  2. #2
    All AUGI, all the time
    Join Date
    2010-10
    Posts
    535
    Login to Give a bone
    0

    Default Re: Lisp to determine directory of active open drawings

    vl-mkdir to create folder so no need for BAT file
    Code:
    (vl-mkdir (setq root "C:\\testpurge\\"))
    incorporated on a lisp file


    Current name of active drawing:
    (getvar 'Dwgname)
    or
    (vla-get-fullname
    (vla-get-activedocument
    (vlax-get-acad-object)))

    Current folder of active drawing:
    (getvar 'Dwgprefix)
    or
    (vla-get-path
    (vla-get-activedocument
    (vlax-get-acad-object)))

    a better purge:
    Code:
    ;;; Credits to Peter J. ;;;
    (defun C:Purgeall ()
     (repeat 4
      (vla-purgeall (vla-get-activedocument (vlax-get-acad-object)))
     )
    )
    
    (defun C:Purgealls ()
     (command "-layer" "u" "*" "")
     (command "-wblock" (vla-get-fullname 
                          (vla-get-activedocument 
                           (vlax-get-acad-object))) "Y" "*")
    )
    This code will override the existing file (so it should say N at th end of your script)

    Now if you want to save it to the folder you just created (c:\testpurge)
    Code:
    (command "-wblock" (strcat root (vla-get-name 
                          (vla-get-activedocument 
                           (vlax-get-acad-object)))) "Y" "*")
    then run your script

  3. #3
    Active Member
    Join Date
    2007-02
    Posts
    61
    Login to Give a bone
    0

    Default Re: Lisp to determine directory of active open drawings

    The main purpose of the .bat file was allowing me to open, purge, and close every drawing in a folder without having to open them all The making of a folder ws just a little bell and whistle. If I get rid of the.bat then I lose this ability.

    What I was looking for was a .lsp that will determine the directory that houses one (only one) opened drawing andt hen run the .bat file, the lisp file , and the .scr file on every .dwg file and .dwg file in a sub - diretory in that particular directory.

    The .bat, .lsp., and .scr would reside on the server in a central location, available to all operators.

  4. #4
    All AUGI, all the time
    Join Date
    2010-10
    Posts
    535
    Login to Give a bone
    0

    Default Re: Lisp to determine directory of active open drawings

    You can still do without a BAT and script and maintan the ability to open and save

    ObjectDBX allows you to access drawings without loading them in the drawing editor. This results in a huge improvement in processing speed at the expense of not having the user interface.

    If you need help with this just holler.

  5. #5
    I could stop if I wanted to
    Join Date
    2001-07
    Posts
    319
    Login to Give a bone
    0

    Default Re: Lisp to determine directory of active open drawings

    I've download the files from Autodesk. If you could drop a few lines to show how it's done, only the main parts to open, run a routine and close the dwg that'll be great!.
    Thanks

  6. #6
    All AUGI, all the time
    Join Date
    2010-10
    Posts
    535
    Login to Give a bone
    0

    Default Re: Lisp to determine directory of active open drawings

    Check this link

    http://www.augi.com/forums/showthrea...ight=objectDBX

    Thats how i get started
    Have fun

  7. #7
    I could stop if I wanted to
    Join Date
    2001-07
    Posts
    319
    Login to Give a bone
    0

    Default Re: Lisp to determine directory of active open drawings

    Thanks,
    It seems that I still have to start Autocad to run the routine. So I suppose I have to start with a blank dwg and from there I can work with dwgs without opening them in the graphic mode?
    (it's not directly linked with the original question of this topic ... sorry for that)

  8. #8
    All AUGI, all the time
    Join Date
    2010-10
    Posts
    535
    Login to Give a bone
    0

    Default Re: Lisp to determine directory of active open drawings

    thats correct,
    but hat good about it is you dont have to open the drawing to obtain\modify data via documents/dictinaries collection. unlike script, the file needs to be active for you to access data. with Object DBX you don't need to. there are limitations though. ObjectDBX cannot directly work on drawings that are read-only or templates. You cannot perform selection set operations(interactive that is) on drawings through DBX. Only table operations can be used.

    just think
    "hundreds of drawings in seconds rather than hours."

  9. #9
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: Lisp to determine directory of active open drawings

    I too would use ObjectDBX (ODBX) for this operation.

    I began using it (ODBX), with a project of +/-450 drawings... my scripts took +1 hour, ODBX only took +/-45 seconds.

    If you need help, let us know.
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  10. #10
    I could stop if I wanted to
    Join Date
    2001-07
    Posts
    319
    Login to Give a bone
    0

    Default Re: Lisp to determine directory of active open drawings

    Thanks guys,
    Is it possible to plot a dwg with ODBX?

Page 1 of 2 12 LastLast

Similar Threads

  1. Open all drawings in a directory, save, close.
    By JSimons in forum AutoLISP
    Replies: 18
    Last Post: 2020-05-08, 10:08 PM
  2. AutoCAD LT and Active Directory
    By jonathan.landeros in forum Networks
    Replies: 3
    Last Post: 2015-06-29, 07:49 AM
  3. MVIEW determine which camera is active
    By bruce.jones542083 in forum AutoCAD 3D (2006 or below)
    Replies: 5
    Last Post: 2009-04-03, 02:34 PM
  4. EXCLUDE, GROUP and Active Directory
    By ShawnF in forum Networks
    Replies: 2
    Last Post: 2008-12-11, 01:44 PM
  5. Determine If Multiple Drawings Are Open
    By CADdancer in forum AutoLISP
    Replies: 10
    Last Post: 2007-11-29, 07:39 PM

Posting Permissions

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