<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Lisp modification for Average, Min, Max value in Visual LISP, AutoLISP and General Customization Forum</title>
    <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-modification-for-average-min-max-value/m-p/13414071#M1202</link>
    <description>&lt;P&gt;you can use this function which I modified from &lt;STRONG&gt;pBe&amp;nbsp;&lt;/STRONG&gt;here:&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.cadtutor.net/forum/topic/49178-remove-only-alphabetical-characters-from-string/" target="_blank"&gt;https://www.cadtutor.net/forum/topic/49178-remove-only-alphabetical-characters-from-string/&lt;/A&gt;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;(defun numbers1 (str / a b)
 (setq a "")
 (repeat (strlen str)
   (if	(&amp;lt; 45 (ascii (setq b (substr str 1 1))) 58)
     (setq a (strcat a b))
   )
   (setq str (substr str 2))
 )
 a
)&lt;/LI-CODE&gt;&lt;P&gt;&lt;A href="https://www.cadtutor.net/forum/topic/49178-remove-only-alphabetical-characters-from-string/" target="_blank"&gt;https://www.cadtutor.net/forum/topic/49178-remove-only-alphabetical-characters-from-string/&amp;nbsp;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Usage based on your Example:&lt;/P&gt;&lt;LI-CODE lang="general"&gt;(/ (+ (distof(numbers1 "H=0.60")) (distof(numbers1 "B=2.75"))) 2)&lt;/LI-CODE&gt;&lt;P&gt;Returns:&amp;nbsp;&lt;/P&gt;&lt;P&gt;1.675&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 08 Apr 2025 05:59:41 GMT</pubDate>
    <dc:creator>paullimapa</dc:creator>
    <dc:date>2025-04-08T05:59:41Z</dc:date>
    <item>
      <title>Lisp modification for Average, Min, Max value</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-modification-for-average-min-max-value/m-p/13413876#M1201</link>
      <description>&lt;P&gt;Can someone please assist me?&lt;BR /&gt;I found the below Lisp that does a great job already of calculating Average value for example, but I need to have it modified to ONLY read numeric values within selected text strings. I have values that regularly have prefixes that are not allowing the Lisp to function properly.&lt;/P&gt;&lt;P&gt;e.g. "H=0.60" + "B=2.75" to return "1.675"&lt;/P&gt;&lt;P&gt;Currently it is returning the result as "0.000".&lt;BR /&gt;&lt;BR /&gt;Thanks in advance!&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;; Max, Min and Average by Lee McDonnell -- 12/08

(defun c:number    (/       ans         ss_max    ssl_max     xth       tent_max  ent_max   ent_base_max
        num_max   ss_min    ssl_min   yth     tent_min  ent_min   ent_base_min
        num_min   ss         ssl       index     tents       tot         ent       num
        ave
       )

   (princ "\nInitializing...")
   (initget 1 "Max Min Average")
   (setq ans (getkword "\nSpecify Numerical Requirement [MAx/MIn/Ave]: "))
   (cond
   ((= ans "Max")
    (setq ss_max    (ssget)
          ssl_max    (sslength ss_max)
          xth    0
          tent_max    0
    ) ;_  end setq
    (if (/= ssl_max 0)
        (progn
        (while    (&amp;lt; xth ssl_max)
            (setq ent_max (entget (ssname ss_max xth)))
            (if (= (cdr (assoc 0 ent_max)) "TEXT")
            (progn
                (setq ent_base_max (atof (cdr (assoc 1 ent_max))))
                (setq xth ssl_max)
            ) ;_  end progn
            (setq xth (1+ xth))
            ) ;_  end if
        ) ;_  end while
        (setq xth 0)
        (repeat ssl_max
            (setq ent_max (entget (ssname ss_max xth)))
            (if (= (cdr (assoc 0 ent_max)) "TEXT")
            (progn
                (setq num_max (atof (cdr (assoc 1 ent_max))))
                (if (&amp;gt; num_max ent_base_max)
                (setq ent_base_max num_max)
                ) ;_  end if
                (setq tent_max (1+ tent_max))
            ) ;_  end progn
            ) ;_  end if
            (setq xth (1+ xth))
        ) ;_  end repeat
        (alert (strcat "Maximum of " (rtos tent_max) " Numbers is: " (rtos ent_base_max)))
        ) ;_  end progn
        (alert "No Entities Selected.")
    ) ;_  end if
   )
   ((= ans "Min")
    (setq ss_min    (ssget)
          ssl_min    (sslength ss_min)
          yth    0
          tent_min    0
    ) ;_  end setq
    (if (/= ssl_min 0)
        (progn
        (while    (&amp;lt; yth ssl_min)
            (setq ent_min (entget (ssname ss_min yth)))
            (if (= (cdr (assoc 0 ent_min)) "TEXT")
            (progn
                (setq ent_base_min (atof (cdr (assoc 1 ent_min))))
                (setq yth ssl_min)
            ) ;_  end progn
            (setq yth (1+ yth))
            ) ;_  end if
        ) ;_  end while
        (setq yth 0)
        (repeat ssl_min
            (setq ent_min (entget (ssname ss_min yth)))
            (if (= (cdr (assoc 0 ent_min)) "TEXT")
            (progn
                (setq num_min (atof (cdr (assoc 1 ent_min))))
                (if (&amp;lt; num_min ent_base_min)
                (setq ent_base_min num_min)
                ) ;_  end if
                (setq tent_min (1+ tent_min))
            ) ;_  end progn
            ) ;_  end if
            (setq yth (1+ yth))
        ) ;_  end repeat
        (alert (strcat "Minimum of " (rtos tent_min) " Numbers is: " (rtos ent_base_min)))
        ) ;_  end progn
        (alert "No Entities Selected.")
    ) ;_  end if
   )
   ((= ans "Average")
    (setq ss    (ssget)
          ssl   (sslength ss)
          index 0
          tents 0
          tot   0
    ) ;_  end setq
    (repeat ssl
        (setq ent (entget (ssname ss index)))
        (if (= (cdr (assoc 0 ent)) "TEXT")
        (progn
            (setq num (atof (cdr (assoc 1 ent))))
            (setq tot (+ num 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&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Apr 2025 01:48:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-modification-for-average-min-max-value/m-p/13413876#M1201</guid>
      <dc:creator>brendon_butler2</dc:creator>
      <dc:date>2025-04-08T01:48:57Z</dc:date>
    </item>
    <item>
      <title>Re: Lisp modification for Average, Min, Max value</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-modification-for-average-min-max-value/m-p/13414071#M1202</link>
      <description>&lt;P&gt;you can use this function which I modified from &lt;STRONG&gt;pBe&amp;nbsp;&lt;/STRONG&gt;here:&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.cadtutor.net/forum/topic/49178-remove-only-alphabetical-characters-from-string/" target="_blank"&gt;https://www.cadtutor.net/forum/topic/49178-remove-only-alphabetical-characters-from-string/&lt;/A&gt;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;(defun numbers1 (str / a b)
 (setq a "")
 (repeat (strlen str)
   (if	(&amp;lt; 45 (ascii (setq b (substr str 1 1))) 58)
     (setq a (strcat a b))
   )
   (setq str (substr str 2))
 )
 a
)&lt;/LI-CODE&gt;&lt;P&gt;&lt;A href="https://www.cadtutor.net/forum/topic/49178-remove-only-alphabetical-characters-from-string/" target="_blank"&gt;https://www.cadtutor.net/forum/topic/49178-remove-only-alphabetical-characters-from-string/&amp;nbsp;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Usage based on your Example:&lt;/P&gt;&lt;LI-CODE lang="general"&gt;(/ (+ (distof(numbers1 "H=0.60")) (distof(numbers1 "B=2.75"))) 2)&lt;/LI-CODE&gt;&lt;P&gt;Returns:&amp;nbsp;&lt;/P&gt;&lt;P&gt;1.675&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Apr 2025 05:59:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-modification-for-average-min-max-value/m-p/13414071#M1202</guid>
      <dc:creator>paullimapa</dc:creator>
      <dc:date>2025-04-08T05:59:41Z</dc:date>
    </item>
    <item>
      <title>Re: Lisp modification for Average, Min, Max value</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-modification-for-average-min-max-value/m-p/13414234#M1203</link>
      <description>&lt;P&gt;It seems like it's Lees's training code from his early days... If you like a more streamlined version returning an overview...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;(vl-load-com)

(defun c:Numbers ( / LM:parsenumbers s)
  
  ;; Parse Numbers  -  Lee Mac ;; Parses a list of numerical values from a supplied string. ;; https://www.lee-mac.com/parsenumbers.html
  (defun LM:parsenumbers ( str )
    (   (lambda ( l ) (read (strcat "(" (vl-list-&amp;gt;string
					  (mapcar '(lambda ( a b c )
						     (if (or (&amp;lt; 47 b 58)
							     (and (= 45 b) (&amp;lt; 47 c 58) (not (&amp;lt; 47 a 58)))
							     (and (= 46 b) (&amp;lt; 47 a 58) (&amp;lt; 47 c 58))
							     )
						       b 32))
						  (cons nil l) l (append (cdr l) '(()))))
				    ")")))
      (vl-string-&amp;gt;list str)))
  
  ; ================================================================================================

  (and (setq s (ssget '((0 . "*TEXT") (1 . "*#*"))))
       (setq s (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))))
       (setq s (mapcar '(lambda (e) (cond ((not (vl-catch-all-error-p (setq x (vl-catch-all-apply 'getpropertyvalue (list e "TextString"))))) x)
					  ((not (vl-catch-all-error-p (setq x (vl-catch-all-apply 'getpropertyvalue (list e "Text"))))) x)))
		       s))
       (setq s (mapcar 'LM:parsenumbers s))
       (setq s (mapcar 'car s))
       (setq s (vl-sort s '&amp;lt;))
       (princ (strcat (itoa (length s)) " found: " (substr (apply 'strcat (mapcar '(lambda (x) (strcat " &amp;lt; " (rtos x))) s)) 4)
		      "\n&amp;gt;&amp;gt; dlt " (rtos (- (apply 'max s) (apply 'min s))) " -- sum " (rtos (apply '+ s))
		      "\n&amp;gt;&amp;gt; min " (rtos (apply 'min s)) " -- avg " (rtos (/ (apply '+ s) (float (length s)))) " -- max " (rtos (apply 'max s))))
       )
  (princ)
  )
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Apr 2025 07:42:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-modification-for-average-min-max-value/m-p/13414234#M1203</guid>
      <dc:creator>ВeekeeCZ</dc:creator>
      <dc:date>2025-04-08T07:42:17Z</dc:date>
    </item>
    <item>
      <title>Re: Lisp modification for Average, Min, Max value</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-modification-for-average-min-max-value/m-p/13415166#M1204</link>
      <description>&lt;P&gt;The&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt; (atof)&lt;/STRONG&gt; &lt;/FONT&gt;function always returns 0.0 from a string that doesn't &lt;EM&gt;begin with&lt;/EM&gt; numerical content.&lt;/P&gt;
&lt;P&gt;Stripping the non-numerical parts from a text string could be simplified if there's something consistent about them, such as always beginning with a letter and an&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt; =&lt;/STRONG&gt; &lt;/FONT&gt;sign.&amp;nbsp; Is there some constant property like that?&amp;nbsp; Even just that everything up to and including an&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt; =&lt;/STRONG&gt; &lt;/FONT&gt;sign should be removed, even if there's more than one character before it?&amp;nbsp; Is there ever a suffix, too, or instead?&amp;nbsp; [If there's a non-numerical &lt;EM&gt;suffix only&lt;/EM&gt;, then&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt; (atof)&lt;/STRONG&gt; &lt;/FONT&gt;should give the right result -- it works with the starting numerical content, and ignores the rest.]&lt;/P&gt;</description>
      <pubDate>Tue, 08 Apr 2025 17:09:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-modification-for-average-min-max-value/m-p/13415166#M1204</guid>
      <dc:creator>Kent1Cooper</dc:creator>
      <dc:date>2025-04-08T17:09:58Z</dc:date>
    </item>
    <item>
      <title>Re: Lisp modification for Average, Min, Max value</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-modification-for-average-min-max-value/m-p/13417060#M1205</link>
      <description>&lt;P&gt;Here is a generalization using RegEx (&lt;EM&gt;*multi*numbers*&lt;/EM&gt; controls whether ALL numbers in given texts are extracted):&lt;/P&gt;
&lt;LI-CODE lang="lisp"&gt;;Extract numbers from texts
; original by ВeekeeCZ at https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-modification-for-average-min-max-value/td-p/13413876
; RegEx and MLeader/Dim generalization by V.Michl, www.arkance.world - www.cadforum.cz

(vl-load-com)

(defun C:Extract-numbers ( / lst)

 ;(RegexpExec "weight=123.4kg" "^[^0-9\\-]*(-?\\d+(?:\\.\\d+)?)") --&amp;gt; ("123.4")
 ;(RegexpExec "is -98 per 123 pcs" "^[^0-9\\-]*(-?\\d+(?:\\.\\d+)?)") --&amp;gt; ("-98")
 (defun RegExpExec (string pattern / sublst lst RegExp)
  (setq RegExp (vlax-create-object "VBScript.RegExp"))
  (vlax-put-property RegExp 'Pattern pattern)
  (vlax-put-property RegExp 'Global :vlax-true)
  (vlax-for match (vlax-invoke RegExp 'Execute string)
    (setq sublst nil)
    (vl-catch-all-apply
      '(lambda ()
		(vlax-for submatch (vlax-get match 'SubMatches)
		 (if submatch
	      (setq sublst (cons submatch sublst))
		 )
		)
       )
    )
	(setq lst (cons (car sublst) lst))
  )
  (setq RegExp nil)
  (reverse lst)
 )
;(PRINT (RegExpExec "weight=123.4kg" "^[^0-9\\-]*(-?\\d+(?:\\.\\d+)?)"))
;(PRINT (RegExpExec "weight=1234kg" "^[^0-9\\-]*(-?\\d+(?:\\.\\d+)?)"))
;(PRINT (RegExpExec "weight=-1234kg" "^[^0-9\\-]*(-?\\d+(?:\\.\\d+)?)"))
;(PRINT (RegExpExec "weight=123.4kg per 89 pcs" "[^0-9\\-]*(-?\\d+(?:\\.\\d+)?)"))

;flatten list
 (defun LM:flatten ( l )
    (if (atom l)
        (list l)
        (append (LM:flatten (car l)) (if (cdr l) (LM:flatten (cdr l))))
    )
 )

  ; ================================================================================================

  (and (setq s (ssget '((0 . "*TEXT,*LEADER,DIMENSION") (-4 . "&amp;lt;OR")(1 . "*#*")(304 . "*#*")(-4 . "OR&amp;gt;"))))
       (setq s (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))))
       (setq s (mapcar '(lambda (e) 
						(setq o (vlax-ename-&amp;gt;vla-object e)) ; getpropertyvalue fails
						(cond 
							((not (vl-catch-all-error-p (setq x (vl-catch-all-apply 'vlax-get-property (list o "TextOverride"))))) x)
							((not (vl-catch-all-error-p (setq x (vl-catch-all-apply 'vlax-get-property (list o "TextString"))))) x)
							((not (vl-catch-all-error-p (setq x (vl-catch-all-apply 'vlax-get-property (list o "Text"))))) x)
						))
		       s))
	   (setq s (mapcar '(lambda(e) (RegExpExec e "[^0-9\\-]*(-?\\d+(?:\\.\\d+)?)")) s))
	   (if *MULTI*NUMBERS* 
	    (setq s (mapcar '(lambda(e) (read e)) (LM:flatten s))) ; all numbers in a text
	    (setq s (mapcar '(lambda(e) (read (car e))) s)) ; just first
	   )
       (setq s (vl-sort s '&amp;lt;))
       (princ (strcat (itoa (length s)) " found: " (substr (apply 'strcat (mapcar '(lambda (x) (strcat " &amp;lt; " (rtos x))) s)) 4)
		      "\n&amp;gt;&amp;gt; delta " (rtos (- (apply 'max s) (apply 'min s))) " -- sum " (rtos (apply '+ s))
		      "\n&amp;gt;&amp;gt; min " (rtos (apply 'min s)) " -- avg " (rtos (/ (apply '+ s) (float (length s)))) " -- max " (rtos (apply 'max s))))
       )
  (princ)
)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Vladimir Michl, &lt;A href="http://www.arkance.world" target="_blank" rel="noopener"&gt;www.arkance.world&lt;/A&gt;&amp;nbsp; -&amp;nbsp; &lt;A href="http://www.cadforum.cz" target="_blank" rel="noopener"&gt;www.cadforum.cz&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Apr 2025 06:54:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-modification-for-average-min-max-value/m-p/13417060#M1205</guid>
      <dc:creator>vladimir_michl</dc:creator>
      <dc:date>2025-04-11T06:54:17Z</dc:date>
    </item>
    <item>
      <title>Re: Lisp modification for Average, Min, Max value</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-modification-for-average-min-max-value/m-p/13420132#M1206</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/17180473"&gt;@brendon_butler2&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Try the attached...&lt;/P&gt;</description>
      <pubDate>Thu, 10 Apr 2025 23:51:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-modification-for-average-min-max-value/m-p/13420132#M1206</guid>
      <dc:creator>john.uhden</dc:creator>
      <dc:date>2025-04-10T23:51:33Z</dc:date>
    </item>
  </channel>
</rss>

