TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Lonnie on May 15, 2023, 12:02:11 PM

Title: Cleanup lsp fails when no solids are found.
Post by: Lonnie on May 15, 2023, 12:02:11 PM
I am hoping someone can tell me how to do this without the lisp asking for the objects multiple times.

This lisp does a couple of things in this order.

1. Selects all SOLID entities in the drawing and erases all the selected entities

2. Changes the color property of all entities left behind (after step 2) to BYLAYER, using the AutoCAD command "CHPROP".

3. Moves all entities left behind (after step 3) to a layer named "g-heavy", using the function "c:g-heavy".

4. Performs an "overkill" operation on all entities

Code: [Select]
;; DESCRIPTION
;;;
;;; Clean up exl2dwg
;;; Kills the solids, moves everything to the g-heavy layer
;;; Does an overkill
;;;
;;;Lonnie Shaw
;;; 2023/05/12
;;; ---------------------------- Main program --------------------------------;

(defun c:exl ()
  (setq ss (ssget "_X" '((0 . "SOLID"))))
  (if ss
    (progn
      (command ".erase" ss "")
      (if (/= (sslength ss) 0)
        (progn
          (command "CHPROP"
                   ss
                   ""
                   "_C"
                   "BYLAYER"
                   ""
                   )
          (c:g-heavy)
          (command "-overkill" ss "" "")
;          (princ (strcat "\n" (itoa (sslength ss)) " entities remaining."))
        )
)
    )
    (princ "\nNothing selected.")
  )
)


Thanks in advance.
Lonnie
Title: Re: Cleanup lsp fails when no solids are found.
Post by: JohnK on May 15, 2023, 12:41:46 PM
As far as I can tell, that shouldnt ask you to select at all. Is there something in the G-HEAVY subroutine that we dont know about?

Here is some code to color *everything* bylayer (instead of just the SS). This is only posted here just in case you wanted *everything* instead of just the SS.
Code - Auto/Visual Lisp: [Select]
  1. (defun colorByLayer (/ ss i elist)
  2.   (setq i -1)
  3.   (repeat
  4.     (sslength (setq ss (ssget "x" '((-4 . "/=") (62 . 256)))))
  5.      (entmod
  6.        (subst '(62 . 256) (assoc 62 (setq elist (entget (ssname ss (setq i (1+ i)))))) elist))
  7.   )
  8.   (princ)
  9. )
  10.  
Title: Re: Cleanup lsp fails when no solids are found.
Post by: Lonnie on May 17, 2023, 12:46:49 PM
This is what I ended up with.

Code: [Select]
(defun c:exl (prev_ss)
  (c:g-heavy)
  (setq prev_ss (ssget "_X"))
  (command "chprop" prev_ss "" "c" "bylayer" "") ; Change properties of selection to by layer
  (command "overkill" prev_ss "") ; Run Overkill on the selection set
  (setq solids (ssget "_X" '((0 . "SOLID")))) ; Select all solids
  (command "erase" solids "") ; Erase all selected solids
  (princ)
)


Title: Re: Cleanup lsp fails when no solids are found.
Post by: JohnK on May 17, 2023, 02:54:28 PM
Small change on the first line.
(defun c:exl ( / prev_ss)

Add the slash.