Hi,
I want to put all selected entities to BYLAYER (including nested blocks). I have made following LISP :-
(defun c:PutAllbyLayer ()
;; Puts All Entities Color, Lineweight and Linetype BYLAYER
;;
(defun getblockitems (e / o n blks blk enames)
;;Get all the block entities within a selected block
;;Does not get all the subobjects of all the nested blocks.
;;D.C. Broad, Jr. 2013
;;FORMAT: (GETBLOCKITEMS <INSERTENAME>)
;; Source : https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-acces-entities-within-a-block/td-p/4572545
(setq o (vlax-ename->vla-object e) ;insert object
n (vla-get-effectivename o) ;name
blks (vla-get-blocks (vla-get-document o)) ;block collection
blk (vla-item blks n) ;block of interest
)
;;build a list with the block definitions enames
(vlax-for n blk (setq enames (cons (vlax-vla-object->ename o) enames)))
(reverse enames) ;return list otherwise nil
)
(defun convertbylayer (ent / obj xx tmp)
(if (entget ent)
(progn (if (eq (cdr (assoc 0 (entget ent))) "INSERT")
(progn (if (setq tmp (getblockitems ent))
(mapcar (function (lambda (xx) (convertbylayer xx))) tmp)
)
)
(progn (setq obj (vlax-ename->vla-object ent))
(vla-put-color obj acByLayer)
(vla-put-lineweight obj acLnWtByLayer)
(vla-put-linetype obj "BYLAYER")
)
)
)
)
)
(vl-load-com)
(setq ss (ssget "_:L"))
(repeat (setq n (sslength ss))
(setq ent (ssname ss (setq n (1- n))))
(convertbylayer ent)
)
(princ)
)
but every time I run it, AutoCAD crashes and I get following error :-