Autocad Lisp Current Drawing Folder

#1

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

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

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

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.


#6

Default Re: Lisp to determine directory of active open drawings


#8

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

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 3630, Core i9-9900K 5.0GHz, 128GB RAM, Samsung 970 Pro M.2, 8GB NVIDIA Quadro P4000


millertatifechand.blogspot.com

Source: https://forums.augi.com/showthread.php?126983-Lisp-to-determine-directory-of-active-open-drawings

0 Response to "Autocad Lisp Current Drawing Folder"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel