- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Denunciar
My dear Brothers and sisters,
I don’t know how to write lisp routine, when I need same kind of lisp I search in Google and get. First of all I want to thank for all of you.
Recently I found a lisp that helps me a lot to get min, max and average.
For an example, if I have a cad drawing having lots of pulse minus levels, I need average of selected levels. With help of that lisp I get average.
When that lisp runs, after bunch of values are selected, the requirement will be asked. (min or max or avg). after requirement is entered. Answer is displayed.
But I want that answer to be written on the drawing itself.
If somebody can edit that lisp “select the location to place the answer” or something like that. I would be very much grateful.
---------------------------------------------------------
This is the lisp
; Max, Min and Average by Lee McDonnell -- 12/08
(defun c:number (/ ans ent1 nmax ent num ent2 nmin ent3 num2 ss ssl index tents tot ent4 num3 ave)
(princ "\nInitializing...")
(initget 1 "Max Min Average")
(setq ans (getkword "\nSpecify Numerical Requirement [MAx/MIn/Ave]: "))
(cond
((= ans "Max")
(if
(setq ent1 (car (entsel "\nSelect Numerical Text: ")))
(progn
(setq nmax (atof (cdr (assoc 1 (entget ent1)))))
(while
(/= (setq ent (car (entsel "\nSelect Numerical Text: "))) nil)
(if (= (cdr (assoc 0 (entget ent))) "TEXT")
(progn
(setq num (atof (cdr (assoc 1 (entget ent)))))
(if (> num nmax)
(setq nmax num)
) ;_ end if
) ;_ end progn
(alert "Selected Entity must be Text.")
) ;_ end if
) ;_ end while
(alert (strcat "Maximum Number is: " (rtos nmax)))
) ;_ end progn
(alert "Text Required.")
) ;_ end if
)
((= ans "Min")
(if
(setq ent2 (car (entsel "\nSelect Numerical Text: ")))
(progn
(setq nmin (atof (cdr (assoc 1 (entget ent2)))))
(while
(/= (setq ent3 (car (entsel "\nSelect Numerical Text: "))) nil)
(if (= (cdr (assoc 0 (entget ent3))) "TEXT")
(progn
(setq num2 (atof (cdr (assoc 1 (entget ent3)))))
(if (< num2 nmin)
(setq nmin num2)
) ;_ end if
) ;_ end progn
(alert "Selected Entity must be Text.")
) ;_ end if
) ;_ end while
(alert (strcat "Minimum Number is: " (rtos nmin)))
) ;_ end progn
(alert "Text Required.")
) ;_ end if
)
((= ans "Average")
(setq ss (ssget)
ssl (sslength ss)
index 0
tents 0
tot 0
) ;_ end setq
(repeat ssl
(setq ent4 (entget (ssname ss index)))
(if (= (cdr (assoc 0 ent4)) "TEXT")
(progn
(setq num3 (atof (cdr (assoc 1 ent4))))
(setq tot (+ num3 tot))
(setq tents (1+ tents))
) ;_ end progn
) ;_ end if
(setq index (1+ index))
) ;_ end repeat
(if (/= tents 0)
(progn
(setq ave (/ tot tents))
(alert (strcat "Average of " (rtos tents) " Numbers is: " (rtos ave)))
) ;_ end progn
(alert "No Text Entities Selected.")
) ;_ end if
)
) ;_ end cond
(princ)
) ;_ end defun
¡Resuelto! Ir a solución.
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Denunciar
Replace this line of code --> (alert (strcat "Maximum Number is: " (rtos nmax)))
with the following 3 lines of code
(setq textpoint (getpoint "PICK LOCATION for ANSWER"))
(setq answer (strcat "Maximum Number is: " (rtos nmax)))
(command "text" textpoint "" "" answer)
Do the same as above for this line --> (alert (strcat "Minimum Number is: " (rtos nmin)))
(setq textpoint (getpoint "PICK LOCATION for ANSWER"))
(setq answer (strcat "Minimum Number is: " (rtos nmin)))
(command "text" textpoint "" "" answer)
and finally replace this line --> (alert (strcat "Average of " (rtos tents) " Numbers is: " (rtos ave)))
with the following lines
(setq textpoint (getpoint "PICK LOCATION for ANSWER"))
(setq answer (strcat "Average of " (rtos tents) " Numbers is: " (rtos ave)))
(command "text" textpoint "" "" answer)
Make sure you have a copy of the original before making changes.
And please thank Lee McDonnell for the original code.
Hope this helps
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Denunciar
I owe you a lot my brothers.. ....!!
Thanks again for your Kind Generous. You guys make our life easier..
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Denunciar
I tried this with the changes, is there a way to make the output number as just a decimal number rather than x'-x". I'm use to the old command in R2000 that gave a total, number of items, average, max and min all in one output.
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Denunciar
@Anonymous wrote:
.... is there a way to make the output number as just a decimal number rather than x'-x". ....
The (rtos) [real number to string] function returns a text string in whatever the current Units mode and precision settings are, if you don't tell it to do something different. Read about it in Help to understand its mode and precision arguments. Basically, you should go through the code and find all of those, and change those where you want a decimal output from:
(rtos whatever)
to something like:
(rtos whatever 2 3)
The 2 is for decimal mode, the 3 is my arbitrary assumption for the number of decimal places, so change that to what you prefer.