Jump to content

Recommended Posts

Posted

hello:

I would like to know if there is any LSP routine that helps me define the definition of attributes

like similar to Tcount from  master LEE MAC .

Here I attach an example dwg of the entities that I need to quantify

 

thanks

 

example.dwg

Posted

I have something that would have done what you want, but it looks for blocks with attributes, I personally only ever make blocks with say a single attribute.

 

Complicating it even more the display is the tag names. It's not a very nice dwg.

 

lastly the answer is in lst3 but you have not said what you want done with it.

 

; count attdefs via tagname
; BY AlanH July 2025

(defun c:wow ( / lst lst2 att cnt lst3)

(defun my-count (a L)
  (cond
   ((null L) 0)
   ((equal a (car L)) (+ 1 (my-count a (cdr L))))
   (t (my-count a (cdr L))))
)

; By Gile
(defun remove_doubles (lst)
  (if lst
    (cons (car lst) (remove_doubles (vl-remove (car lst) lst)))
  )
)

(setq ss (ssget '((0 . "ATTDEF"))))
(setq lst '())
(repeat (setq x (sslength ss))
  (setq att (vlax-ename->vla-object (ssname ss (setq x (1- x)))))
  (setq lst (cons (vlax-get att 'tagstring) lst))
)
(setq lst (acad_strlsort lst))

(setq lst2 (remove_doubles lst))
(foreach val lst2
  (setq cnt (my-count val lst))
  (setq lst3 (cons (list val cnt) lst3))
)

(princ)
)

 

  • Thanks 1
Posted

thanks for the contribution master

There is a routine that I use for texts and it helps me know what number is missing in a series of numbers.

A similar one would help me a lot but for "ATTDEF" because I receive drawings in which other people number pieces, sometimes with texts and sometimes with "ATTDEF"

So I need to do an audit to know the amount of "ATTDEF", which number is missing and how many times each tag is repeated. :)

here code master...

(defun nqf (tuSS / i lista)
(princ "\nNumero que falta")
(terpri)
(setq cant (sslength tuSS))
(princ "\nCantidad de textos seleccionados = ")
(princ cant)
(princ "\nLista de numeros faltantes")
;Pasar del SS a una lista de valores
   (setq i 0)
   (repeat (sslength tuSS)
      (setq lista (cons (atoi (cdr (assoc 1 (entget (ssname tuSS i))))) lista)
           i (1+ i))
   )
;Imprimir los valores que no aparezcan
   (setq lista (vl-sort lista '< )
        i 1
   )

   (repeat (last lista)
      (if (null (member i lista))(princ (strcat "\nFalta el # " (itoa i))))
      (setq i (1+ i))

   )


(princ "\nLista de numeros existentes")
(terpri)
(princ lista)
(terpri)
   (textscr)
)

(defun c:nqf nil (nqf (ssget '((0 . "TEXT")))))

 

thanks

 

Posted

Try

;BACALADODEBILBADO.noes
(defun nqf (tuSS / i lista tipObj cad)
  (princ "\nNumero que falta")
  (terpri)
  (setq cant (sslength tuSS))
  (princ "\nCantidad de textos seleccionados = ")
  (princ cant)
  (princ "\nLista de numeros faltantes")
					;Pasar del SS a una lista de valores
  (setq i 0)
  (repeat (sslength tuSS)
    (setq tipObj (cdr (assoc 0 (setq le (entget (ssname tuSS i)))))
	  num (atoi (cdr (assoc (if (= tipObj "TEXT") 1 2) le)))
	  i	(1+ i)
	  lista (if (setq l (assoc num lista))
		  (subst (list num (1+ (cadr l))) l lista)
		  (append lista (list (list num 1)))
		)
    )
  )
					;Imprimir los valores que no aparezcan
  (terpri)
  (setq i 1)
  (princ
    (strcat "\nLista de numeros existentes\n"
	    (while lista
	      (if (setq v (assoc i lista))
		(setq cad (if (= (cadr v) 1)
			    (if	cad
			      (strcat cad ", " (itoa (car v)))
			      (itoa (car v))
			    )
			    (if cad
			      (strcat cad ", " (itoa (car v)) "(" (itoa (cadr v)) ")")
			      (itoa (car v))
			    )
	                  )
		      lista (vl-remove v lista)
		)
		(princ (strcat "\nFalta el # " (itoa i)))
	      )
	      (setq i (1+ i))
	      cad
	    )
    )
  ) 
  (princ)
)

(defun c:nqf nil (nqf (ssget '((0 . "TEXT,ATTDEF")))))

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...