再次非常感谢 这个怎么样:
(defun C:test ( / L )
(cond
( (not c:BFind) (alert "\nPlease download Lee Mac's Batch Find v2-0 rotuine.") )
( (not (setq L (xl_TwoColumnsPrompt))) "c'mon you know what you (not) did" )
( (not (setq L (vl-remove-if (function (lambda (x) (= "" (car x) (cdr x)))) L))) (prompt "\nInvalid cells in first and second column.") )
(
(defun _GetSavePath ( / tmp ) ; Taken from BFindV2-0.lsp
(cond
( (setq tmp (getvar 'ROAMABLEROOTPREFIX))
(strcat (vl-string-right-trim "\\" (vl-string-translate "/" "\\" tmp)) "\\Support")
)
( (setq tmp (findfile "ACAD.pat"))
(vl-string-right-trim "\\" (vl-string-translate "/" "\\" (vl-filename-directory tmp)))
)
( (vl-string-right-trim "\\" (vl-filename-directory (vl-filename-mktemp))) )
)
); defun _GetSavePath
(Bfind2-0:BatchDefaultFindReplaceList (strcat (_GetSavePath) "\\LMAC_BFind_V" "2-0" ".cfg") L)
(c:BFind)
)
); cond
(princ)
); defun
(defun xl_TwoColumnsPrompt ( / *error* xlapp xls msg xlwbs xlwbk xlsht xlrng xlcls xlcol L )
(defun *error* ( m )
(and (eq 'VLA-OBJECT (type xlwbk)) (vl-catch-all-apply 'vlax-invoke-method (list xlwbk 'close :vlax-false)) )
(and xlapp (vl-catch-all-apply 'vlax-invoke-method (list xlapp 'quit)))
(foreach o (reverse (list xlapp xls msg xlwbs xlwbk xlsht xlrng xlcls xlcol L)) (and (eq 'VLA-OBJECT (type o)) (vl-catch-all-apply 'vlax-release-object (list o))) )
(gc) (and m (princ m)) (princ)
); defun *error*
(cond
( (not (setq xlapp (vlax-get-or-create-object "Excel.Application"))) (prompt "\nUnable to interfere with Excel application.") )
( (not (setq xls (getfiled "Specify xlsx file" (strcat (getenv "userprofile") "\\Desktop\\") "xlsx" 16))) )
(
(vl-catch-all-error-p
(setq msg
(vl-catch-all-apply
(function
(lambda ( / GetCellText i )
(setq GetCellText (lambda ( xlcls row col ) (vlax-variant-value (vlax-get-property (vlax-variant-value (vlax-get-property xlcls 'item row col)) 'Text)) ))
(vlax-put-property xlapp 'Visible :vlax-false)
(setq xlwbs (vlax-get-property xlapp 'Workbooks))
(setq xlwbk (vlax-invoke-method xlwbs 'Open xls))
(setq xlsht (vlax-get-propertyxlapp 'ActiveSheet))
(setq xlrng (vlax-get-propertyxlsht 'UsedRange))
(setq xlcls (vlax-get-propertyxlrng 'Cells))
(repeat (setq i (vlax-get-property (setq xlcol (vlax-get-propertyxlrng 'Rows)) 'Count))
(setq L (cons (cons (GetCellText xlcls i 1) (GetCellText xlcls i 2)) L))
(setq i (1- i))
); repeat
)
)
)
)
)
(prompt (strcat "\nError: "(vl-catch-all-error-message msg)))
)
); cond
(*error* nil) L ; NOTE: L is based on the UsedRange, so there might be empty cells like: ("" . ""), these are retained in the list due the posibility to use the cell's positions
); defun xl_TwoColumnsPrompt
; fnm - (strcat (_GetSavePath) "\\LMAC_BFind_V" "2-0" ".cfg"), (_GetSavePath) can be found inside of BFindV2-0.lsp, "2-0" is the Bfind version
; L - dxf assoc list of strings: '(("FindThis" . "ReplaceWithThis") ...)
; example: (Bfind2-0:BatchDefaultFindReplaceList (strcat (_GetSavePath) "\\LMAC_BFind_V" "2-0" ".cfg") '(("1" . "2")("3" . "4")) )
(defun Bfind2-0:BatchDefaultFindReplaceList ( fnm L / stringp *error* des row tmp r )
(setq stringp (lambda (x) (eq 'STR (type x))))
(defun *error* ( m ) (and (eq 'FILE (type des)) (close des)) (and m (princ m)) )
(cond
( (not (stringp fnm)) )
( (or (not (vl-consp L)) (not (vl-every (function (lambda (x) (and (vl-consp x) (stringp (car x)) (stringp (cdr x))))) L))) )
( (findfile fnm)
(setq des (open fnm "R")) (while (setq row (read-line des)) (setq tmp (cons row tmp))) (setq tmp (reverse tmp)) (close des)
(setq des (open fnm "W")) (foreach x (cons (vl-prin1-to-string L) (cdr tmp)) (write-line x des))
(setq r t)
)
( (apply 'vl-filename-mktemp (fnsplitl fnm)) (setq des (open fnm "W"))
(foreach x (list L (vl-string-right-trim "\\" (getvar 'dwgprefix)) "0" "0" "1" (+ 1 8 16 32 64 128 256 512) "0" "0") ; these are the defaults from BFindV2-0.lsp
(write-line (vl-prin1-to-string x) des)
); foreach
(setq r t)
)
); cond
(*error* nil) r
); defun Bfind2-0:BatchDefaultFindReplaceList
但它需要李·麦克的批量查找和替换文本 很好的一个家伙,Marko&Grrr,它显示了听起来像是一个简单请求所需的开销,只需更改一些文本。 @Grrr,
同样感谢您的代码,它有一些额外的功能,比我预期的和需要的要高。
谢谢你,比格尔!
不过,谢谢你,所有这些功能都来自Lee Mac的例程——我刚刚想出了如何在其中批处理预定义的查找/替换列表(以及excel部分)。
页:
1
[2]