Jump to content

LISP Code to Select Block in Layouts and Update Attributes


Bill Tillman

Recommended Posts

This may be an alternative method the idea is it will work with any block in a layout has no limit on the number of atts updated 1 -> all. Rather than use tag name uses attribute creation order.

 

It is written to read a file input as that wa sthe original post request but could be changed for a more user version when making the paired list of attribute order and new value. Either as a dcl entry I am pretty sure I have that.

 

(ah:blockupdater lst) where lst is ((1 "BT Group LLC")(2 "Job Name")( 3 "BT") ( 12 "9/13/17")) etc

 

 

; a universal block attribute updater allows for input from file.
; By Alan H 2017
(defun ah:blockupdater ( / newline bname )
(setq fo (open "c:\\temp\\blkupdate.txt" "R"))
(setq 1stline  (read-line fo) ) ; 1st line Model or Layouts
(setq bname  (read-line fo) ) ; block name

; make a list of pairs position and new variable
(setq lst '() )
(while (setq newline (read-line fo)) 
(setq x (vl-string-search "," newline))
(setq pos (substr newline 1  x))
(setq newval (substr newline (+ x 2)))
(setq lst (cons pos lst))
(setq lst (cons newval lst))
)
(setq lst (reverse lst))
(close fo)

; other criteria ?
(cond ((= "MODEL" (strcase 1stline)(do-model-blocks))
            ((= "LAYOUTS" (strcase 1stline))(do-layout-blocks))
)
) ;defun

(defun do-model-blocks ( / ss)
(setvar 'ctab "Model")
(setq ss (ssget "x"  (list (cons 0 "INSERT") (cons 2 bname)(cons 410 "Model"))))
(ah:attup)
)

(defun do-layout-blocks ( / doc lay plotabs len tabname x y z ss)

(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(vlax-for lay (vla-get-Layouts doc)
(setq plotabs (cons (vla-get-name lay) plotabs))
)

(repeat (length plotabs)
(setq tabname (nth x plotabs))
(if (/= tabname "Model")
(progn
(setvar "ctab" tabname)
(setq ss (ssget "x"  (list (cons 0 "INSERT") (cons 2 bname)(cons 410 tabname))))
(ah:attup)
)
)
)
)

(defun ah:attup ( / x y z)
(repeat (setq x (sslength ss))
(setq obj (vlax-ename->vla-object (ssname  ss (setq x (- x 1))) ) )
(setq atts (vlax-invoke obj  'getattributes))
(setq z 0)

(repeat (setq y (/ (length lst ) 2 ))
(vla-put-textstring (nth  (atoi (nth z lst)) atts)  (nth (+ z 1) lst))
(setq z (+ z 2))
)

)

)  

(princ)      
(ah:blockupdater)

file data

Layouts
Myblockname
1,alan
4,FRED
6,asdf

Edited by BIGAL
Link to comment
Share on other sites

  • Replies 20
  • Created
  • Last Reply

Top Posters In This Topic

  • Bill Tillman

    9

  • Tharwat

    7

  • BIGAL

    3

  • ronjonp

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