CADCAL: free GeomCal functionality (and more) for BricsCAD

BricsCAD is a almost perfect clone for AutoCAD, but many users are missing the GeomCal functionality. This problem is solved with the Lisp-application CADCAL, which can be downloaded for free from www.archtools.de/cadcal.zip. CADCAL brings the same functionality as GeomCal, including the possibility to use GeomCal calculations in Lisp like in (cal "PLT(end,end,/3)"). You can get an overview of CADCAL at www.archtools.de/cadcal.html.

CADCAL has some more functions than GeomCAL, i.e. PGR(<p1>,<p2>) which divides the distance between P1 and P2 in the Golden Ratio, or PCG(<p1>,<p2> ... <pn>) which returns the center of gravity of a polygon over all points in the function's argument.

And now CADCAL also can be used with a dialog and a history of previously called math expressions. The dialog is called with the command DDCAL and should be self explaining. The history of the last 30 executed math expressions is stored inside the dwg and will be restored when you reopen the dwg. All results of all math expressions in the history are stored too and can be recalled. DDCAL can be called transparently from any running CAD command, and the results of the calculations as well as the recalled results of previous results from the history list can be used directly as input to the running command. The ZIP also contains a demo DWG file with a history of CADCAL expressions for a first view at this functionality.

CADCAL is programmed in Lisp only, and therefore should work in AutoCAD, BricsCAD
and all similar CAD applications as well. CADCALs parser first translates the string containing the math expression into an evaluable Lisp expression. The user can do this too using the CC-STR->LISP function, i.e. using (CC-STR->LISP "PLD(end,end,100)"). Because any math expression needs only one single translation within the same DWG-Session, CADCAL is rather fast. In AutoCAD overall CADCAL is about 5 to 10% slower than GeomCal, and in BricsCAD because of the very fast Lisp interpreter CADCAL is about 10 times faster than GeomCal in AutoCAD.

The DDCAL functionality is new and therefore CADCAL is still in beta stadium. Please let me know what you think of CADCAL. And when you have any ideas for additional functionality, then please let me know.

Comments

  • Thanks for nice work, although I use it in a limited way, as a simple calculator (I do not like standard ones). I was thinking about creating something similar with much smaller functionality. I wonder if you are planning to commercialise this program, i.e. do I need to still think about my own version 🙂?

    As far as functionality, for my own purposes I added possibility of using dot/comma as number delimiter and loading results into clipboard.

  • Hello jbn1,

    using comma instead of dot as a decimal limiter will not work, since then the comma as a limiter between arguments in the argument list would no longer work. And using another limiter than a comma for the argument list would destroy compatibility with GeomCal.

    I do'nt believe that CADCAL can be sold commercially, but source code licenses are available. Many companies used GeomCAL calculations in scripts to create simple parametric drawings, others used CAL expressions in Lisp. Without CADCAL all their old work would be lost.

    I did offer CADCAL to Bricsys for integration into BricsCAD, but they are not interested.

    Cheers, Tom

  • For simple maths calculation a nice one by the great Lee-Mac. I am pretty sure there is a more advanced version out there also.

    ; thanks to Lee-mac for this defun
    ; www.lee-mac.com
    ; 44 is comma
    ; 42 is *
    ; 43 is +
    ; 45 is -
    ; 47 is / forward slash
    ; 92 is \ backward slash
    ; 32 is a space
    (defun _csv->lst ( str del / pos )
    (if (setq pos (vl-string-position del str))
    (cons (substr str 1 pos) (_csv->lst (substr str (+ pos 2)) del))
    (list str)
    )
    )

    (defun math1 ()
    (setq lst (_csv->lst ans 43))
    (princ (+ (atof (nth 0 lst))(atof (nth 1 lst))))
    )

    (defun math2 ()
    (setq lst (_csv->lst ans 42))
    (princ (* (atof (nth 0 lst))(atof (nth 1 lst))))
    )

    (defun math3 ()
    (setq lst (_csv->lst ans 45))
    (princ (- (atof (nth 0 lst))(atof (nth 1 lst))))
    )

    (defun math4 ()
    (setq lst (_csv->lst ans 36))
    (princ (/ (atof (nth 0 lst))(atof (nth 1 lst))))
    )

    (defun c:Math ()
    (setq ans (getstring "enter string "))
    (setq ans (VL-STRING-TRANSLATE "/" "$" ans))
    (cond
    ((/= (vl-string-position 43 ans) nil)(math1))
    ((/= (vl-string-position 45 ans) nil)(math3))
    ((/= (vl-string-position 42 ans) nil)(math2))
    ((/= (vl-string-position 36 ans) nil)(math4))
    )
    (princ)
    )

  • Thanks for information, however this calculator is too simple for my purposes, but may be a starting point. I thought rather about something like reverse polish notation converter with additional functions.

  • ALANH
    edited June 9

    Google I am sure I have seen (1 + 2)/(3 + 5) it was under convert formula to lisp.

    Maybe start here https://www.theswamp.org/index.php?topic=41681

  • Thanks again, good start point.

  • I have the feeling that you all missed the essential point of GeomCal and CADCAL: these programs do vector calculations too, and this can immensely increase the productivity of any CAD user.

    A simple sample: calculate and "osnap" to the point at 1/3 of the distance between p1 and p2:

    The vector between P1 and p2 simply is "p2-p1", and a vector 1/3 of that length is "(p2-p1)/3". And the point which we are trying to osnap to is "p1+ (p2-p1)/3". And you can use this formula directly, when you have the points p1 and p2 bound to their variables. This done with "p1=end" and "p2=end". The "end" function in GeomCal and CADCAL prompts the user to pick a endpoint with the cursor.

    When you want to "osnap" the startpoint of a line to that point, you can call GeomCal or CADCAL transparently from the running LINE command.

    And instead of binding the points p1 and p2 to variavbles, you can just as well use multiple "end" calls in your formula. Each single "end" aks the user to pick a endpoint, and uses this point for the calculation. So you simply can use:

    : line
    Start of line: 'cal
    CC ?=help >> expression: end+(end-end)/3

    Instead of 'CAL you can now also use 'DDCAL to use the dialog driven version of CAL.

  • I am aware that that simple calculator is small part of CAL possibilities, but this part is most interesting for my purposes. Anyhow thank you for explanation.

  • Very rarely a CAD user needs simple numbers as input to CAD commands, and in all of these cases you can easily enter a simple Lisp function. I don't speak about "programming" Lisp, but simply to use the Lisp syntax for calculations like in (+ 2 3). If Lisp is too complicated for you, then you can use any "pocket" calculator, and there are millions available as freeware.

    So for your purposes there are plenty of solutions readily available. GeomCaL and CADCAL aim at completely different purposes.

  • You are correct some of the cal function get very involved regarding 3d function directions and solve for a 3D point etc. Yes I have the R12 paper copy Chapter 4, some 16 pages of help. There are some very complex solutions. Let Cal work them out.

    Some of the basics like M2P is now built in = "p1+ (p2-p1)/2" in cal it was called something else, so M3P could be done simply using a lisp defun.

    (defun c:M3P ( / p1 p2)
    (setq p1 (getpoint "\nPick point 1 ")
    p2 (getpoint p1 "\nPick point 2 ")
    )
    (setq p3 (polar p1 (angle p1 p2) (/ (distance p1 p2) 3.)))
    (princ)
    )

    Its probably these more basic calculations wanted rather than having to type a calculation.

    a transparent use example

    Line 'm3p pick2points !p3

  • Indeed GeomCal was not widely used despite that it was included with AutoCAD since many years. I always wondered, why CAD users did not use this tool, since for what I do sometimes, it is very helpful and makes me much more productive. One reason for not using GeomCal probably is that CAD users would have to remember the functions of GeomCal. I wanted to solve this problem with he DDCAL front end.

    Most engineers know their math very well, but don't know much about programming. I know some very big international companies where engineers used GeomCal for calculations in scripts, and so enabling parametric design via scripts. The CAD users then use these scripts to create complex drawings. For one of these companies CADCAL was the reason to switch from AutoCAD to BricsCAD. Without CADCAL all there old scripts using GeomCal would have become worthless.

    In the next version (coming within a week or so) of CADCAL users can export the history to a script, which can be run by the SCRIPT command inside AutoCAD or BricsCAD. But when the users use the CALSCRIPT command instead, the drawing produced by the script can be modified parametrically. And other than the SCRIPT command the CALSCRIPT accepts user input within the script. Even when another user has nothing but a DWG file containing such parametric parts he will be able to modify the parametric properties and so modify the parts, even when he does not have the script.

    And then there is another feature especially targeting at programmers. There will be a SCRIPT→LISP command which translates those scripts into pure Lisp, which can be used in any Lisp code.

  • ALANH
    edited June 15

    Years ago another cad package had macro record and it wrote VBA code, think Excel. For programmers like me Acad's macro record is pretty useless and wonder why they did it. Perhaps Bricscad could introduce a macro record that is useable.