Jump to content

LISP - Do routine if specific text is found in a specific block attribute


h0okem

Recommended Posts

I have a routine that replaces one block with another block based on the block name. I need help making it run only if a specific string of text is found in one of the attributes within the found block.

Can someone help? Thanks.

(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...")
     )
   )
     )
   )
 )
)

Edited by h0okem
Link to comment
Share on other sites

My version ... :)

 

(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)
)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...