Author Topic: BatchDwg to Plot  (Read 8113 times)

0 Members and 1 Guest are viewing this topic.

GDF

  • Water Moccasin
  • Posts: 2081
BatchDwg to Plot
« on: March 14, 2006, 08:48:56 AM »
I have modified the following routine "BatchDwg.lsp" to do by batch plotting and everything works fine. The only thing I would like to modify is to delete one drawing from the batch list: "2436TB.dwg", and I am stumped. Anyone have any ideas? I want to delete this
one drawing from the script.

Gary
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

kpblc

  • Bull Frog
  • Posts: 396
Re: BatchDwg to Plot
« Reply #1 on: March 14, 2006, 09:04:12 AM »
Try to use this:
Code: [Select]
;|
It's your function, but only 1 parameter added.
Ignores file with full path and name
|;
(defun arch:batchplot (file-list-exclude)
  ;; portions by Tim Willey
  (if (setq dirpath (directory-dia "* Select folder of Drawings to process *"))
    (progn
      (setq dwglist (vl-directory-files dirpath "*.dwg" 1))
      (setq scrfile (strcat dirpath "MyScript.scr"))
      (setq ofil (open scrfile "W"))
      (write-line "SDI 1" ofil)
      (write-line (strcat "(setvar " (chr 34) "FILEDIA" (chr 34) " 0)") ofil)
      (foreach dwg dwglist

(setq fullpath (strcat dirpath dwg))
(if (not (member fullpath file-list-exclude))
  (progn
    (write-line (strcat "_.open " (chr 34) fullpath (chr 34)) ofil)
    (write-line
      (strcat "(load " (chr 34) my_lisp_file (chr 34) ")")
      ofil
      ) ;_ end of write-line
    (write-line ".qsave" ofil)
    (write-line "_.close" ofil)
    ) ;_ end of progn
  ) ;_ end of if
) ;_ end of foreach
      (write-line (strcat "(setvar " (chr 34) "FILEDIA" (chr 34) " 1)") ofil)
      (write-line "SDI 0" ofil)
      (write-line "\(alert \"Done!!\"\)" ofil)
      (close ofil)
      (command "_.script" scrfile)
      ) ;_ end of progn
    ) ;_ end of if
  (princ)
  ) ;_ end of defun
sample of call:
(arch:batchplot '("c:\\files\\I Don't Want to plot this file.dwg"))
Sorry for my English.

GDF

  • Water Moccasin
  • Posts: 2081
Re: BatchDwg to Plot
« Reply #2 on: March 14, 2006, 09:22:27 AM »
Try to use this:
Code: [Select]
;|
It's your function, but only 1 parameter added.
Ignores file with full path and name
|;
(defun arch:batchplot (file-list-exclude)
  ;; portions by Tim Willey
  (if (setq dirpath (directory-dia "* Select folder of Drawings to process *"))
    (progn
      (setq dwglist (vl-directory-files dirpath "*.dwg" 1))
      (setq scrfile (strcat dirpath "MyScript.scr"))
      (setq ofil (open scrfile "W"))
      (write-line "SDI 1" ofil)
      (write-line (strcat "(setvar " (chr 34) "FILEDIA" (chr 34) " 0)") ofil)
      (foreach dwg dwglist

(setq fullpath (strcat dirpath dwg))
(if (not (member fullpath file-list-exclude))
  (progn
    (write-line (strcat "_.open " (chr 34) fullpath (chr 34)) ofil)
    (write-line
      (strcat "(load " (chr 34) my_lisp_file (chr 34) ")")
      ofil
      ) ;_ end of write-line
    (write-line ".qsave" ofil)
    (write-line "_.close" ofil)
    ) ;_ end of progn
  ) ;_ end of if
) ;_ end of foreach
      (write-line (strcat "(setvar " (chr 34) "FILEDIA" (chr 34) " 1)") ofil)
      (write-line "SDI 0" ofil)
      (write-line "\(alert \"Done!!\"\)" ofil)
      (close ofil)
      (command "_.script" scrfile)
      ) ;_ end of progn
    ) ;_ end of if
  (princ)
  ) ;_ end of defun
sample of call:
(arch:batchplot '("c:\\files\\I Don't Want to plot this file.dwg"))


Thanks for the help, but you lost me. I ran part of my original routine to get the list of drawings below. It is the following
drawing in the list {always the first item} "2436TB.dwg" that I don't want to plot.

 Here is where you lost me: (arch:batchplot '("c:\\files\\I Don't Want to plot this file.dwg"))

Code: [Select]
Command: (LOAD "E:/Arch_WorkOn/newfiles/ARCH_BatchPlot.lsp")
Command: (setq DirPath (Directory-dia "* Select folder of Drawings to process
*"))
"F:\\Jobs\\2005\\050207\\ACAD\\"
Command: (setq DwgList (vl-directory-files DirPath "*.dwg" 1))
("2436TB.dwg" "A0-00.dwg" "A0-01.dwg" "A1-01.dwg" "A1-02a.dwg" "A1-02b.dwg"
"A1-02c.dwg" "A1-03.dwg" "A1-04.dwg" "A1-05.dwg" "A2-00a.dwg" "A2-00b.dwg"
"A2-00c.dwg" "A2-00d.dwg" "A2-00e.dwg" "A2-01a.dwg" "A2-01b.dwg" "A2-01c.dwg"
"A2-02a.dwg" "A2-02b.dwg" "A2-02c.dwg" "A2-03a.dwg" "A2-03b.dwg" "A2-03c.dwg"
"A2-03d.dwg" "A2-03e.dwg" "A3-00.dwg" "A3-01.dwg" "A3-02a.dwg" "A3-02b.dwg"
"A3-02c.dwg" "A3-03a.dwg" "A3-03b.dwg" "A3-04.dwg" "A3-05.dwg" "A3-06a.dwg"
"A3-06b.dwg" "A3-07.dwg" "A3-08.dwg" "A4-01.dwg" "A4-02.dwg" "A4-03.dwg"
"A4-04.dwg" "A5-01.dwg" "A5-02.dwg" "A5-03.dwg" "A5-04.dwg" "A5-05.dwg"
"A5-06.dwg" "A6-01.dwg" "A6-02.dwg" "A6-03.dwg" "A6-04.dwg" "A6-05.dwg"
"A7-01.dwg" "A7-02.dwg" "A7-03.dwg" "A7-04.dwg" "A7-05.dwg" "A7-06.dwg"
"A7-07.dwg" "A7-08.dwg" "A8-00.dwg" "A8-01a.dwg" "A8-01b.dwg" "A8-01c.dwg"
"A8-01d.dwg" "A8-01e.dwg" "A8-02a.dwg" "A8-02b.dwg" "A8-02c.dwg" "A8-03.dwg"
"A8-04.dwg" "A8-05.dwg" "A8-06.dwg" "A8-07.dwg" "A8-08.dwg" "A9-01.dwg"
"A9-02.dwg")

Thanks for your help.

Gary

Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: BatchDwg to Plot
« Reply #3 on: March 14, 2006, 09:39:52 AM »
Another way to skin that cat.

Code: [Select]
(defun arch:batchplot (file-list-exclude)
  ;; portions by Tim Willey
  (if (setq dirpath (directory-dia "* Select folder of Drawings to process *"))
    (progn
      (setq dwglist (vl-remove file-list-exclude (vl-directory-files dirpath "*.dwg" 1)))
      (setq scrfile (strcat dirpath "MyScript.scr"))
      (setq ofil (open scrfile "W"))
      (write-line "SDI 1" ofil)
      (write-line (strcat "(setvar " (chr 34) "FILEDIA" (chr 34) " 0)") ofil)
      (foreach dwg dwglist
        (setq fullpath (strcat dirpath dwg))
        (write-line (strcat "_.open " (chr 34) fullpath (chr 34)) ofil)
        (write-line(strcat "(load " (chr 34) my_lisp_file (chr 34) ")") ofil)
        (write-line ".qsave" ofil)
        (write-line "_.close" ofil)
      )
      (write-line (strcat "(setvar " (chr 34) "FILEDIA" (chr 34) " 1)") ofil)
      (write-line "SDI 0" ofil)
      (write-line "\(alert \"Done!!\"\)" ofil)
      (close ofil)
      (command "_.script" scrfile)
    )
  )
  (princ)
)

Gary, his routine skips over that drawing if you send that drawing name.
My version removes it from the list. But you have to supply the skip list of names.
The program call should not include the path, use this for both routines.
(arch:batchplot '("2436TB.dwg"))
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

kpblc

  • Bull Frog
  • Posts: 396
Re: BatchDwg to Plot
« Reply #4 on: March 14, 2006, 09:45:29 AM »
Ok. If the file you don't want to plot guaranteed is first, you can use (cdr) function to return the list of file names (something like this):
Code: [Select]
(defun arch:batchplot ()
  ;; portions by Tim Willey
  (if (setq dirpath (directory-dia "* Select folder of Drawings to process *"))
    (progn
      (setq dwglist (vl-directory-files dirpath "*.dwg" 1))
      (setq scrfile (strcat dirpath "MyScript.scr"))
      (setq ofil (open scrfile "W"))
      (write-line "SDI 1" ofil)
      (write-line (strcat "(setvar " (chr 34) "FILEDIA" (chr 34) " 0)") ofil)
      (foreach dwg (cdr dwglist)
(setq fullpath (strcat dirpath dwg))
    (write-line (strcat "_.open " (chr 34) fullpath (chr 34)) ofil)
    (write-line
      (strcat "(load " (chr 34) my_lisp_file (chr 34) ")")
      ofil
      ) ;_ end of write-line
    (write-line ".qsave" ofil)
    (write-line "_.close" ofil)
) ;_ end of foreach
      (write-line (strcat "(setvar " (chr 34) "FILEDIA" (chr 34) " 1)") ofil)
      (write-line "SDI 0" ofil)
      (write-line "\(alert \"Done!!\"\)" ofil)
      (close ofil)
      (command "_.script" scrfile)
      ) ;_ end of progn
    ) ;_ end of if
  (princ)
  ) ;_ end of defun
Sorry for my English.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: BatchDwg to Plot
« Reply #5 on: March 14, 2006, 09:50:11 AM »
Oops I'm sorry. kpblc's version did require the path but if you change his
to this it will work with the drawing name only

Code: [Select]
      (foreach dwg dwglist
(setq fullpath (strcat dirpath dwg))
(if (not (member dwg file-list-exclude))
« Last Edit: March 14, 2006, 09:56:48 AM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

GDF

  • Water Moccasin
  • Posts: 2081
Re: BatchDwg to Plot
« Reply #6 on: March 14, 2006, 10:01:51 AM »
Thanks guys.

Thats what I tried the first time in another directory with only two drawings to test it out. And it failed because the drawing did not have the correct layout name. Anyway my bad. I get it now, I can skin a cat more than one way now.

Thank you both. Works great now.

Gary
« Last Edit: March 14, 2006, 10:10:27 AM by Gary Fowler »
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 2081
Re: BatchDwg to Plot
« Reply #7 on: March 14, 2006, 10:42:18 AM »
On a side issue that would help in my routine, I have two more questions:

(1.) How do you test for only one drawing open? Test for the SDI mode I quess.

(2.) How do you test for the current drawing being recently saved?

Gary
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: BatchDwg to Plot
« Reply #8 on: March 14, 2006, 10:56:16 AM »
(= 0 (vlax-variant-value (vla-getvariable DocObj "sdi")))

TDUPDATE
(Read-only)
Type: Real
Saved in: Drawing
Stores the local time and date of the last update/save.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

GDF

  • Water Moccasin
  • Posts: 2081
Re: BatchDwg to Plot
« Reply #9 on: March 14, 2006, 11:32:57 AM »
(= 0 (vlax-variant-value (vla-getvariable DocObj "sdi")))

TDUPDATE
(Read-only)
Type: Real
Saved in: Drawing
Stores the local time and date of the last update/save.

Well for now this is what I have done {still lacks the test for current saved drawing}

Code: [Select]
(defun BPLOT-IT (/ tmp *Error*)
  (defun *Error*  (msg)
   (princ "\n*** ///////// Program  CANCELLED ///////// ***")
   ;(princ msg)
   (princ)) 
  (initget "1 2")
  (setq tmp (getkword "\n* Select Batch Plot Type: <1> NetLaser   <2> NetPlot *"))
  (cond
    ((= tmp "1")(setq my_lisp_file (strcat "V:/ARCH/Custom_Architettura/" "PlotCFG/" "NetLaser.lsp"))(ARCH:BatchPlot '("2436TB.dwg")))   
    ((= tmp "2")(setq my_lisp_file (strcat "V:/ARCH/Custom_Architettura/" "PlotCFG/" "NetPlot.lsp"))(ARCH:BatchPlot '("2436TB.dwg")))
    ((or (= tmp nil)(= tmp ""))(princ "\n*** ///////// Program  CANCELLED ///////// ***"))
  )     
  (princ)
)
(defun BPLOTIT () 
  (cond   
    ((= (getvar "SDI") 0)
      (ARCH:MsgBox
    " Arch Program© : Batch Plot Utilities" 64"
     Please follow these instructions:
--------------------------------------------------------------------------------------------
     First:      The ''Current Drawing'' must be SAVED.
     Second:  Have only ONE File open before proceeding."
      )
    )
    ((= (getvar "SDI") 1)(BPLOT-IT))
  )
  (princ)
)

Gary
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: BatchDwg to Plot
« Reply #10 on: March 14, 2006, 12:10:48 PM »
You may want to try something like this.
But it will force you to save the file before plotting.
I suppose you may want to allow plotting the file if it is older than today.
Code: [Select]
(defun BPLOTIT () 
  (cond   
    ((= (getvar "SDI") 0)
      (ARCH:MsgBox
    " Arch Program© : Batch Plot Utilities" 64"
     Please follow these instructions:
--------------------------------------------------------------------------------------------
     First:      The ''Current Drawing'' must be SAVED.
     Second:  Have only ONE File open before proceeding."
      )
    )
    ((= (getvar "SDI") 1)
      (if (< (- (getvar "DATE") (getvar "TDUPDATE")) (/ 5.0 1440))     
        (BPLOT-IT)
      (ARCH:MsgBox
    " Arch Program© : Batch Plot Utilities" 64"
     Error: File has not been saved in the last 5 minuites.
     PLease save the file and try again."
     )
        ))
    (t ;;  SDI = 3 or 4 , read only
      (ARCH:MsgBox
    " Arch Program© : Batch Plot Utilities" 64"
     Error: File is 'Read Only'
     You may not plot from a Read Only File."
     )
  )
  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

GDF

  • Water Moccasin
  • Posts: 2081
Re: BatchDwg to Plot
« Reply #11 on: March 14, 2006, 02:16:27 PM »
You may want to try something like this.
But it will force you to save the file before plotting.
I suppose you may want to allow plotting the file if it is older than today.
Code: [Select]
(defun BPLOTIT () 
  (cond   
    ((= (getvar "SDI") 0)
      (ARCH:MsgBox
    " Arch Program© : Batch Plot Utilities" 64"
     Please follow these instructions:
--------------------------------------------------------------------------------------------
     First:      The ''Current Drawing'' must be SAVED.
     Second:  Have only ONE File open before proceeding."
      )
    )
    ((= (getvar "SDI") 1)
      (if (< (- (getvar "DATE") (getvar "TDUPDATE")) (/ 5.0 1440))     
        (BPLOT-IT)
      (ARCH:MsgBox
    " Arch Program© : Batch Plot Utilities" 64"
     Error: File has not been saved in the last 5 minuites.
     PLease save the file and try again."
     )
        ))
    (t ;;  SDI = 3 or 4 , read only
      (ARCH:MsgBox
    " Arch Program© : Batch Plot Utilities" 64"
     Error: File is 'Read Only'
     You may not plot from a Read Only File."
     )
  )       <-missing ")" here
  (princ)
)

Thanks Allen, that is perfect. Had to add a missing ")". That is just what I wanted.
This part lost me:  (if (< (- (getvar "DATE") (getvar "TDUPDATE")) (/ 5.0 1440)) ...will have to stuy upon it.

I thought SDI could be only 1 or 0?

(t
     ;;  SDI = 3 or 4 , read only

Gary

Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: BatchDwg to Plot
« Reply #12 on: March 14, 2006, 03:38:03 PM »
I thought SDI could be only 1 or 0?

Gary
Quote from: Autocad Help
Type: Integer
Saved in: Registry
Initial value: 0
Controls whether AutoCAD runs in single- or multiple-document interface. Helps third-party developers update applications to work smoothly with the AutoCAD multiple-drawing mode.

0  Turns on multiple-drawing interface.
1  Turns off multiple-drawing interface.
2  (Read-only) Multiple-drawing interface is disabled because AutoCAD has loaded an application that does not support multiple drawings. SDI setting 2 is not saved.
3  (Read-only) Multiple-drawing interface is disabled because the user has set SDI to 1 and AutoCAD has loaded an application that does not support multiple drawings. (SDI was set to 1 before the application was loaded.) SDI setting 3 is not saved.

  If SDI is set to 3, AutoCAD switches it back to 1 when the application that doesn't support multiple drawings is unloaded.
Quote from: Gary
How do you test for only one drawing open?
Code: [Select]
(vla-get-count (vla-get-documents (vlax-get-acad-object)))
Quote from: Gary
How do you test for the current drawing being recently saved?
Code: [Select]
(vla-get-saved
  (vla-get-activedocument
    (vlax-get-acad-object)))
returns :vlax-true or :vlax-false....true meaning it has been saved since any changes were made

GDF

  • Water Moccasin
  • Posts: 2081
Re: BatchDwg to Plot
« Reply #13 on: March 14, 2006, 04:17:07 PM »
Thanks Jeff

I will play around with the tips.

I'm the worst when it comes to plotting...I default to others.

Besides the batchplot routine, I've added the following plotting routines: {I know the coding could use alot of help, but it works}

Code: [Select]
(defun C:LASERW  (/ tmp *Error* x1 x2 y1 y2 XX YY x y) 
  (defun *Error*  (msg)
    (princ "\n*** ///////// Program  CANCELLED ///////// ***") ;(princ msg)
    (princ))
  (setq xx (getpoint "\n* Please pick first point of window *"))
  (setq yy (getcorner xx  "\n* Please pick second point of window *"))
  (setq x1 (car xx) x2 (cadr xx) y1 (car yy) y2 (cadr yy))
  (setq x (list x1 x2))
  (setq y (list y1 y2))
  (initget "1 2")
  (setq tmp (getkword "\n* Select Plot Layout Type: <1> ''Model'' Layout   <2> ''FullSize'' Layout *"))
  (cond ((= tmp "1")
         (command ".plot" "y" "Model" "netlaser.pc3" "Tabloid" "i" "l" "n" "w" X Y "f" "center" "y" "aia standard.ctb" "y" "y" "n" "n" "y" "y"))
        ((= tmp "2")
         (command ".plot" "y" "FullSize" "netlaser.pc3" "Tabloid" "i" "l" "n" "w" X Y "f" "center" "y" "aia standard.ctb" "y" "y" "n" "n" "n" "y" "y"))
        ((or (= tmp nil) (= tmp ""))
         (princ "\n*** ///////// Program  CANCELLED ///////// ***")))
  (princ))
(defun C:LASER  ()
  (command "script" "V:/arch/custom_architettura/plotcfg/NetLaser.scr")
  (princ))
(defun C:NETPLOT  ()
  (command "script" "V:/arch/custom_architettura/plotcfg/NetPlot.scr")
  (princ))

Gary
« Last Edit: March 14, 2006, 04:23:01 PM by Gary Fowler »
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: BatchDwg to Plot
« Reply #14 on: March 14, 2006, 05:48:29 PM »
Thanks Jeff for filling in the missing piece's.
Replace this (vla-get-activedocument (vlax-get-acad-object)) with your *doc* var
Code: [Select]
(defun bplotit ()
  (cond
    ((= (getvar "SDI") 0)
     (arch:msgbox
       " Arch Program© : Batch Plot Utilities"
       64
       "
     Please follow these instructions:
--------------------------------------------------------------------------------------------
     First:      The ''Current Drawing'' must be SAVED.
     Second:  Have only ONE File open before proceeding."
     )
    )
    ((= (getvar "SDI") 1)
     (if (= (vla-get-saved (vla-get-activedocument (vlax-get-acad-object))) :vlax-true)
       (bplot-it)
       (arch:msgbox
         " Arch Program© : Batch Plot Utilities"
         64
         "
     Error: File has not been saved .
     PLease save the file and try again."
       )
     )
    )
    (t
     ;;  SDI = 3 or 4 , read only
     (arch:msgbox
       " Arch Program© : Batch Plot Utilities"
       64
       "
     Error: File is 'Read Only'
     You may not plot from a Read Only File."
     )
    )
  )
  (princ)
)

Gary what was the vla-get-count for? Were you going to allow plotting if SDI=0 & count was 1
« Last Edit: March 14, 2006, 05:54:38 PM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

GDF

  • Water Moccasin
  • Posts: 2081
Re: BatchDwg to Plot
« Reply #15 on: March 15, 2006, 09:58:24 AM »
I would say most of the time I don't know what I'm doing...I just want to get something that works and figure it out later.
And plotting has always been a head ache. It works perfectly now, thanks to you guys. That batch utilty for creating script files is pretty sweet.

Gary
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64