TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: chilldaddy on March 19, 2024, 09:38:01 AM

Title: Automate All to Zero and With Existing Entity Properties: How-to Needed
Post by: chilldaddy on March 19, 2024, 09:38:01 AM
Goal:
Find methods to help assemble a new LISP program or find an existing LISP program to perform the  following:
Convert all entities to layer zero while maintaining properties as originally assigned based on the entities' original layer.
In a single DWG file, 700+/- details are organized and include drawing borders that supply individual details to our main non-Autodesk specialized and multi-functional design application.

Please provide:
Links to and/or actual LISP programs that perform this or similar conversions.
LISP tips and/or instruction on links to methods to create a conversion LISP program.
Non-programmed methods to accomplish this conversion. 

Skill level:
Almost a LISP Beginner
Title: Re: Automate All to Zero and With Existing Entity Properties: How-to Needed
Post by: ribarm on March 19, 2024, 10:05:00 AM
If you have Autocad 2007+, then this should work, since "copytolayer" command was introduced at that release...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:moveto0layer ( / ss )
  2.   (prompt "\nSelect objects to move to 0 Layer...")
  3.   (if (setq ss (ssget "_:L"))
  4.     (progn
  5.       (if command-s
  6.         (command-s "_.-copytolayer" ss "" "0" "")
  7.         (vl-cmdf "_.-copytolayer" ss "" "0" "")
  8.       )
  9.       (if command-s
  10.         (command-s "_.erase" ss "")
  11.         (vl-cmdf "_.erase" ss "")
  12.       )
  13.       ;;; if you want to keep source layer(s) don't remove ;| and |; , but if you want them purged - erased, remove ;| and |; ...
  14.       ;|
  15.       (if command-s
  16.         (command-s "_.-purge" "_la" "*" "_n")
  17.         (vl-cmdf "_.-purge" "_la" "*" "_n")
  18.       )
  19.       |;
  20.     )
  21.   )
  22.   (princ)
  23. )
  24.  

M.R.
Title: Re: Automate All to Zero and With Existing Entity Properties: How-to Needed
Post by: ribarm on March 19, 2024, 11:56:33 AM
Another one in pure AutoLISP...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:moveto0layer ( / ss i e ex )
  2.   (prompt "\nSelect objects to move to 0 Layer...")
  3.   (if (setq ss (ssget "_:L"))
  4.     (repeat (setq i (sslength ss))
  5.       (setq e (ssname ss (setq i (1- i))))
  6.       (setq ex (entget e))
  7.       (entupd (cdr (assoc -1 (entmod (subst (cons 8 "0") (assoc 8 ex) ex)))))
  8.     )
  9.   )
  10.   (princ)
  11. )
  12.  
Title: Re: Automate All to Zero and With Existing Entity Properties: How-to Needed
Post by: chilldaddy on March 19, 2024, 12:13:56 PM
Ah yes, "ribarm"!

We run the latest version. Both of your generous contributions and the descriptions provided are very helpful and educated me, saving my company tons of processing time and expense.

Thanks a million!