Add Counter to Lisp

Add Counter to Lisp

matt_sibum
Participant Participant
1,550 Views
3 Replies
Message 1 of 4

Add Counter to Lisp

matt_sibum
Participant
Participant

Hi All, 

 

I have a lisp I wrote which lets me use a selection window to list all the layers in a selected area of my drawing. A quick way for me to see if all the layers in a particular area are correct. One modification I would like is to add a counter behind each layer stating how many objects on each layer (e.g. "defpoints (10)") if there are 10 objects on the defpoints layer.

 

Not sure how complicated it would be to modify my code, or if I would need to rewrite the code to allow this functionality. Any help would be much appreciated.

(defun C:lli (/ ss n1 loop laylist isolayers layer n2 numlist stringlist listex)

(princ "\nSelect objects to list used layers...")

(if 
(setq ss (ssget))
(progn
(setq n1 (sslength ss))
(setq loop 0)
(setq laylist ())
(setq isolayers ())

(textscr)

(progn
	(repeat n1
			(setq layer (cdr (assoc 8 (entget (ssname ss loop)))))
			(if (not (member layer laylist)) (setq laylist (cons layer laylist)))
			(setq loop (1+ loop))
	)
	(setq laylist (acad_strlsort laylist))
)

(setq mylist laylist)

(setq n2 (length laylist))
(setq numlist 0)

(setq stringlist "\nSelected Layers...\n")

(progn
	(repeat n2
			(setq listext (nth numlist laylist))
			(setq stringlist (strcat stringlist "\n    " listext))
			(setq numlist (1+ numlist))
	)
)

(princ stringlist)

);	END PROGN 

(princ "\nNo Entities Selected..")

);	END IF

(princ)	
	
)

Thanks, 

Matt

 

 

0 Likes
Accepted solutions (1)
1,551 Views
3 Replies
Replies (3)
Message 2 of 4

ВeekeeCZ
Consultant
Consultant

Here is an example of the algorithm. Point is to get list structured like this:

'((layername1 . mount1)
  (layername2 . mount2)
  (layername3 . mount3)
....)

 

(setq laylst (if (setq a (assoc (setq lay (cdr (assoc 8 (entget en)))) laylst))
               (subst (cons lay (1+ (cdr a)))
                      a
                      laylst)
               (cons (cons lay 1) laylst)))

I guess you're skilled enough to add inter-corporate it into your code... 😉

0 Likes
Message 3 of 4

marko_ribar
Advisor
Advisor
Accepted solution

Hi, here is quick mod of your code...

HTH., M.R.

 

(defun c:lli ( / ss n1 loop laylist layer n2 numlist stringlist listex ) ; mylist is global variable
  (princ "\nSelect objects to list used layers...")
  (if (setq ss (ssget))
    (progn
      (setq n1 (sslength ss))
      (setq loop 0)
      (textscr)
      (repeat n1
        (setq layer (cdr (assoc 8 (entget (ssname ss loop)))))
        (if (not (member layer laylist))
          (setq laylist (cons layer laylist))
        )
        (setq loop (1+ loop))
      )
      (setq laylist (acad_strlsort laylist))
      (setq mylist laylist)
      (setq n2 (length laylist))
      (setq numlist 0)
      (setq stringlist "\nSelected Layers...\n")
      (repeat n2
        (sssetfirst nil ss)
        (setq listext (nth numlist laylist))
        (setq listext (strcat listext "(" (itoa (sslength (ssget "_I" (list (cons 8 listext))))) ")"))
        (setq stringlist (strcat stringlist "\n    " listext))
        (setq numlist (1+ numlist))
      )
      (princ stringlist)
      (sssetfirst nil nil)
    )
    (princ "\nNo Entities Selected...")
  )
  (princ)	
)
Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 4 of 4

matt_sibum
Participant
Participant

Thanks marko_ribar, works perfectly. 

 

Much appreciated.