leonucadomi Posted Wednesday at 10:37 PM Posted Wednesday at 10:37 PM 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 Quote
BIGAL Posted yesterday at 12:33 AM Posted yesterday at 12:33 AM 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) ) 1 Quote
leonucadomi Posted 14 hours ago Author Posted 14 hours ago 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 Quote
GLAVCVS Posted 12 hours ago Posted 12 hours ago 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"))))) 1 Quote
leonucadomi Posted 5 hours ago Author Posted 5 hours ago 5 hours ago, GLAVCVS said: 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"))))) It's excellent, thank you I just think there is a mistake When the first number has more than one repetition, it is not counted. Could it be possible to export a file xls with two columns of values, its tag and its quantity? Quote
GLAVCVS Posted 4 hours ago Posted 4 hours ago ;BACALADODEBILBADOO.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)) ")") (strcat (itoa (car v)) "(" (itoa (cadr 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"))))) 1 Quote
GLAVCVS Posted 4 hours ago Posted 4 hours ago Excel and I barely know each other. I don't feel as prepared as some to talk about him 1 Quote
leonucadomi Posted 4 hours ago Author Posted 4 hours ago 7 minutes ago, GLAVCVS said: ;BACALADODEBILBADOO.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)) ")") (strcat (itoa (car v)) "(" (itoa (cadr 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"))))) thank you master Quote
leonucadomi Posted 4 hours ago Author Posted 4 hours ago 3 minutes ago, GLAVCVS said: Excel and I barely know each other. I don't feel as prepared as some to talk about him It can also be a csv file Here I have an example code that, while calculating, generates a file like the one I told you about. (setq fn (getfiled "Fichero de punto a exportar" "" "csv" 1)) (setq Archivo (open fn "w")) (setq var0 "Puntos") (setq var1 "Angulos") (setq var2 "Distancias") (princ (strcat var0 "," var1 "," var2) Archivo) (princ "\n" Archivo) (setq n 0) Quote
BIGAL Posted 3 hours ago Posted 3 hours ago @GLAVCVS & @leonucadomi have a look at this it,s not code solution but rather a number of defuns to talk to Excel, read and write plus more. I keep adding functions. Alan Excel library.lsp Quote
Recommended Posts
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.