broncos15 发表于 2022-7-5 16:40:00

从E更新块属性

因此,我试图基于一个包含四列的csv文件更新一个块(名为DRN-BASIN)。第一列有盆地编号,接下来是英亩,接下来是CO-EF,接下来是CO-EF-2。我需要根据块的相应盆地编号属性更新图形中的块。块的所有属性都对应于Excel csv文件中的一列。我应该从哪里开始迭代块并找到每个块属性?

BIGAL 发表于 2022-7-5 17:12:15

第一李mac有一个csv到一个“列表”为每一行,所以你得到4个值。
 
这里的许多块示例都是从ssget开始的(2.Blockname)
 
只需搜索选择集并使用标记名检查属性TEXTSTRING,如果是,则更新属性。
 
这需要更新多个标记

; update the COGG title blocks in a dwg
; change the 410 to layout name
;;-------------------=={ Parse Numbers }==--------------------;;
;;                                                            ;;
;;Parses a list of numerical values from a supplied string. ;;
;;------------------------------------------------------------;;
;;Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;Arguments:                                                ;;
;;s - String to process                                     ;;
;;------------------------------------------------------------;;
;;Returns:List of numerical values found in string.       ;;
;;------------------------------------------------------------;;
(defun LM:ParseNumbers ( s )
(
   (lambda ( l )
   (read
       (strcat "("
         (vl-list->string
         (mapcar
             (function
               (lambda ( a b c )
               (if
                   (or
                     (< 47 b 58)
                     (and (= 45 b) (< 47 c 58) (not (< 47 a 58)))
                     (and (= 46 b) (< 47 a 58) (< 47 c 58))
                   )
                   b 32
               )
               )
             )
             (cons nil l) l (append (cdr l) (list nil))
         )
         )
         ")"
       )
   )
   )
   (vl-string->list s)
)
)
(defun ah:sheetupdate1 ( / ss1 len lay plotabs tabname dwgname oldtag1 oldtag2 oldtag3 oldtag4 oldtag5)
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(vlax-for lay (vla-get-Layouts doc)
(setq plotabs (cons (vla-get-name lay) plotabs))
)
(IF (NOT AH:getval3)(LOAD "GETVALS"))
(AH:getval3 "Please enter dwg number" 12 9
"Please enter version for all sheets <Cr> no change" 8 5
"Please enter line1 details " 40 38
)
(setq dwgname VAL1)
(setq newstr4 VAL2)
(SETQ NEWSTR6 VAL3)

(princ "0")
(setq len (length plotabs))
(setq x 0)
(setq bname "DA1DRTXT")
(repeat len
(setq tabname (nth x plotabs))
(if (/= tabname "Model")
   (progn
   (setvar "ctab" tabname)
   (command "pspace")
   (setq ss1 (ssget "x"(list (cons 0 "INSERT") (cons 2 bname)(cons 410 tabname))))
   (setq dwgnum (Lm:parsenumbers tabname))
   (setq sheetnum (car dwgnum))
   (setq oldtag1 "SHT_NO") ;attribute tag name
   (setq newstr1 (rtos sheetnum 2 0))
   (setq oldtag2 "DRG_NO") ;attribute tag name
   (setq oldtag3 "PROJ_NO") ;attribute tag name
   (setq newstr3 dwgname)
   (setq oldtag4 "REV_NO") ;attribute tag name
   (setq oldtag5 "SHEETS") ;attribute tag name
   (setq oldtag6 "STREET") ;attribute tag name

; if less than 10
(if (< (car dwgnum) 10.0)
   (setq newstr2 (strcat dwgname "-D0"(rtos sheetnum 2 0)))
   (setq newstr2 (strcat dwgname "-D"(rtos sheetnum 2 0)))
)
   (foreach att (vlax-invoke (vlax-ename->vla-object (ssname SS1 0 )) 'getattributes)
       (if (= oldtag1 (strcase (vla-get-tagstring att)))
       (vla-put-textstring att newstr1)
       ) ; end if
       (if (= oldtag2 (strcase (vla-get-tagstring att)))
       (vla-put-textstring att newstr2)
       ) ; end if
       (if (= oldtag3 (strcase (vla-get-tagstring att)))
       (vla-put-textstring att newstr3)
       ) ; end if
       (if (and (/= newstr4 nil) (= oldtag4 (strcase (vla-get-tagstring att))) )
       (vla-put-textstring att newstr4)
       ) ; end if
       (if (= oldtag5 (strcase (vla-get-tagstring att)))
       (vla-put-textstring att (rtos (- len 1) 2 0))
       ) ; end if
(if (= oldtag6 (strcase (vla-get-tagstring att)))
       (vla-put-textstring att newstr6)
       ) ; end if
      ) ; end foreach
   ) ; end progn
) ; end if
(setq x (+ x 1))
) ; end repeat
(setq ss1 nil)
) ; end defun ah

(ah:sheetupdate1)
(princ)

BIGAL 发表于 2022-7-5 17:52:59

差点忘了如果你想删除生成csv的步骤,可以直接从excel中删除。
页: [1]
查看完整版本: 从E更新块属性