Author Topic: Arithmetic operations in numeric strings  (Read 4333 times)

0 Members and 1 Guest are viewing this topic.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1454
  • Marco
Arithmetic operations in numeric strings
« on: November 12, 2016, 05:52:52 AM »
I need to sum "numeric strings" and I have solved with:
many thanks to Lee Mac  :-)
Code: [Select]
;;-------------------=={ Parse Numbers }==--------------------;;
;;                                                            ;;
;;  Parses a list of numerical values from a supplied string. ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  s  - String to process                                    ;;
;;------------------------------------------------------------;;
;;  Returns:  List of numerical values found in string.       ;;
;;------------------------------------------------------------;;
;
(defun LM:ParseNumbers ( s )
  (
    (lambda ( l )
      (read
        (strcat "("
          (vl-list->string
            (mapcar
              (function
                (lambda ( a b c )
                  (if
                    (or
                      (< 47 b 58)
                      (and (= 45 b) (< 47 c 58) (not (< 47 a 58)))
                      (and (= 46 b) (< 47 a 58))
                      (= 32 b)
                    )
                    b 32
                  )
                )
              )
              (cons nil l) l (append (cdr l) (list nil))
            )
          )
          ")"
        )
      )         
    )
    (vl-string->list s)
  )
)
Code: [Select]
(apply '+ (LM:PARSENUMBERS "11 + 25")) => 36
(apply '+ (LM:PARSENUMBERS "11+25"))   => 36

Maybe this is an old question: how to calc simple numeric strings without AutoCAD "CAL" (no cal in Bricscad)
I.e.: Command: (cal "10+12-6") => 16

ribarm

  • Gator
  • Posts: 3313
  • Marko Ribar, architect
Re: Arithmetic operations in numeric strings
« Reply #1 on: November 12, 2016, 06:30:39 AM »
What happens if you (arxload "geomcal.arx") or (arxload "geomcal.crx") obtained from ACAD... I suppose BricsCAD have (arxload) function... Then simply (c:cal "10+3-6") => 7
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Arithmetic operations in numeric strings
« Reply #2 on: November 12, 2016, 06:35:40 AM »
An AutoCAD .arx cannot be used in BricsCAD.

@Marc'Antonio:
I believe Gile has done some Lisp-coding for this, but I can't find it now.
You can try using the WSH.

Lee Mac

  • Seagull
  • Posts: 12928
  • London, England
Re: Arithmetic operations in numeric strings
« Reply #3 on: November 12, 2016, 07:34:51 AM »
Thanks Marc  :-)

This thread may be of interest:
https://www.theswamp.org/index.php?topic=41681.0

ribarm

  • Gator
  • Posts: 3313
  • Marko Ribar, architect
Re: Arithmetic operations in numeric strings
« Reply #4 on: November 12, 2016, 08:15:13 AM »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1454
  • Marco
Re: Arithmetic operations in numeric strings
« Reply #5 on: November 12, 2016, 08:41:38 AM »
Thanks Marc  :-)

This thread may be of interest:
https://www.theswamp.org/index.php?topic=41681.0
Very interesting!   :-)
With:
Code: [Select]
(defun _doMath ( expr / scr res )
  (if (setq scr (vla-getinterfaceobject (vlax-get-acad-object) "ScriptControl"))
      (progn
          (vl-catch-all-apply 'vlax-put-property (list scr 'language "VBScript"))
          (setq res (vl-catch-all-apply 'vlax-invoke (list scr 'eval expr)))
          (vlax-release-object scr)
          (if (not (vl-catch-all-error-p res)) res)
      )
  )
)
I get the same error on my Windows 10:
Comando: (vla-getinterfaceobject (vlax-get-acad-object) "ScriptControl")
; errore: Errore di automazione. Errore durante il caricamento dell'applicazione.


Lee Mac

  • Seagull
  • Posts: 12928
  • London, England
Re: Arithmetic operations in numeric strings
« Reply #7 on: November 12, 2016, 08:43:42 AM »
This thread may be of interest:
https://www.theswamp.org/index.php?topic=41681.0
I get the same error on my Windows 10:
Comando: (vla-getinterfaceobject (vlax-get-acad-object) "ScriptControl")
; errore: Errore di automazione. Errore durante il caricamento dell'applicazione.

I believe this method is only compatible with 32-bit systems unfortunately.  :-(

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Arithmetic operations in numeric strings
« Reply #8 on: November 13, 2016, 12:31:15 PM »
Alternative for the 'ScriptControl' code that works on x64:
Code - Auto/Visual Lisp: [Select]
  1. ; Based on: https://gist.github.com/TLMcode/0d3ad68924892ff04750
  2. ; Return value: number or nil.
  3. ; (HtmlCalc "5/2")
  4. ; (HtmlCalc "Math.PI")
  5. (defun HtmlCalc (str / html ret)
  6.   (vl-catch-all-apply
  7.     (function
  8.       (lambda ()
  9.         (setq html (vlax-get-or-create-object "htmlfile"))
  10.         (vlax-invoke
  11.           html
  12.           'write
  13.           (strcat ".<script>document.body.innerHTML=eval('" str "')</script>")
  14.         )
  15.         (setq ret (read (vlax-get (vlax-get html 'body) 'innerhtml)))
  16.       )
  17.     )
  18.   )
  19.   (if html (vlax-release-object html))
  20.   (if (numberp ret) ret)
  21. )
  22.  

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Arithmetic operations in numeric strings
« Reply #9 on: November 13, 2016, 01:04:07 PM »
Can't imagine that executing very fast BUT kudos for the outside the box thinking Roy, definitely has (other) potential.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Lee Mac

  • Seagull
  • Posts: 12928
  • London, England
Re: Arithmetic operations in numeric strings
« Reply #10 on: November 13, 2016, 02:36:44 PM »
kudos for the outside the box thinking Roy, definitely has (other) potential.

1+ Nice solution Roy.  :-)

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Arithmetic operations in numeric strings
« Reply #11 on: November 14, 2016, 03:37:54 AM »
Can't imagine that executing very fast BUT kudos for the outside the box thinking Roy, definitely has (other) potential.
Yes it is slow the first time you use it in a CAD session. I suppose the same applies to the 'ScriptControl' solution.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1454
  • Marco
Re: Arithmetic operations in numeric strings
« Reply #12 on: November 14, 2016, 04:47:39 AM »
Comando: (htmlcalc "6-3*8-2")
-20
Comando: (htmlcalc "(6-3)*(8-2)")
18
 :-)