Author Topic: Need guidance with batch processing  (Read 8990 times)

0 Members and 1 Guest are viewing this topic.

JohnK

  • Administrator
  • Seagull
  • Posts: 10649
Re: Need guidance with batch processing
« Reply #30 on: February 26, 2010, 10:27:44 AM »
If i think i understand (i hope you're not gonna ask what i think you're gonna ask :lol:) that changes the complexity just a bit.

In the off chance that this might appease you...okay its more like a quick joke but. Here is a quick reproduction of the "FILE NEW" button. Does that work?
Code: [Select]
(if (= 0 (getvar 'SDI))
  (vla-add
    (vla-get-documents
      (vla-get-application
(vlax-get-acad-object)))))

Map out what you think the progy should do in plain english.

EX:

Start  a new dwg
copy in blocks from <1.dwg>
copy in layers from <2.dwg>
...
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Need guidance with batch processing
« Reply #31 on: February 26, 2010, 11:11:38 AM »
I would strongly recommend against using SDI mode, because SDI mode will most likely be gone with the next file format change.

debgun

  • Guest
Re: Need guidance with batch processing
« Reply #32 on: March 01, 2010, 09:33:27 AM »
Okay! So here is my attempt at batch processing.  I haven't had a chance to try it out, yet.

Code: [Select]
(defun c:inscircuit (/ Alldata Header bName actdoc actspace en x y scale colnum sheetnum tblock terminal)
  (setq Alldata (GetExcel "C:\\Documents and Settings\\dguenthner\\My Documents\\GenerateIO.xlsx" nil nil))
  (setq Header (car Alldata)) ;stores the column names separate from data
  (setq Alldata (cdr Alldata)) ;stores the data separate from the column names
  (setq path (BrowseFolder)) ;stores folder location ;User Interaction Required
 
  (foreach data Alldata ;cycles through all lines of data to retrieve block path
    (setq bName (nth 1 data) ;assigns variable to block path
        dwgname (nth 0 data) ;assigns variable the dwg name
actdoc (vla-get-activedocument (vlax-get-acad-object)) ;retrieves the active document
actspace (vla-get-block (vla-get-activelayout actdoc))) ;retrieves the active space e.g. model / paper
    (if (<> dwgname "") ;if variable contains a value then start a new dwg
       (progn
          (setq newdoc (vla-add (vla-get-documents (vlax-get-acad-object)) "Kice 11X17"))
          (vla-saveas newdoc (strcat path "/" dwgname) ac2007_dwg)
          (command (DwgSetup))
       ) ;progn
    ) ;if
    (vla-startundomark actdoc) ;allows undo to undo one step at a time, whereas all at once
    (setq x (atof (nth 3 data))
  y (atof (nth 4 data))
  scale (atof (nth 5 data)))
    (c:wd_ins_circ2 bName (list x y) scale 7) ;insert collection of prewired components
    (setq colnum 6) ;setting column number to fill-in attribute values
    (setq en (entlast)) ;selecting plc block object
    (foreach head Header
      (c:wd_modattrval en (nth colnum Header) (nth colnum data) nil) ;modifying attributes
      (setq colnum (1+ colnum))
    ) ;foreach close
    (command (Retag_terminal)) ;calling next function
    (command (EditLadder)) ;calling next function
   ) ;foreach close
  (CloseExcel nil) ;killing excel instance
  (princ) ;quiet exit
 ) ;defun close


(defun DwgSetup (/ DName SheetDName)
   (setq Dwg "IO"
         DName (getvar "DWGNAME"))
   (setq SheetDName (substr DName 3))
   (setq ss (ssget "X" '((0 . "INSERT") (2 . "wd_m"))))
   (setq en (ssname ss))
   (c:wd_modattrval en "SHEET" Dwg nil)
   (c:wd_modattrval en "SHEETDWGNAME" SheetDName nil)
   (c:wd_ladr_reref)
)

debgun

  • Guest
Re: Need guidance with batch processing
« Reply #33 on: March 11, 2010, 05:22:53 PM »
With the help of an expert (T.Willey) on The Swamp I was able to get a working batch script.  Here is the final result.
Code: [Select]
;This program creates a batch process for IO drawings.  It starts by creating the IO drawings then runs 2 commands.
;Command 1, sets up the drawing and adds it to the active project.  Command 2, inserts the IO for that drawing.
;Need in conjuntion with this program: tb_concatenate.lsp, match_proj_properties.lsp, Insert IO.lsp, GetExcel.lsp,
;KillExcel.vbs
;Created March 11, 2010
;Debbie Guenthner
                 ;      ;        ;;;;     ;;;;;  ;;   ;
  ; ;    ; ;      ;    ;      ;    ; ;  ;
       ;  ;   ;   ;    ;;;;;;;;    ;    ;  ; ;
      ;    ; ;     ;  ;        ;    ;    ;   ;;
        ;     ;      ; ;          ; ;;;;;  ;    ;

;Main Program

(defun C:Batch (/ script Alldata path dwglst dwgs)
  (setq script "c:/newdwgs.scr")
  (alert "Close Excel documents before proceeding.")
  (setq Alldata (GetExcel "G:\\Automation\\Drawing Patterns\\AutoCAD STD\\AutoLisp Files\\Excel to IO\\GenerateIO.xlsx" nil nil))
  (setq Alldata (cdr Alldata) ;stores the data separate from the column names
        path (strcat (BrowseFolder) "\\"))
  (foreach data Alldata ;cycles through all lines of data to retrieve dwg name
    (setq dwglst (cons (nth 0 data) dwglst))
  ) ;foreach
  (foreach dwg dwglst
    (if (null (member dwg dwgs)) ;remove duplicates
      (setq dwgs (cons dwg dwgs))
    ) ;if
  ) ;foreach
;;;  (setq dwgs (apply 'path (dwgs)))
  (CreateScript script path dwgs)
  (command "_.SCRIPT" script)
  (vl-file-delete script)
  (princ)
)

;-------------------------------------------------------------------------------------------------------------------------
;This function creates the script file
(defun CreateScript (script path dwgs / f io lsp)
  (setq f (open script "w"))
  (setq io "G:/Automation/Drawing Patterns/AutoCAD STD/AutoLisp Files/Excel to IO/Insert IO.lsp") ;2nd routine
  (setq lsp "G:/Automation/Drawing Patterns/AutoCAD STD/AutoLisp Files/Excel to IO/StartIO.LSP") ;1st routine
  (foreach dwg dwgs
    (write-line "_.new \"Kice 11X17\"" f)
    (write-line (strcat "_.saveas 2007 \"" path dwg ".dwg\"") f)
    (write-line (strcat "(load \"" lsp "\")") f)
    (write-line "DwgSetup" f)
    (write-line (strcat "(load \"" io "\")") f)
    (write-line "insertio" f)
    (write-line "_.qsave" f)
    (write-line "_.close" f)
    ) ;foreach
    (write-line "" f)
    (close f)
) ;defun

;-------------------------------------------------------------------------------------------------------------------------
;This function prepares the drawing to add to active project and update titleblock
(defun C:DwgSetup (/ DName Dwg SheetDName bk ss en) ;1st rountine
  (setq Dwg "IO"
DName (getvar "DWGNAME"))
  (setq SheetDName (substr DName 4 2)) ;retrieving sheet no i.e. AA
  (setq ss (ssget "X" '((0 . "INSERT") (2 . "wd_m")))) ;locating block to modify attributes
  (setq sslen (sslength ss)) ;# of blocks inserted
  (setq bk -1) ;counter
  (while (< (setq bk (1+ bk)) sslen)
    (setq en (ssname ss bk))
    (c:wd_modattrval en "SHEET" SheetDName nil)
    (c:wd_modattrval en "SHEETDWGNAME" Dwg nil)
    (c:wd_ladr_reref) ;update ladder numbers
    (c:ace_add_dwg_to_project nil nil) ;add active drawing to active project
    (c:wd_tb_process_one 0 (list (list 0 0 0 0 0 0 1 1 0 0 1 1 1) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)) ;update titleblock
    (c:match_proj_properties)
    ;(c:insertio)
  ) ;while
) ;defun

;-------------------------------------------------------------------------------------------------------------------------
;This function opens a file dialog box for user to select a folder
(defun BrowseFolder (/ ShlObj Folder FldObj OutVal)
  (setq ShlObj (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application")
Folder (vlax-invoke-method ShlObj 'BrowseForFolder 0 "" 0)
  ) ;setq
  (vlax-release-object ShlObj)
  (if Folder
    (progn
      (setq FldObj (vlax-get-property Folder 'Self)
    OutVal (vlax-get-property FldObj 'Path)
      ) ;setq
      (vlax-release-object Folder)
      (vlax-release-object FldObj)
      OutVal
    ) ;progn
  ) ;if
) ;defun