TMORRIS 发表于 2022-7-6 09:27:47

从中获取文本字符串的值

我有一系列称为1bar、2bar、4bar、8bar、12bar、16bar等的比例尺块
 
每个块中都有一段类似的文本
i、 例如,12“=1’-0”、6“=1’-0”、3“=1’-0”、1 1/2“=1’-0”等
 
我需要一段代码来获取该文本字符串的值,以便我可以在lisp例程的其他地方使用它
 
懒洋洋地走出来寻求帮助
 
TAM公司

BlackBox 发表于 2022-7-6 09:33:14

文本是嵌套的文本/多行文字对象,还是属性?
 
如果您可以发布示例块,这也会有所帮助。

TMORRIS 发表于 2022-7-6 09:38:37

我应该说我想“设置”整个文本
 
它只是一段文字(不是多行文字或属性)

BlackBox 发表于 2022-7-6 09:42:10

这可以使用AutoLISP或Visual LISP来完成(不确定您更精通哪一种?)
 
您必须单步遍历块的嵌套对象,当您找到要查找的对象的匹配项时,提取TextString属性。
 
例子:
 

;; <-- Step through
(if (= "AcDbText" (vla-get-objectname <Object>))
   (setq TextString (vla-get-textstring <Object>)))

24巴。图纸

Lee Mac 发表于 2022-7-6 09:45:10

 
您不能使用ssget选择子实体,您需要按照前面所述逐步完成块定义。

TMORRIS 发表于 2022-7-6 09:49:25

听起来好像有人需要制作一个属性块。

TMORRIS 发表于 2022-7-6 09:50:59

详细示例:

(progn
;;SET VARIABLES
(setvar "cmdecho" 0)
(setvar "attdia" 0)
(setvar "attreq" 0)
(setvar "filedia" 0)
(command "ucsicon" "off")
(command "style" "standard" "simplex" "" "" "22.5" "" "" "")
;
;
;
;
;
;DEFINED FUNCTION - CHOOSES STUFF FROM HYDRO PULLDOWN MENU PICKS AND SETS VARIABLES
(defun tbupdate ()
   (setq b1 (ssname sset1 0))
   (setq e1 (entnext b1) e2 (entnext e1) e3 (entnext e2)
         e4 (entnext e3) e5 (entnext e4) e6 (entnext e5)
         e7 (entnext e6) e8 (entnext e7) e9 (entnext e8)
         e10 (entnext e9) e11 (entnext e10) e12 (entnext e11)
         e13 (entnext e12) e14 (entnext e13) e15 (entnext e14)
         e16 (entnext e15) e17 (entnext e16) e18 (entnext e17)
         e19 (entnext e18) ep1 (entnext e19) ep2 (entnext ep1)
      )
;
;
   (setq fg (strlen (getvar "dwgname")))
   (setq fg2 (- fg 4))
   (setq ofile (substr (getvar "dwgname") 1 fg2))
;
;
   (setq nfile (entget e1))
      (setq nfile (subst (cons 1 ofile)(assoc 1 nfile)nfile))
      (entmod nfile)
   (setq nnam (entget e2))
      (setq nnam (subst (cons 1 nam)(assoc 1 nnam)nnam))
      (entmod nnam)
   (setq nmcode (entget ep2))
      (setq nmcode (subst (cons 1 mcode)(assoc 1 nmcode)nmcode))
      (entmod nmcode)
   (setq ndamloc (entget e7))
      (setq ndamloc (subst (cons 1 damloc)(assoc 1 ndamloc)ndamloc))
      (entmod ndamloc)
      (command "regen")
);defun
;
;
;;START VISUAL LISP
(vl-load-com)
(vla-startundomark (vla-Get-ActiveDocument (vlax-Get-Acad-Object)))
;
;
;;SET AUTOLISP SYMBOL ASSIGNMENTS
(setq asize "A")
(setq bsize "B")
(setq csize "C")
(setq dsize "D")
(setq esize "E")
(setq style "HYDRO-DEC-DIM")
(setq p1 "0,0")
;
;
;;FREEZE UNNEEDED LAYERS
(command "layer" "s" "scale" "f" "*" "")
;
;
;;FIND SOLIDWORKS SCALE-OBJECT
(setq ss1 (ssget "_X" '((8 . "SCALE")(0 . "MTEXT")(1 . "SCALE:*"))))
;
;
;;CHANGE SCALE-OBJECT TO REPLACE UNNEEDED DATA WITH NOTHING AND GET REMAINING DATA
(setq patt "SCALE: 1:")
(setq newpatt "")
(setq count -1)
(while (< (setq count (1+ count))(sslength ss1))
   (setq ent1 (entget (ssname ss1 count))
         obj1 (vlax-ename->vla-object (cdr (car ent1)))
         str1 (vla-get-textstring obj1))
   (while (setq match? (vl-string-search patt str1))
   (setq str1 (vl-string-subst newpatt patt str1))
   (vla-put-textstring obj1 str1)
   );while
);while
;
;
;;GET VALUE OF SCALE-OBJECT DATA
(setq scale str1)
;
;
;;DELETE SCALE-OBJECT
(vla-delete obj1)
;
;
;;FIND SOLIDWORKS TITLEBLOCK SIZE-OBJECT
(setq ss2 (ssget "_X" '((8 . "SCALE")(0 . "MTEXT"))))
(setq count2 -1)
(setq count2 (1+ count2))
(sslength ss2)
(setq ent2 (entget (ssname ss2 count2)))
(setq obj2 (vlax-ename->vla-object (cdr (car ent2))))
;
;
;;GET VALUE OF TB SIZE-OBJECT
(setq str2 (vla-get-textstring obj2))
;
;
;;DELETE TB SIZE-OBJECT
(vla-delete obj2)
;
;
;;MATCH VALUE OF TB SIZE-OBJECT TO CHOOSE AUTOCAD TITLEBLOCK SIZE AND SET POINT FOR SCALE-BAR INSERT
(if (eq asize str2)
(setq tb "HEDTBA" p5 (* (read str1) 3) p6 (* (read str1) 3.25)))
(if (eq bsize str2)
(setq tb "HEDTBB" p5 (* (read str1) 4.75) p6 (* (read str1) 0.5)))
(if (eq csize str2)
(setq tb "HEDTBC" p5 (* (read str1) 10.75) p6 (* (read str1) 0.5)))
(if (eq dsize str2)
(setq tb "HEDTBD" p5 (* (read str1) 21.75) p6 (* (read str1) 0.5) x1 (* (read str1) 25.5)))
(if (eq esize str2)
(setq tb "HEDTBE" p5 (* (read str1) 27.25) p6 (* (read str1) 0.5)))
;
;
;
;
;
;
;;INSERT, DELETE AND PURGE AUTOCAD TEMPLATE BLOCK TO GET DIMENSION STYLE
(command "insert" "template" "0,0" "" "" "")
(command "erase" "l" "")
(command "purge" "b" "template" "n")
;
;
;;THAW ALL LAYERS, SET LAYER 0 TO CURRENT AND ADD LAYER BASE
(command "layer" "t" "*" "s" "0" "n" "BASE" "")
;
;
;;CHANGE ALL SOLIDWORKS ENTITIES TO BASE LAYER
(command "change" "all" "" "p" "la" "BASE" "")
;
;
;;PURGE ALL UNUSED LAYERS
(command "purge" "la" "" "n")
;
;
;;SET "HYDRO-DIM-DEC" AS CURRENT DIMSTYLE, CHANGE DIMSCALE TO RETRIEVED SCALE VALUE & SAVE THE CHANGE TO "HYDRO-DIM-DEC"
(setq activedoc(vlax-get-property(vlax-get-acad-object)'activedocument))
(vlax-put-property activedoc 'ActiveDimStyle (vla-item(vla-get-dimstyles activedoc)style))
(setvar "dimscale" (read scale))
(command "dimstyle" "s" "HYDRO-DEC-DIM" "y")
;
;
;;SCALE SOLIDWORKS ENTITIES PER RETRIEVED SCALE VALUE
(command "scale" "all" "" "0,0" scale)
;
;
;;CHANGE ALL SOLIDWORKS DIMESIONS TO HYDRO DIMSTYLE
(command "dimstyle" "a" "all" "")
(command "zoom" "a" "zoom" "e" "zoom" "a")
;
;
;;MOVE SOLIDWORKS ENTITIES TO BASE POINT
(setq p2 (getvar "extmin"))
(setq p3 (list (* 0.5 (read scale))(* 0.5 (read scale))))
(command "move" "all" "" p2 p3)
;
;
;;PURGE UNUSED DIMENSION STYLES
(command "purge" "d" "" "n")
;
;
;;PURGE UNUSED TEXT STYLES
(command "purge" "st" "" "n")
;
;
;;SET OTHER AUTOCAD VARIABLES PER RETRIEVED SCALE VALUE
(setvar "ltscale" (read scale))
(setvar "dimscale" (read scale))
(setvar "textsize" (* 0.125 (read scale)))
;
;
;;INSERT SCALEBAR PER RETRIEVED SCALE VALUE
(SETQ bar (strcat str1 "BAR"))
(command "insert" bar (list p5 p6) 1 1 0)
;
;
;;PURGE
(command "purge" "a" "" "n")
;
;
;;INSERT THE MADE IN SOLIDWORKS BLOCK
(setq Y1 0)
(command "insert" "madeinsw" (list x1 y1) scale scale 0)
;
;
;;INSERT TITLEBLOCK PER RETRIEVED SCALE VALUE
(command "insert" tb "0,0" (read scale) "" "")
;
;
;;GETS HYDRO TITLEBLOCK AND PREPARES FOR THE DEFINED FUNCTION TO RUN
(setq sset1 (ssget "x" (list (cons 2 "hedtb*"))))
;
;
;;SET DWG LIMITS
(command "zoom" "a")
(setq p4 (getvar "extmax"))
(command "limits" p1 p4)
(command "zoom" "a")
;
;
;;RUNS THE DEFINED FUNCTION
(tbupdate)
;
;
;SET BASE LAYER TO CURRENT
(command "layer" "s" "base" "")
;
;
);progn
(setvar "cmdecho" 1)
(setvar "attdia" 1)
(setvar "attreq" 1)
(setvar "filedia" 1)
(setvar "lunits" 2)
(command "ddatte" "l")

BlackBox 发表于 2022-7-6 09:56:15

 
... 我偷偷地怀疑我的英雄会出现。
 

BlackBox 发表于 2022-7-6 09:58:19

这太可悲了-
我有35000张两座水电站的图纸
其中可能有1/5的内存在这些预定义的块中
如果我换块
我必须更新所有这些图纸(使用适当的比例尺)
 
对于本练习(将solidworks图形更新为AutoCAD标准)
我宁愿炸掉积木
抹掉所有碎片
然后重新插入
 

在那里插入一些设置每个比例可能性的代码
为了得到我想要的文本

TMORRIS 发表于 2022-7-6 10:02:15

8618。。。。。。。。。。。。。。
页: [1] 2
查看完整版本: 从中获取文本字符串的值