Author Topic: Put All Entities Within a Block ByLayer  (Read 1628 times)

0 Members and 1 Guest are viewing this topic.

mailmaverick

  • Bull Frog
  • Posts: 494
Put All Entities Within a Block ByLayer
« on: December 11, 2017, 02:03:27 AM »
Hi,
I want to put all selected entities to BYLAYER (including nested blocks). I have made following LISP :-
Code: [Select]
(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 :-

kpblc

  • Bull Frog
  • Posts: 396
Re: Put All Entities Within a Block ByLayer
« Reply #1 on: December 11, 2017, 03:08:13 AM »
Try to audit dwg. And some times I saw blocks named with UTF-symbols. LISP doesn't understand these symbols, so LISP can'f find the block definition. It was another problem source.
Sorry for my English.