明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1788|回复: 2

我的lisp,请那位大侠给调试一下,谢了:)

[复制链接]
发表于 2006-11-29 22:10:00 | 显示全部楼层 |阅读模式


;  Permissions:
;    Permission is hereby granted to copy and modify this lisp.  It is provided "as is" by the author.
;    The authorship and url must remain with the copied function. 
;  Version:
;    1.0 - April 2, 2004
;  Explanation:
;    This function binds external refrences in a directory and copies it to a specified location within
;    that same directory.
;    To initiate the function, load bb.lsp and type bb.  When the dialog closes, the function should open the
;    first in the list of files selected, saveas to a specified location, and bind it.  It will continue
;    this process until halted (esc) or all the files have been processed.  If the process has been halted,
;    the function will continue when the process is started(*) again.  After being halted and started from a 
;    new location, if the next file is not found, the registry should be cleared of the queued files.
;    * To start the process after a file is opened, the bb.lsp needs to be loaded.  This can either be
;      done manually or by setting AutoCAD to load the lisps with every drawing.
;  Known bugs:
;    none


(setq bb_keydir "HKEY_LOCAL_MACHINE\\SOFTWARE\\Autodesk\\AutoCAD\\autolisp.org\\bb\\")

(defun clear_bb (/ quant count)

 ; for use with batch bind
  (setq quant (vl-registry-read bb_keydir "quantity"))
  (setq count (atoi (if quant quant ""))) (vl-registry-write bb_keydir "quantity" "0")
  (while (>= (setq count (1- count)) 0) (if (vl-registry-read bb_keydir (itoa count)) (vl-registry-delete bb_keydir (itoa count))))
  count
)


(defun c:bb ( / quitmode pre dir fo a dcl count togglelst) ; Batch Bind
; donations welcome
  (setq maxcol 25) (clear_bb)
  (setq continue T)
  (while continue
    (setq pre (getvar "dwgprefix"))
    (setq dcl (strcat pre "bbout.dcl"))
    (setq dir (vl-directory-files pre "*.dwg"))
    (setq continue nil)
    (setq fo (open dcl "w"))
    (write-line "bb : dialog {" fo)
    (write-line (strcat "  label = \"Batch Bind - bind a whole directory\"" (chr 59)) fo)
    (write-line (strcat "  : row { key = \"r1\"" (chr 59)) fo)
    (write-line (strcat "    : column { key = \"c1\"" (chr 59)) fo)
    (write-line (strcat "      : button { key = \"butt1\"" (chr 59)) fo)
    (write-line (strcat "        label = \"Unselect All\"" (chr 59)) fo)
    (write-line (strcat "      }") fo)
    (write-line (strcat "      : button { key = \"butt2\"" (chr 59)) fo)
    (write-line (strcat "        label = \"Select All\"" (chr 59)) fo)
    (write-line (strcat "      }") fo)
    (setq count -1)
    (foreach a dir
      (setq count (1+ count))
      (if (> (length dir) maxcol)
        (if (and (> count 0) (= (rem count maxcol) 0)) (progn
          (write-line "} " fo) ; col
          (write-line (strcat ": column { key = \"c" (itoa count) "\"" (chr 59)) fo)
        ))
      ) ; if & progn maxcol
      (write-line (strcat "      : toggle { key = \"t" (itoa count) "\"" (chr 59)) fo)
      (write-line (strcat "        label = \"" a "\"" (chr 59)) fo)
      (write-line (strcat "      }") fo)
    ) ; foreach
    (setq count2 (1+ count))
    (write-line (strcat "    }") fo) ; column1
    (write-line (strcat "  }") fo) ; r1
    (write-line (strcat "  ok_cancel_help" (chr 59)) fo)
    (write-line "}" fo)
    (close fo)

    (new_dialog "bb" (setq load_err (load_dialog dcl)))
    (if (> (length dir) 60) (progn (princ " Put some of these files in folders, there's too many!") (setq load_err -1)))
    (vl-file-delete dcl)
    (if (< load_err 0) (quit))
    (action_tile "butt1" "(setq togglelst nil)(setq count -1)(foreach a dir (setq count (1+ count))(set_tile (strcat \"t\" (itoa count)) \"\"))")
    (action_tile "butt2" "(setq count -1) (while (< (setq count (1+ count)) (length dir)) (setq togglelst (append togglelst (list count))))(setq count -1)(foreach a dir (setq count (1+ count))(set_tile (strcat \"t\" (itoa count)) \"1\"))")
    (action_tile "cancel" "(done_dialog)(setq quitmode 1)")
    (action_tile "help" "(done_dialog)(princ \"Help\")(setq quitmode 2)")
    (setq count (1+ count))
    (while (>= (setq count (1- count)) 0)
      (action_tile (strcat "t" (itoa count))
        (strcat
          "(if (member " (itoa count) " togglelst) (setq togglelst (vl-remove " (itoa count) " togglelst)) (setq togglelst (append togglelst (list " (itoa count) "))))"
        ) ; strcat
      ) ; action_tile
    ) ; while
    (start_dialog)
  ) ; while continue
  (cond
    ((= quitmode 1) (princ "* CANCEL *"))
    ((= quitmode 2) (princ "? There's no help for you. Try someone with a little more patience. You're ugly. "))
    (T
      (vl-registry-write bb_keydir "quantity" (itoa (length dir)))
      (setq count -1)
      (foreach a dir
        (setq count (1+ count))
        (if (member count togglelst)
          (vl-registry-write bb_keydir (itoa count) a)
        ) ; if member
      ) ; foreach
      (institute_bb nil)
    ) ; T cond
  ) ; cond
  (princ)
) ; bb

(defun institute_bb (go / quant count pre curdwg file) ; for use with bb
; implimentation of the bb command
  (setq quant (atoi (vl-registry-read bb_keydir "quantity")) count -1)
  (setq pre (getvar "dwgprefix") innerfolder "bound\\")
  (while (and (<= (setq count (1+ count)) quant) (not curdwg) (> quant 0))
    (setq curdwg (vl-registry-read bb_keydir (itoa count)))
  )
  (if curdwg
    (setq file (findfile (strcat pre curdwg)))
    (progn
      (clear_bb)
      (command "_saveas" "" (strcat pre innerfolder (getvar "dwgname")) "xref" "bind" "*" "_qsave")
    ) ; progn
  )
  (if file (progn
    (vl-mkdir (strcat pre innerfolder))
    (vl-registry-delete bb_keydir (itoa (1- count)))
    (if go
      (command "_saveas" "" (strcat pre innerfolder (getvar "dwgname")) "xref" "bind" "*" "_qsave" "open" file)
      (command "_qsave" "open" file)
    ) ; if
  ) (clear_bb)) ; if & progn
  (princ)
) ; institute_bb

(if (> (atoi (vl-registry-read bb_keydir "quantity")) 0) (institute_bb 1))

 楼主| 发表于 2006-11-30 12:30:00 | 显示全部楼层

这个lisp是完成批量邦定的德,请那位大侠调试一下,有点问题

发表于 2006-11-30 16:09:00 | 显示全部楼层

;未测试

(if (and (vl-registry-read BB_KEYDIR "quantity")
  (> (atoi (vl-registry-read BB_KEYDIR "quantity")) 0)
    )
  (INSTITUTE_BB 1)
)

 

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2025-9-19 03:54 , Processed in 0.214053 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表