Help :) with Changing fields objectID on attributes contained on MTEXT in Layout.

Help :) with Changing fields objectID on attributes contained on MTEXT in Layout.

amirbSPDJQ
Contributor Contributor
199 Views
1 Reply
Message 1 of 2

Help :) with Changing fields objectID on attributes contained on MTEXT in Layout.

amirbSPDJQ
Contributor
Contributor

Hello, i am taking so long time to change the object id of the fields where i have some attributes because i have to pick each field one by one, select the object and the attribute.

 

I need help, i need a lisp to change the object id of 3 different attributes contained in an Mtext in my layout.

 

Context: I have terminals in my model space, each terminal has terminal size, address and PON attributes, in my layout i have to list these attributes in an Mtext, per terminal, for the first one i did it by hand, and now i would like to change the object id so i just run a lisp , select the terminal2 , terminal 3 and change the attributes values automatically.

 

Anyone could help me with this? Here a sample file: 

0 Likes
200 Views
1 Reply
Reply (1)
Message 2 of 2

ВeekeeCZ
Consultant
Consultant

Try this. I don't understand your suggested workflow -- Hopefully, mine is good enough.

You can update fields one by one, or select multiple sources and multiple targets. Just mind the order if matters.

 

(vl-load-com)

(defun c:FUTerm ( / :repIDs s d i e o l)

(defun :repIDs (str lst / b e) ; lst = list of string IDs in order to replace
  (if (and (car lst)
	   (setq b (vl-string-search "ObjId" str))
	   (setq e (vl-string-position (ascii ">") str b))
	   )
    (strcat (substr str 1 (+ b 6)) (car lst) (:repIDs (substr str (1+ e)) (cdr lst)))
    str))

  (if (and (princ "\nSource Terminal blocks, ")
	   (setq s (ssget '((0 . "INSERT") (66 . 1))))
	   (setq s (vl-remove-if '(lambda (x) (/= "TERMINAL" (getpropertyvalue x "BlockTableRecord/Name"))) (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))))
	   (vl-cmdf "_.pspace")
	   (princ "\nDestination Mtexts,  ")
	   (setq d (ssget '((0 . "MTEXT"))))
	   )
    (repeat (setq i (length s))
      (and (setq e (nth (setq i (1- i)) s))				; source ename
	   (setq o (vlax-ename->vla-object (ssname d i)))		; dest obj
	   (setq l (mapcar 'itoa (mapcar 'vla-get-objectid (mapcar 'vlax-ename->vla-object (list e (entnext e) (entnext (entnext e)))))))  ; '(blk 1st-att 2nd-att)
	   (vla-put-textstring o (:repIDs (vla-fieldcode o) l))
	   )))
	   
  (vla-regen (vla-get-ActiveDocument (vlax-get-acad-object)) acActiveViewport)
  (princ)
  )

 

0 Likes