h0okem 发表于 2022-7-6 08:40:04

LISP-如果特定,则执行例程

我有一个例程,根据块名用另一个块替换一个块。我需要帮助,使其仅在找到的块中的一个属性中找到特定的文本字符串时运行。
有人能帮忙吗?谢谢

(defun c:name ()
(setvar "attreq" 0)
(setq ssblocks (ssget "x" '((0 . "INSERT"))))
(if ssblocks
   (progn
   (setq lstblockmap
      (txtfile2lst
          "C:\\path\\filename.txt"
      )
   )
   (setq lstblocks (sel2lst ssblocks))
   (foreach enblock lstblocks
   (setq strblockname
          (car
      (getval (setq stroldname (strcase (getval 2 enblock)))
            lstblockmap
      )
          )
   )
   (if strblockname
   (progn
       (prompt (strcat "****** " strblockname " found.******"))
       (progn
;;;;;Do more code
       )   
   )
   (progn
       (prompt "No block definition, Skipping...")
   )
   )
   )
   )
)
)

LibertyOne 发表于 2022-7-6 09:15:51

我们都被指示,在我们帮助你之前,你必须阅读这篇文章。。。
 
http://www.cadtutor.net/forum/showthread.php?9184-代码发布指南

pBe 发表于 2022-7-6 09:20:31

(if(成员str(attb字符串检索子的结果))
(做你的事)
(msg)
)

Tharwat 发表于 2022-7-6 09:48:04

我的版本。。。
 

(defun c:TesT (/ blks b found st i sn n e)
;;; Tharwat 19. Nov. 2011 ;;;
(if
   (and
   (setq blks (ssget "_x" '((0 . "INSERT") (66 . 1))))
   (setq b (getstring t "\n Enter Name of Block to be replaced :"))
   (setq found (tblsearch "BLOCK" b))
   (setq st (getstring t "\n Enter Attribute string :"))
   )
    (repeat (setq i (sslength blks))
      (setq sn (ssname blks (setq i (1- i))))
      (setq n (entnext sn))
      (while
      (not
          (eq (cdr (assoc 0 (setq e (entget n))))
            "SEQEND"
          )
      )
         (if (and (eq (cdr (assoc 0 e)) "ATTRIB")
                  (eq (cdr (assoc 1 e)) st)
             )
         (progn (entmakex (list '(0 . "INSERT")
                                  (assoc 10 (entget sn))
                                  (cons 2 b)
                                  '(41 . 1.)
                                  '(42 . 1.)
                                  '(43 . 1.)
                            )
                  )
                  (entdel sn)
         )
         )
         (setq n (entnext n))
      )
    )
    (cond (
         (not blks)
         (princ
             "\n You do not have Attributed Blocks in this drawing !!"
         )
          )
          (
         (not found)
         (princ "\n Name of block is not found in this drawing !!")
          )
    )
)
(princ)
)
页: [1]
查看完整版本: LISP-如果特定,则执行例程