leonucadomi Posted July 16 Posted July 16 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 July 17 Posted July 17 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 July 17 Author Posted July 17 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 July 17 Posted July 17 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 July 17 Author Posted July 17 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 July 17 Posted July 17 ;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 July 17 Posted July 17 Excel and I barely know each other. I don't feel as prepared as some to talk about him 1 Quote
leonucadomi Posted July 17 Author Posted July 17 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 July 17 Author Posted July 17 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 July 17 Posted July 17 @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 1 1 Quote
leonucadomi Posted 7 hours ago Author Posted 7 hours ago On 7/17/2025 at 5:01 PM, 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"))))) you can make the routine show the number of selected texts and the number of attributes, please Quote
GLAVCVS Posted 4 hours ago Posted 4 hours ago ;BACALADO DE BILBADOOO (PLUS) (defun nqf (tuSS / i lista tipObj cant cad txs atts) (princ "\nNumero que falta") (terpri) (if tuSS (setq cant (sslength tuSS)) (progn (alert "No existe conjunto de seleccion o esta vacio") (exit) ) ) (princ "\nCantidad de textos seleccionados = ") (princ cant) (princ "\nLista de numeros faltantes") ;Pasar del SS a una lista de valores (setq i 0 txs 0 atts 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))) ) ) (if (= tipObj "TEXT") (setq txs (+ txs 1)) (setq atts (+ atts 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 ) "\nTextos: " (itoa txs) "\nAtributos: " (itoa atts) ) ) (princ) ) (defun c:nqf nil (nqf (ssget '((0 . "TEXT,ATTDEF"))))) Quote
GLAVCVS Posted 2 hours ago Posted 2 hours ago On 7/18/2025 at 1:14 AM, leonucadomi said: 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) var1, var2, and var3 should be "punto," "angulo," and "distancia"? So: angle and distance... between what objects? Quote
BIGAL Posted 2 hours ago Posted 2 hours ago (edited) " how many times each tag is repeated. " that is in the answer I provided. (("048" 1) ("047" 1) ("046" 1) ("045" 2) ("044" 1) ("043" 2) ("042" 1) ("041" 2) ("040" 1) ("039" 1) ("038" 2) ("037" 1) ("036" 2) ("035" 2) ("034" 6) ("033" 6) ("032" 6) ("031" 2) ("030" 2) ("029" 12) ("028" 6) ("027" 6) ("026" 23) ("025" 2) ("024" 4) ("023" 6) ("022" 6) ("021" 1) ("020" 1) ("019" 2) ("018" 2) ("017" 1) ("016" 1) ("015" 2) ("014" 6) ("013" 2) ("012" 2) ("011" 2) ("010" 1) ("009" 1) ("008" 1) ("007" 1) ("006" 4) ("005" 16) ("004" 1) ("003" 1) ("002" 1) ("001" 1)) change code at end add princ lst3 ) (princ lst3) (princ) ) I can do the send to excel if you want ? You have asked for text also can you post anther sample dwg with say both, text and Attdef. Will have a think about missing value. Edited 2 hours ago by BIGAL 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.