TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: mailmaverick on December 11, 2017, 02:03:27 AM

Title: Put All Entities Within a Block ByLayer
Post by: mailmaverick 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 :-
Title: Re: Put All Entities Within a Block ByLayer
Post by: kpblc 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.
Title: Re: Put All Entities Within a Block ByLayer
Post by: Marc'Antonio Alessi on December 11, 2017, 07:55:16 AM
maybe this can help: https://www.theswamp.org/index.php?topic=53683.0