Code Red > AutoLISP (Vanilla / Visual)

HOW TO XREF BIN INSERT MODE

(1/2) > >>

DEVITG:
Hi all , would you help me please??

I'm looking for a batch processor to do the following

I have a lot of drawings with it's XREF files on a given phat.

This is the seudo code.

select the phat
while files on phat

open each drawing
do the following

 
--- Quote ---Command: bindtype

Enter new value for BINDTYPE <0>: 1

Command: -xref

Enter an option [?/Bind/Detach/Path/Unload/Reload/Overlay/Attach] <Attach>: b

Enter xref name(s) to bind: *

Command: z
ZOOM
Specify corner of window, enter a scale factor (nX or nXP), or
[All/Center/Dynamic/Extents/Previous/Scale/Window] <real time>: e
Command: _qsave


--- End quote ---


end while



--- Quote ---

The pourpouse is to send to sub contractors only one file.


--- End quote ---


How far is pack and go from expresstool to do the same?
Of course it make one at the time.

Thank in advance.

V-Man:
Here you go. Just save this LISP and DCL in your search path and load the LISP. Type in BatchBind at the command prompt. You will then be asked to go and select any drawing in the directory, a dialog box will pop-up and then you can select ow many and/or which drawings you want this lisp to run on. Have fun....

Don V.

**Lisp Code Below**

--- Code: ---
;;; BatchBind.LSP  - Batch processing
;;;
;;; This routine can batch process drawing files in a directory.
;;; You can edit the following command line for your needs.
;;; For example, you can use this routine to batch audit drawings
;;; or batch convert drawings from one AutoCAD version to another.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq *process
;; Commands will be run after the drawing is open - can be edited
;--------------------------------------------------------------------;
;   "ZOOM E"     ;Example for Zooming to Extents on all drawings
    "bindtype 1 -xref b * zoom e" ;Example to bind Xref's
;--------------------------------------------------------------------;
)

(defun C:BatchBind(/ afile listpath tempfile filelist scrfile fp file)
   (setq afile (getfiled (strcat "Select a file in a desired "
             "directory for multiple selecting") "" "DWG" 0))
   (if afile
     (progn
       (setq listpath (get_path afile))
       (setq tempfile (strcat "\"" listpath "temp.dwg\""))
       (if (findfile tempfile)
         (command "_SAVE" tempfile "y")
         (command "_SAVE" tempfile)
       )
       (setq filelist (select_list (get_file_list listpath)))
     )
     (alert "You need to pick a file in the directory!")
   )

  (if filelist
   (progn
     (setq scrfile (strcat listpath "temp.scr"))
     (setq fp (open scrfile "w"))
     (foreach file filelist
       (write-line (strcat "_OPEN " "\"" listpath file "\"") fp)
       (write-line (strcat *process " _QSAVE") fp)
     )
     (close fp)
     (command "_SCRIPT" scrfile)
  ) ;progn
 ) ;if
 (princ)
)

;; return multiple selections in a list box
(defun select_list(from_list / lst_dcl select lst_mode)
     (setq lst_dcl (load_dialog "BatchBind.dcl"))
     (if (not (new_dialog "BatchBind_dcl" lst_dcl))(exit))
     (start_list "file_lst")
     (mapcar 'add_list from_list)
     (end_list)
     (action_tile "file_lst" "(setq select $value)")
     (action_tile "lst_ok" "(done_dialog 1)")
     (action_tile "lst_cancel" "(done_dialog 2)")
     (setq lst_mode (start_dialog))
     (unload_dialog lst_dcl)
     (if (= lst_mode 1)
       (if select
          (mk_list select from_list)
       )
     )
)

;; return to_list from from_list according to select value
(defun mk_list (select from_list / count item to_list)
  (setq count 1)
  (while (setq item (read select))
     (setq to_list (cons (nth item from_list) to_list))
     (while (and (/= " " (substr select count 1))
        (/= "" (substr select count 1)))
       (setq count (1+ count))
     )
     (setq select (substr select count))
   )
   (reverse to_list)
)


;; Return file list in listpath directory with extention ext
(defun get_file_list (listpath / listfile fp fileline linelen
                     startnum filelist scr file extention filename c)
   (setq listfile "temp.txt")
   (setq listfile (strcat listpath listfile))
   (setq fp (open listfile "w"))
   (write-line "File list for this directory:" fp)
   (close fp)
   (setq filelist '())
   (setq scr (strcat "dir \"" listpath "\" > \"" listfile "\""))
   (command "_shell" scr)
   (command "_delay" 2000)
   (setq fp (open listfile "r"))
   (while (setq fileline (read-line fp))
      (setq linelen (strlen fileline))

      ;; for windows 3.1 file name start position
      (setq startnum 40)  
      (if (or (= (substr fileline startnum 1) ":") ; for Windows 95
              (= (substr fileline (1+ startnum) 1) ":") ; for Windows NT
          )
          (setq startnum 45)  
      )

      ;; for windows 3.1 or windows 95 long file system    
      (if (> linelen (+ startnum 3))
        (progn
           (setq file (substr fileline startnum (1+ (- linelen startnum))))
           (setq extention (substr file (- (strlen file) 2) 3))
        )
        ;else for windows 95 without long file
        (progn
          (if (> linelen 12)
           (progn
             (setq extention (substr fileline 10 3))
    (setq file (strcat (substr fileline 1 8) "." extention))
             (setq file (delete_space file))
           )
           (setq extention "")
          )
        );progn
       )

       ; if file has extention "dwg" add to file list
       (if (= (strcase extention) "DWG")
           (setq filelist (append filelist (list file)))
       )
   ); end while
   (close fp)
   (setq filelist filelist)
)

;; delete space in file name
(defun delete_space(in_file / out_file file_len count c)
   (setq file_len (strlen in_file) count 1 out_file "")
   (while (<= count file_len)
     (setq c (substr in_file count 1))
     (if (/= c " ")
       (setq out_file (strcat out_file c))
     )
     (setq count (1+ count))
   )
   (eval out_file)
)

(defun get_name (full_str / count full_count not_found)
  (if full_str (progn
    (setq count (strlen full_str))
    (setq full_count count)
    (setq not_found T)
    (while not_found
    (if (or(= (substr full_str count 1) "\\")
           (= (substr full_str count 1) "/"))
      (setq not_found nil)
      (setq count (- count 1)))
     )
    (substr full_str (1+ count)  (- full_count 1) )
   )(eval "")) ;progn if
)

(defun get_path(fullname / path name)
   (setq name (get_name fullname))
   (setq path (substr fullname 1 (- (strlen fullname) (strlen name))))
)

(princ "\nType BatchBind to run batch processing.")(princ)

--- End code ---




**Dialog Box Code Below**

--- Code: ---
BatchBind_dcl : dialog {
    label = "Select Multiple Drawings";
    spacer_1;
    :list_box { key = "file_lst"; width = 20; height = 24; multiple_select=true;}
    :row {
       spacer_0;
       :ok_button { key = "lst_ok"; is_cancel = true;}
       :cancel_button { key = "lst_cancel"; is_cancel = true;}
       spacer_0;
    }
 }

--- End code ---



Good Luck

DEVITG:
Hi Dvarino .

I run the lisp and get this , I change to #bb as the new command , just for speed typing


--- Quote ---Command: #bb
_SAVE Save drawing as <C:\Archivos de programa\AutoCAD
2002\bindingxref\temp.dwg>: "C:\Archivos de programa\AutoCAD
2002\bindingxref\temp.dwg"
Command: y Unknown command "Y".  Press F1 for help.

Command: _shell
OS Command: dir "C:\Archivos de programa\AutoCAD 2002\bindingxref\" >
"C:\Archivos de programa\AutoCAD 2002\bindingxref\temp.txt"
Command: _delay Enter delay time (in milliseconds): 2000
Command: ; error: quit / exit abort

--- End quote ---

V-Man:
Sorry about that, I forgot that this only works in SINGLE drawing mode only.
Go to TOOLS/OPTIONS/SYSTEM/ and check on the Single-Drawing capatibility mode.

KewlToyZ:
or just start the routine with
(command "SDI" "1") ;to turn on single drawing mode
end the routine with
(command "SDI" "0") ;to turn off single drawing mode

Navigation

[0] Message Index

[#] Next page

Go to full version