Jump to content

Sum Text Strings to Text Field...


tomjas

Recommended Posts

On 12/1/2010 at 10:46, tomjas said:

Wiz - Eres mi heroe:)

 

Gracias por tu ayuda

 

 

Lee - Tú también eres mi héroe:)

 

¡El formateo funciona muy bien! Probablemente buscaré más propiedades, es decir. Altura del texto

 

Si puede mirar el archivo stx.lsp, que he adjuntado, y busque 'inspiración' ya que esta rutina está haciendo esto:)

 

Ustedes saben lo que significa '{' - Solo sé cómo cargar lsp a CAD:llorar:

stx.lsp 1,7 KB · 35 descargas

Hello, I greet you with great pleasure and pleasure, while I ask for your help. The STX.lsp routine adds TEXT & MTEXT. they can modify it in such a way that it adds the TEXT or MTEXT. enclosed within a closed polyline. thanks for your help

Link to comment
Share on other sites

On 12/1/2010 at 5:56, tomjas said:

Hola,

 

Tengo 2 rutinas lisp: la primera es crear una etiqueta con el área de la escotilla seleccionada (como un campo de texto, por lo que si el área de la escotilla cambia, la etiqueta también cambiará). El segundo es crear una etiqueta con suma de números en textos seleccionados (como un texto estándar). Mi pregunta es: cómo editar la segunda rutina que, en lugar de crear una etiqueta como un texto estándar, creará una etiqueta usando un campo de texto, por lo que si las áreas cambian, la etiqueta con la suma de todas las áreas también cambiará. Gracias por la ayuda de antemano y perdon por mi mal ingles

1 - tarifa.zip 10,97 KB · 63 descargas

2 - stx.lsp 1,7 KB · 58 descargas

Hello, I greet you with great pleasure, while I ask for your help. The STX.lsp routine adds TEXT & MTEXT. they can modify it in such a way that it adds the TEXT or MTEXT. enclosed within a closed polyline. thanks for your help   Could it be done by selecting multiple polygons?. Thanks for your interest and help.

EXAMPLE.dwg

Link to comment
Share on other sites

Easy to do you want to count up items, the only issue is where to place the answer. If use geo centre on some shapes will go outside.

 

Watch this space bit busy at moment

 

But only a counter not a field answer.

Edited by BIGAL
Link to comment
Share on other sites

Thanks for your attention. The center of the polygon is the ideal place. You can express the result circled in red with the "existing gain" layer.

Link to comment
Share on other sites

Working on something.

 

Try this.

; ; https://www.cadtutor.net/forum/topic/17288-sum-text-strings-to-text-field/page/4/
; Count object inside plines
; By AlanH March 2023

(defun ptnummakeblk ( / )
  (entmake (list (cons 0 "BLOCK")
    (cons 2 "COUNTBUB")
    (cons 70 2)
    (cons 10 (list 0 0 0))
    (CONS 8 "0")
  ))
  (entmake (list (cons 0 "CIRCLE")
	 (cons 8 "0")
	 (cons 10 (list 0 0 0))
	 (cons 40 3.25)		; rad
	 (cons 210 (list 0 0 1))
	 (cons 62 256)
	 (cons 39 0)
	 (cons 6 "BYLAYER")
   )
  )
  (entmake (list (cons 0 "ATTDEF")
       (cons 8 "0")
       (cons 10 (list 0 0 0))
	   (cons 1 "1") ; default value
       (cons 2 "COUNTER")		; nblock name
       (cons 3 "Ptnum")		; tag name
       (cons 6 "BYLAYER")
       (cons 7 "STANDARD")	;text style
       (cons 8 "0")		; layer
       (cons 11 (list 0.0 0.0 0.0)) ; text insert pt
       (cons 39 0)
       (cons 40 3.5)		; text height
       (cons 41 1)		; X scale
       (cons 50 0)		; Text rotation
       (cons 51 0)		; Oblique angle
       (cons 62 256)		; by layer color 
       (cons 70 0)
       (cons 71 0)		;Text gen flag
       (cons 72 1)		; Text Justify hor 1 center
       (cons 73 0)		; field length
       (cons 74 2)		; Text Justify ver 2 center
       (cons 210 (list 0 0 1))
  ))
  (entmake (list (cons 0 "ENDBLK")))
  (princ "\nBlock made ")
  (princ)
)

(defun c:startshere ( / )
(if (tblsearch "BLOCK" "COUNTBUB")
  (princ "exists")
  (ptnummakeblk)
)

(setq oldsnap (getvar 'osmode))
(setvar 'osmode 0)
(setvar 'attreq 1)
(setq ss (ssget '((0 . "LWPOLYLINE")(8 . "MANZANAS")(70 . 1))))
(command "zoom" "e")

(if (= ss nil)
(progn (alert "No objects found on layer MANZANAS ")(exit))
(progn
(repeat (setq x (sslength ss))
  (setq plent (ssname ss (setq x (1- x))))
  (setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget plent))))
  (setq cpt (mapcar '(lambda ( x ) (/ x (length co-ord))) (apply 'mapcar (cons '+ co-ord))))
  (setq co-ord (cons (last co-ord) co-ord))
  (setq ss2 (ssget "WP" co-ord '((0 . "ELLIPSE"))))
  (if (= ss2 nil)
   (princ "miss")
   (progn
   (setq cnt (sslength ss2))
   (command "-insert" "countbub" "s" 1 cpt 0 (rtos cnt 2 0))
   )
  )
)
)
)

(setvar 'osmode oldsnap)
(princ)
)
(c:startshere)

 

Edited by BIGAL
Link to comment
Share on other sites

17 hours ago, BIGAL said:

Working on something.

 

Try this.

; ; https://www.cadtutor.net/forum/topic/17288-sum-text-strings-to-text-field/page/4/
; Count object inside plines
; By AlanH March 2023

(defun ptnummakeblk ( / )
  (entmake (list (cons 0 "BLOCK")
    (cons 2 "COUNTBUB")
    (cons 70 2)
    (cons 10 (list 0 0 0))
    (CONS 8 "0")
  ))
  (entmake (list (cons 0 "CIRCLE")
	 (cons 8 "0")
	 (cons 10 (list 0 0 0))
	 (cons 40 3.25)		; rad
	 (cons 210 (list 0 0 1))
	 (cons 62 256)
	 (cons 39 0)
	 (cons 6 "BYLAYER")
   )
  )
  (entmake (list (cons 0 "ATTDEF")
       (cons 8 "0")
       (cons 10 (list 0 0 0))
	   (cons 1 "1") ; default value
       (cons 2 "COUNTER")		; nblock name
       (cons 3 "Ptnum")		; tag name
       (cons 6 "BYLAYER")
       (cons 7 "STANDARD")	;text style
       (cons 8 "0")		; layer
       (cons 11 (list 0.0 0.0 0.0)) ; text insert pt
       (cons 39 0)
       (cons 40 3.5)		; text height
       (cons 41 1)		; X scale
       (cons 50 0)		; Text rotation
       (cons 51 0)		; Oblique angle
       (cons 62 256)		; by layer color 
       (cons 70 0)
       (cons 71 0)		;Text gen flag
       (cons 72 1)		; Text Justify hor 1 center
       (cons 73 0)		; field length
       (cons 74 2)		; Text Justify ver 2 center
       (cons 210 (list 0 0 1))
  ))
  (entmake (list (cons 0 "ENDBLK")))
  (princ "\nBlock made ")
  (princ)
)

(defun c:startshere ( / )
(if (tblsearch "BLOCK" "COUNTBUB")
  (princ "exists")
  (ptnummakeblk)
)

(setq oldsnap (getvar 'osmode))
(setvar 'osmode 0)
(setvar 'attreq 1)
(setq ss (ssget '((0 . "LWPOLYLINE")(8 . "MANZANAS")(70 . 1))))
(command "zoom" "e")

(if (= ss nil)
(progn (alert "No objects found on layer MANZANAS ")(exit))
(progn
(repeat (setq x (sslength ss))
  (setq plent (ssname ss (setq x (1- x))))
  (setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget plent))))
  (setq cpt (mapcar '(lambda ( x ) (/ x (length co-ord))) (apply 'mapcar (cons '+ co-ord))))
  (setq co-ord (cons (last co-ord) co-ord))
  (setq ss2 (ssget "WP" co-ord '((0 . "ELLIPSE"))))
  (if (= ss2 nil)
   (princ "miss")
   (progn
   (setq cnt (sslength ss2))
   (command "-insert" "countbub" "s" 1 cpt 0 (rtos cnt 2 0))
   )
  )
)
)
)

(setvar 'osmode oldsnap)
(princ)
)
(c:startshere)

 

Dear Bigal. Thank you for your help. It works excellent, but the labels to add have variable amounts. You can modify the routine, to add the numeric text quantities.

I apologize for not being assertive in my request.
 

example 1.JPG

Link to comment
Share on other sites

Ok its time for you to have a go at lisp, dont worry if get wrong just post here and we can help.

 

(setq ss2 (ssget "WP" co-ord '((0 . "ELLIPSE")))) change to TEXT

 

(setq cnt (sslength ss2))

becomes a loop 

(setq cnt 0.0)
(repeat (setq x (sslength ss2))
get each item in selection set 
then get text value 
add text value to cnt
)

If you look at code you can see a repeat example. 

 

Ps tested already is adding values but have a go 1st.

image.png.e14026a8a94fccf4ff605294409ec994.png

Edited by BIGAL
Link to comment
Share on other sites

Hace 7 horas, BIGAL dijo:

Ok, es hora de que pruebes lisp, no te preocupes si te equivocas, solo publica aquí y podemos ayudarte.

 

 

Si observa el código, puede ver un ejemplo repetido. 

 

Ps probado ya está agregando valores, pero pruébalo primero.

imagen.png.e14026a8a94fccf4ff605294409ec994.png

Bigal saludos cordiales desde México. Siento decir que no sé nada de programación. No sabría arreglar la rutina para que me diera el resultado esperado. 

Edited by DAVID_OJEDA
Link to comment
Share on other sites

Post also in English please.

 

Try this it is based on "X INFO"

 


; ; https://www.cadtutor.net/forum/topic/17288-sum-text-strings-to-text-field/page/4/
; Count object inside plines
; By AlanH March 2023

(defun ptnummakeblk ( / )
  (entmake (list (cons 0 "BLOCK")
    (cons 2 "COUNTBUB")
    (cons 70 2)
    (cons 10 (list 0 0 0))
    (CONS 8 "0")
  ))
  (entmake (list (cons 0 "CIRCLE")
	 (cons 8 "0")
	 (cons 10 (list 0 0 0))
	 (cons 40 3.25)		; rad
	 (cons 210 (list 0 0 1))
	 (cons 62 256)
	 (cons 39 0)
	 (cons 6 "BYLAYER")
   )
  )
  (entmake (list (cons 0 "ATTDEF")
       (cons 8 "0")
       (cons 10 (list 0 0 0))
	   (cons 1 "1") ; default value
       (cons 2 "COUNTER")		; nblock name
       (cons 3 "Ptnum")		; tag name
       (cons 6 "BYLAYER")
       (cons 7 "STANDARD")	;text style
       (cons 8 "0")		; layer
       (cons 11 (list 0.0 0.0 0.0)) ; text insert pt
       (cons 39 0)
       (cons 40 3.5)		; text height
       (cons 41 1)		; X scale
       (cons 50 0)		; Text rotation
       (cons 51 0)		; Oblique angle
       (cons 62 256)		; by layer color 
       (cons 70 0)
       (cons 71 0)		;Text gen flag
       (cons 72 1)		; Text Justify hor 1 center
       (cons 73 0)		; field length
       (cons 74 2)		; Text Justify ver 2 center
       (cons 210 (list 0 0 1))
  ))
  (entmake (list (cons 0 "ENDBLK")))
  (princ "\nBlock made ")
  (princ)
)
(defun c:startshere ( / )
(if (tblsearch "BLOCK" "COUNTBUB")
  (princ "exists")
  (ptnummakeblk)
)
(setq oldsnap (getvar 'osmode))
(setvar 'osmode 0)
(setvar 'attreq 1)
(setq ss (ssget '((0 . "LWPOLYLINE")(8 . "MANZANAS")(70 . 1))))
(command "zoom" "e")
(if (= ss nil)
(progn (alert "No objects found on layer MANZANAS ")(exit))
(progn
(repeat (setq x (sslength ss))
  (setq plent (ssname ss (setq x (1- x))))
  (setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget plent))))
  (setq cpt (mapcar '(lambda ( x ) (/ x (length co-ord))) (apply 'mapcar (cons '+ co-ord))))
  (setq co-ord (cons (last co-ord) co-ord))
  (setq ss2 (ssget "WP" co-ord '((0 . "TEXT"))))
  (if (= ss2 nil)
   (princ "miss")
   (progn
   (setq cnt 0.0)
   (repeat (setq y (sslength ss2))
   (setq ent (ssname ss2 (setq y (1- y))))
   (setq val (atoi (cdr (assoc 1 (entget ent)))))
   (setq cnt (+ cnt val))
   )
   (command "-insert" "countbub" "s" 1 cpt 0 (rtos cnt 2 0))
   )
  )
)
)
)
(setvar 'osmode oldsnap)
(princ)
)
(c:startshere)

 

Link to comment
Share on other sites

5 hours ago, BIGAL said:

Post also in English please.

 

Try this it is based on "X INFO"

 


; ; https://www.cadtutor.net/forum/topic/17288-sum-text-strings-to-text-field/page/4/
; Count object inside plines
; By AlanH March 2023

(defun ptnummakeblk ( / )
  (entmake (list (cons 0 "BLOCK")
    (cons 2 "COUNTBUB")
    (cons 70 2)
    (cons 10 (list 0 0 0))
    (CONS 8 "0")
  ))
  (entmake (list (cons 0 "CIRCLE")
	 (cons 8 "0")
	 (cons 10 (list 0 0 0))
	 (cons 40 3.25)		; rad
	 (cons 210 (list 0 0 1))
	 (cons 62 256)
	 (cons 39 0)
	 (cons 6 "BYLAYER")
   )
  )
  (entmake (list (cons 0 "ATTDEF")
       (cons 8 "0")
       (cons 10 (list 0 0 0))
	   (cons 1 "1") ; default value
       (cons 2 "COUNTER")		; nblock name
       (cons 3 "Ptnum")		; tag name
       (cons 6 "BYLAYER")
       (cons 7 "STANDARD")	;text style
       (cons 8 "0")		; layer
       (cons 11 (list 0.0 0.0 0.0)) ; text insert pt
       (cons 39 0)
       (cons 40 3.5)		; text height
       (cons 41 1)		; X scale
       (cons 50 0)		; Text rotation
       (cons 51 0)		; Oblique angle
       (cons 62 256)		; by layer color 
       (cons 70 0)
       (cons 71 0)		;Text gen flag
       (cons 72 1)		; Text Justify hor 1 center
       (cons 73 0)		; field length
       (cons 74 2)		; Text Justify ver 2 center
       (cons 210 (list 0 0 1))
  ))
  (entmake (list (cons 0 "ENDBLK")))
  (princ "\nBlock made ")
  (princ)
)
(defun c:startshere ( / )
(if (tblsearch "BLOCK" "COUNTBUB")
  (princ "exists")
  (ptnummakeblk)
)
(setq oldsnap (getvar 'osmode))
(setvar 'osmode 0)
(setvar 'attreq 1)
(setq ss (ssget '((0 . "LWPOLYLINE")(8 . "MANZANAS")(70 . 1))))
(command "zoom" "e")
(if (= ss nil)
(progn (alert "No objects found on layer MANZANAS ")(exit))
(progn
(repeat (setq x (sslength ss))
  (setq plent (ssname ss (setq x (1- x))))
  (setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget plent))))
  (setq cpt (mapcar '(lambda ( x ) (/ x (length co-ord))) (apply 'mapcar (cons '+ co-ord))))
  (setq co-ord (cons (last co-ord) co-ord))
  (setq ss2 (ssget "WP" co-ord '((0 . "TEXT"))))
  (if (= ss2 nil)
   (princ "miss")
   (progn
   (setq cnt 0.0)
   (repeat (setq y (sslength ss2))
   (setq ent (ssname ss2 (setq y (1- y))))
   (setq val (atoi (cdr (assoc 1 (entget ent)))))
   (setq cnt (+ cnt val))
   )
   (command "-insert" "countbub" "s" 1 cpt 0 (rtos cnt 2 0))
   )
  )
)
)
)
(setvar 'osmode oldsnap)
(princ)
)
(c:startshere)

 

Bigal thank  very much. I really appreciate your help. works excellent

Link to comment
Share on other sites

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...