Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

modifying blocks

6 REPLIES 6
Reply
Message 1 of 7
elise_moss
238 Views, 6 Replies

modifying blocks

I have about 500 blocks in my drawing that were inserted. For some reason, the block was defined with an attribute set to a color...I want the attribute set to "bylayer". It is annoying to go thru the drawing using EATTEDIT picking each block, so I tried to write a lisp routine to automate it.

The code doesn't work...I get a dxf error and can't figure out why.

suggestions on how to manage this are appreciated... I also tried selecting all the blocks, but since the attributes are nested, it didn't work. I tried editing the block and redefining it, but that didn't work either.


begin code here------------------------
(defun c:chatt ()
(setq bname (getstring "\nEnter block name to change: "))
(setq ss (ssget "x" (list (cons 0 "INSERT"))))
(setq counter 0)
(setq sslen (sslength ss))
(while (< counter sslen)
(setq ssent (ssname ss counter))
(setq ent-list (entget ssent))
; get block name
(setq entbname (cdr (assoc 2 ent-list)))
(if (= entbname bname)
(progn
(setq ent-att (entnext ssent))
(setq att-list (entget ent-att))
(setq att-list (subst (cons 62 "BYLAYER") (assoc 62 att-list) att-list))
(entupd ent-list)
);end progn
)
(setq counter (+ counter 1))

);end while


); end defun

;;code ends here--------------------------------
6 REPLIES 6
Message 2 of 7
Anonymous
in reply to: elise_moss

This one changes the layer of the attribute to match the layer the block is inserted on, but you can change it.

Tim

(defun c:abl(/ bset1 blng1 ba1 bl1 ba2 ba3 go1 bl2 ba5)
; Changes attributes to match the layer of the block

(command "undo" "group")

(prompt "\nSelect blocks with attributes to match layers: ")
(setq bset1 (ssget '((0 . "INSERT") (66 . 1))))
(if (= bset1 nil)
(setq blng1 0)
(setq blng1 (sslength bset1))
)


(while (/= blng1 0)
(setq ba1 (entget (ssname bset1 0)))
(setq bl1 (assoc 8 ba1))
(setq ba2 (cdr (assoc -1 ba1)))
(setq ba3 ba1)
(setq go1 nil)
(while (/= go1 "stop")
(setq ba3 (entget (entnext (cdr (assoc -1 ba3)))))
(setq ba4 (assoc 0 ba3))
(cond
((equal ba4 (cons 0 "ATTRIB"))
(setq bl2 (assoc 8 ba3))
(setq ba5 (subst bl1 bl2 ba3))
(entmod ba5)
(entupd ba2)
(setq ba5 (subst (cons 62 0) (assoc 62 ba3) ba5))
(entmod ba5)
(entupd ba2)
)
((equal ba4 (cons 0 "SEQEND"))
(ssdel ba2 bset1)
(setq blng1 (1- blng1))
(setq go1 "stop")
)
)
)
)

(command "undo" "end")
(princ)

)
Message 3 of 7
elise_moss
in reply to: elise_moss

Worked great!

Thanks a bunch!

Elise Moss
Message 4 of 7
Anonymous
in reply to: elise_moss

You're welcome. Glad it suits your needs.

Tim
Message 5 of 7
Anonymous
in reply to: elise_moss

Won't BATTMAN work?


wrote in message news:4835016@discussion.autodesk.com...
I have about 500 blocks in my drawing that were inserted. For some reason,
the block was defined with an attribute set to a color...I want the
attribute set to "bylayer". It is annoying to go thru the drawing using
EATTEDIT picking each block, so I tried to write a lisp routine to automate
it.

The code doesn't work...I get a dxf error and can't figure out why.

suggestions on how to manage this are appreciated... I also tried selecting
all the blocks, but since the attributes are nested, it didn't work. I
tried editing the block and redefining it, but that didn't work either.


begin code here------------------------
(defun c:chatt ()
(setq bname (getstring "\nEnter block name to change: "))
(setq ss (ssget "x" (list (cons 0 "INSERT"))))
(setq counter 0)
(setq sslen (sslength ss))
(while (< counter sslen)
(setq ssent (ssname ss counter))
(setq ent-list (entget ssent))
; get block name
(setq entbname (cdr (assoc 2 ent-list)))
(if (= entbname bname)
(progn
(setq ent-att (entnext ssent))
(setq att-list (entget ent-att))
(setq att-list (subst (cons 62 "BYLAYER") (assoc 62 att-list) att-list))
(entupd ent-list)
);end progn
)
(setq counter (+ counter 1))

);end while


); end defun

;;code ends here--------------------------------
Message 6 of 7
elise_moss
in reply to: elise_moss

only on individual blocks...not to redefine all the insertions...I tried it.
Message 7 of 7
Anonymous
in reply to: elise_moss

Here is another way that will do it.


(if (setq ss (ssget "x" '((0 . "INSERT") (66 . 1))))
(progn
(setq i 0)
(repeat (sslength ss)
(setq ename (ssname ss i))
(if (setq lst (nEnts ename "ATTRIB"))
(foreach item lst
(vla-put-color (vlax-ename->vla-object item) 256)
)
)
(setq i (1+ i))
)
)
)

; Jason Piercey . June 2nd, 2003
; get list of sub entity names
; [ename] - entity name or vla-object - block, insert or polyline
; [filter] - string, re: wcmatch()
; return: list of enames or nil
; revised: July 10th, 2003 - accepts ename or vla-object
(defun nEnts (ename filter / data ent rtn)
(or (= 'ename (type ename))
(setq ename (vlax-vla-object->ename ename)) )
(setq filter (strcase filter))
(while (and ename (setq ename (entnext ename)))
(setq data (entget ename))
(setq ent (cdr (assoc 0 data)))
(if (wcmatch ent filter)
(setq rtn (cons ename rtn)) )
(if (= "SEQEND" ent) (setq ename nil))
)
(reverse rtn)
)

--
Autodesk Discussion Group Facilitator



wrote in message news:4835016@discussion.autodesk.com...
I have about 500 blocks in my drawing that were inserted. For some reason,
the block was defined with an attribute set to a color...I want the
attribute set to "bylayer". It is annoying to go thru the drawing using
EATTEDIT picking each block, so I tried to write a lisp routine to automate
it.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost