Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Script to open dwgs

9 REPLIES 9
Reply
Message 1 of 10
Anonymous
208 Views, 9 Replies

Script to open dwgs

O.K.

 

I am totaly confused!

 

All I want to do is cycle through all of the dwgs
(over 9000) on a disk check to see if it is read only or not.  If it
is not read only open the dwg and purge everything.

I have a text file that contains each dwg name on a
single line.

 

i.e.

 


size=2>J:\dwg1.dwg
J:\Sample\EXAMPLE1.dwg
J:\Sample\EXAMPLE2.dwg
J:\Sample\EXAMPLE3.dwg

etc.

 

First I thought a script and the acad.lsp
file would do the trick

 

i.e.

open "J:\dwg1.dwg"
open
"J:\Sample\EXAMPLE1.dwg"
open "J:\Sample\EXAMPLE2.dwg"
open
"J:\Sample\EXAMPLE3.dwg"

 

Acad.lsp

(command "-purge" "all" "" "n")

(command ".qsave")

 

But the script doesn't check for read only and
every time the script file hits a read only dwg it stops.

 

Then I thought I would use the acad.lsp
only

 

(defun isReadOnly (filnam / fil);check for read
only
  (if (setq fil (open filnam "a"))
    (close
fil)
    t
  )
)

 

(setvar "sdi" 1);set to single document
mode
 
  (setq DwgFile (open "H:/1100-Users/CVD/drawing.txt"
"r"))
 
  (while (setq lin (read-line
DwgFile))
    (if (= (isReadOnly lin)
t)
      (setq lin (read-line
DwgFile)
      )
   
)
    (command ".open" lin)

       (command
"-purge" "all" "" "n")
       (command "-purge"
"all" "" "n")
       (command "-purge" "all" ""
"n")
       (command ".qsave")

)

  (close DwgFile)
)

 

But the variables keep reseting so it fails at (=
(isReadOnly lin) t).

 

If someone could please give me some tips I sure
would appreciate it.

 

Thanks,

Charles
9 REPLIES 9
Message 2 of 10
Anonymous
in reply to: Anonymous

"Charles" wrote in message
news:9C35B144450E71DCF57D6A9242ADD17E@in.WebX.maYIadrTaRb...
> (while (setq lin (read-line DwgFile))
> (if (= (isReadOnly lin) t)
> (setq lin (read-line DwgFile)
> )
> )
> (command ".open" lin)
> (command "-purge" "all" "" "n")
> (command "-purge" "all" "" "n")
> (command "-purge" "all" "" "n")
> (command ".qsave")
> )
> (close DwgFile)

Hi,

Try this. I put your (command ...) stuff inside the while; alos, there's no
need to repeat (setq lin (read-line DwgFile)) in the while expression block
when it's in the while conditional expression.

(while (setq lin (read-line DwgFile))
(if (not (isReadOnly lin))
(command ".open" lin)
(command "-purge" "all" "" "n")
(command "-purge" "all" "" "n")
(command "-purge" "all" "" "n")
(command ".qsave")))
(close DwgFile)
Message 3 of 10
Anonymous
in reply to: Anonymous

"Adam Wuellner" wrote in message
news:39BEE70BECE5DD2F29749850A7DA546E@in.WebX.maYIadrTaRb...
> Try this. I put your (command ...) stuff inside the while; alos, there's
no
> need to repeat (setq lin (read-line DwgFile)) in the while expression
block
> when it's in the while conditional expression.
>
> (while (setq lin (read-line DwgFile))
> (if (not (isReadOnly lin))
> (command ".open" lin)
> (command "-purge" "all" "" "n")
> (command "-purge" "all" "" "n")
> (command "-purge" "all" "" "n")
> (command ".qsave")))
> (close DwgFile)

Sorry, you need a progn in there, too.

(while (setq lin (read-line DwgFile))
(if (not (isReadOnly lin))
(progn
(command ".open" lin)
(command "-purge" "all" "" "n")
(command "-purge" "all" "" "n")
(command "-purge" "all" "" "n")
(command ".qsave"))))
(close DwgFile)

And, to clarify a point, if you have
(while (setq x (read-line file))
(do stuff)
(setq x (read-line file)))
you'll wind up skipping every other line in the file. This is because the
(setq x ...) the gets evaluated last in the while block is immediately
redefined by the (setq x ...) in the conditional, which is evaluated in each
loop.

HTH
Adam
Message 4 of 10
Anonymous
in reply to: Anonymous

Of course, this doesn't work. Once the drawing is opened, it's in a seperate namespace. Sorry for
the confusion.

How about a lisp that took your text file, read in the names and tested them, and wrote out any that
weren't readonly to a script file and fired it off immediately? You'd still be susceptible to folks
opening drawings between the time the script was written and the time the script processed a given
file.

"Adam Wuellner" wrote in message
news:2EC231E866C744E8CB68055F936EFF5A@in.WebX.maYIadrTaRb...
>
> "Adam Wuellner" wrote in message
> news:39BEE70BECE5DD2F29749850A7DA546E@in.WebX.maYIadrTaRb...
> > Try this. I put your (command ...) stuff inside the while; alos, there's
> no
> > need to repeat (setq lin (read-line DwgFile)) in the while expression
> block
> > when it's in the while conditional expression.
> >
> > (while (setq lin (read-line DwgFile))
> > (if (not (isReadOnly lin))
> > (command ".open" lin)
> > (command "-purge" "all" "" "n")
> > (command "-purge" "all" "" "n")
> > (command "-purge" "all" "" "n")
> > (command ".qsave")))
> > (close DwgFile)
>
> Sorry, you need a progn in there, too.
>
> (while (setq lin (read-line DwgFile))
> (if (not (isReadOnly lin))
> (progn
> (command ".open" lin)
> (command "-purge" "all" "" "n")
> (command "-purge" "all" "" "n")
> (command "-purge" "all" "" "n")
> (command ".qsave"))))
> (close DwgFile)
>
> And, to clarify a point, if you have
> (while (setq x (read-line file))
> (do stuff)
> (setq x (read-line file)))
> you'll wind up skipping every other line in the file. This is because the
> (setq x ...) the gets evaluated last in the while block is immediately
> redefined by the (setq x ...) in the conditional, which is evaluated in each
> loop.
>
> HTH
> Adam
>
>
>
Message 5 of 10
patrick
in reply to: Anonymous

Hello Charles,

If the reason the drawings are read only is because someone is using the file then I suggest you run your purge routine at night. For 9000 drawings I would suggest the weekend.

With our batch software there is a timer which you can set.
So pick the drawings, assign the routine, set the timer and go home.

If the files are read only without somebody using it then in Windows explorer select the files and reset the read only property.

Patrick
http://www.multi-batch.com
Message 6 of 10
SMMASON
in reply to: Anonymous

Try using msdos prompt to compose a list of read only files. Go to the root directory and use DIR *.DWG /S /B /A R > READONLY.SCR. The list will only be dwgs that are read only and will contain the path to the file. Edit the .scr using notepad or wordpad and enter the purge commands from there.
Message 7 of 10
Anonymous
in reply to: Anonymous

 

 

Charles

 

this is what i have been doing...

open the drawings regardless if they are RO...then
check

 

  (setq cdoc (vla-get-ActiveDocument
(vlax-get-acad-object)))   ;; current document name
  (if (=
(vla-get-ReadOnly cdoc) ':vlax-false)(vla-save cdoc) )    
;; save if it can be saved

 

then quit the drawing...

you can also write a txt file indicating which
drawings were

updated or can use windows explorer and check for
time

modified to see if drawing was
updated.

 

mark

 

 

 

 


style="BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">

O.K.

 

I am totaly confused!

 

All I want to do is cycle through all of the dwgs
(over 9000) on a disk check to see if it is read only or not.  If it
is not read only open the dwg and purge everything.

I have a text file that contains each dwg name on
a single line.

 

i.e.

 


size=2>J:\dwg1.dwg
J:\Sample\EXAMPLE1.dwg
J:\Sample\EXAMPLE2.dwg
J:\Sample\EXAMPLE3.dwg

etc.

 

First I thought a script and the acad.lsp
file would do the trick

 

i.e.

open "J:\dwg1.dwg"
open
"J:\Sample\EXAMPLE1.dwg"
open "J:\Sample\EXAMPLE2.dwg"
open
"J:\Sample\EXAMPLE3.dwg"

 

Acad.lsp

(command "-purge" "all" "" "n")

(command ".qsave")

 

But the script doesn't check for read only and
every time the script file hits a read only dwg it stops.

 

Then I thought I would use the acad.lsp
only

 

(defun isReadOnly (filnam / fil);check for read
only
  (if (setq fil (open filnam "a"))
    (close
fil)
    t
  )
)

 

(setvar "sdi" 1);set to single document
mode
 
  (setq DwgFile (open "H:/1100-Users/CVD/drawing.txt"
"r"))
 
  (while (setq lin (read-line
DwgFile))
    (if (= (isReadOnly lin)
t)
      (setq lin (read-line
DwgFile)
      )
   
)
    (command ".open" lin)

       (command
"-purge" "all" "" "n")
       (command
"-purge" "all" "" "n")
       (command
"-purge" "all" "" "n")
       (command
".qsave")

)

  (close DwgFile)
)

 

But the variables keep reseting so it fails at (=
(isReadOnly lin) t).

 

If someone could please give me some tips I sure
would appreciate it.

 

Thanks,

Charles
Message 8 of 10
Anonymous
in reply to: Anonymous

Charles,

A possible solution:

Create an ACADDOC.LSP
Put the following line in it:
(defun C:YES () (command "GRAPHSCR") (princ))

Create the script with the following lines:
OPEN "MyDrawing.dwg" YES (if (= (getvar "WRITESTAT") 1) (progn (command "MyCommands") (command "QSAVE"))) CLOSE

The trick is the command YES.
If the drawing is ReadOnly then the Yes means: "Yes, I want to open this drawing in ReadOnly mode"
If the drawing is not ReadOnly then the Yes means: "Go to the graphic screen" and actually doen't do anything

The if checks if the drawings is saveable (using WRITESTAT) and performs some commands AND also calls the QSAVE
Then the drawing is closed.

Alex
Message 9 of 10
Anonymous
in reply to: Anonymous

Well thank you to everyone for your
suggestions.  I finally figured it out! 🙂

 

Acad.lsp

 

(defun isReadOnly (filnam / fil)
  (if
(setq fil (open filnam "a"))
    (close
fil)
    t
  )
)

 

(defun purgeall
()
      (command "-purge" "all" ""
"n")
      (command "-purge" "all" ""
"n")
      (command "-purge" "all" ""
"n")
      (command ".qsave")
 
)

 

(defun deleteBak ();deletes .bak file
 
(setq acaddoc (vla-get-activedocument (vlax-get-acad-object)))
  (setq
DwgName (vlax-get-property acaddoc 'fullname))
  (setq DwgBak
(vl-string-subst "bak" "dwg" DwgName))
  (vl-file-delete
DwgBak)
  (vlax-release-object acaddoc)
 
(setq acaddoc nil
 DwgName nil
 DwgBak
nil
  )
)

 

(defun-q mySTARTUP ()
 
(purgeall)
  (deleteBak)
  )

 

(setq S::STARTUP (append S::STARTUP
mySTARTUP))

 

Purgeall.scr

 

(if (not (isReadOnly  "J:\\dwg.dwg"))(command
"open" "J:\\dwg.dwg"))
(if (not (isReadOnly  "J:\\dwg1.dwg"))(command
"open" "J:\\dwg1.dwg"))

(if (not (isReadOnly  "J:\\dwg2.dwg"))(command
"open" "J:\\dwg2.dwg"))

etc.

 

Charles
Message 10 of 10
chairpak
in reply to: Anonymous

Alex,

That was the trick for me.


Thank you very much.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost