Jump to content

Update attribute of block baed upon nearby text outside of block


Organic

Recommended Posts

I tried searching this forum and theswamp without much success. What I am trying to find is a lisp which will update the existing attribute of a block by taking the value of a piece of mtext which is situated over the block (although outside of the block).

 

E.g. attachment.php?attachmentid=56189&cid=1&stc=1

 

The circle is a block and has a text attribute within it, The '182' is mtext on a specific layer and is not part of the block, it is located outside of the block although it on top of the block/within the border extents of the block. I am looking to update the attribute within the block to be '182'.

 

There are several hundread instances of this circular block which each require their attribute changed based upon the mtext sitting on top of them. I've found plenty of lisps online regarding converting text to attributes although not much on updating existing block attributes based upon a nearby object (in this case text on a known layer near the basepoint of the block); is this even possible?

 

Edit: based* typo in the thread title sorry

circle.png

Link to comment
Share on other sites

Hi,

 

You can make a selection set of the attributed blocks then iterate through each block and get its bounding box , then if Mtext objects is found , replace the text string of the attribute text string with Mtext string that is in the block.

Link to comment
Share on other sites

Try this draft:

 

(defun c:test (/ ss i obj j k mt)
 ;; Tharwat 23.11.2015    ;;
 (if (setq ss (ssget "_:L" '((0 . "INSERT") (66 . 1))))
   (repeat (setq i (sslength ss))
     (setq obj (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
     (vla-getboundingbox obj 'j 'k)
     (if (setq mt (ssget "_W"
                         (vlax-safearray->list k)
                         (vlax-safearray->list j)
                         '((0 . "MTEXT"))
                  )
         )
       (vla-put-textstring (car (vlax-invoke obj 'getattributes))
         (cdr (assoc 1 (entget (ssname mt 0))))
       )
     )
   )
 )
 (princ)
)(vl-load-com)

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...