Jump to content

Looking for lisp to Copy Multiple Text Value to Multiple Blocks


Recommended Posts

Posted

Hi Lisp guru's,

 

im looking for help or lisp to copy text/ mtext value to attribute as shown below,  by selection set or something, the goal is not to pick each and pick again where should it go.

Thanks.

image.thumb.png.fae0adbc298de24a3f80f10f656b9c47.png

copy.dwg

Posted

This is just a find text one selection set and look for a block within a defined search area and update attribute, search here or a google its been answered numerous times.

Posted (edited)

If you use a window selection and do it twice using the two corner pick points, ssget all the text, ssget all the blocks.


(setq pt1 (getpoint "pick 1st corner"))

(setq pt2 (getpoint pt1 "pick other corner"))

(setq txtss (ssget "w" pt1 pt2 (list (cons 0 "Text"))))

(setq blkss (ssget "w" pt1 pt2 (list (cons 0 "Insert"))))

Edited by BIGAL
Posted

Hi Bigal thanks for this but i dont have idea how to use it :( 

Posted (edited)

Here is a solution based on code I have created for another thread.

Note: You have to remove mtext formatting first. This can be done by exploding mtexts or by using StripMtext.

(defun KGA_Conv_Pickset_To_ObjectList (ss / i ret)
  (if ss
    (repeat (setq i (sslength ss))
      (setq ret (cons (vlax-ename->vla-object (ssname ss (setq i (1- i)))) ret))
    )
  )
)

(defun KGA_Geom_ObjectMiddle (obj / ptBL ptTR)
  (vla-getboundingbox obj 'ptBL 'ptTR)
  (mapcar
    '/
    (mapcar '+ (vlax-safearray->list ptBL) (vlax-safearray->list ptTR))
    '(2.0 2.0 2.0)
  )
)

(defun c:Test ( / disVec doc blkLst pt tab txtLst)
  (setq disVec '(38.8751 25.4295)) ; Half of diagonal.
  (setq tab (if (= 1 (getvar 'cvport)) (getvar 'ctab) "Model"))
  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (vla-endundomark doc)
  (vla-startundomark doc)
  (if
    (and
      (setq blkLst
        (KGA_Conv_Pickset_To_ObjectList
          (ssget "_A" (list (cons 410 tab) '(0 . "INSERT") '(2 . "BOX")))
        )
      )
      (setq txtLst
        (KGA_Conv_Pickset_To_ObjectList
          (ssget "_A" (list (cons 410 tab) '(0 . "*TEXT") '(1 . "*BOX*")))
        )
      )
    )
    (progn
      ; Note: texts have an elevation.
      (setq txtLst
        (mapcar
          '(lambda (obj) (list (KGA_Geom_ObjectMiddle obj) obj))
           txtLst
        )
      )
      (foreach blk blkLst
        (setq pt (KGA_Geom_ObjectMiddle blk))
        (vl-some
          '(lambda (txtSub)
            (if (vl-every '> disVec (mapcar 'abs (mapcar '- pt (car txtSub))))
              (progn
                (vla-put-textstring (car (vlax-invoke blk 'getattributes)) (vla-get-textstring (cadr txtSub)))
                (vla-delete (cadr txtSub))
                (setq txtLst (vl-remove txtSub txtLst))
                T
              )
            )
          )
          txtLst
        )
      )
      (princ "\nDone! ")
    )
  )
  (vla-endundomark doc)
  (princ)
)

 

Edited by Roy_043
Posted

thanks Roy, but unfortunately nothing happened when i test it. Cheers

copytexttoattribute.gif

Posted

Your new test dwg is quite different. Please test with your original copy.dwg. And then explain...

Posted

ah right! so it's reading the block name?

and if it's different block i'll just match the block name...Thank you very much.

(ssget "_A" (list (cons 410 tab) '(0 . "INSERT") '(2 . "BOX")))
Posted

My code assumes a fixed "BOX" block and that the rotation angle of the references is 0. As per your first example.

  • Like 1

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