Jump to content

Help with lisp: Math calculation in TEXT or Mtext


Recommended Posts

Posted (edited)

Hi, I am using this code to do calculation in text or mtext

 

for example, I have a text

 

6.00*8.00*2.70 + 6.00*8.00*(3.90-2.70)*1/3 + 1.70*3.00*2.38

 

and convert the text to the result 

 

160.94

 

The problem is sometimes gives this error and I don't know why?

 

; error: no function definition: CAL

 

 

Here is the code I use

 

(defun c:cal2 (/ e)
  (setq e (car (entsel "\Select text or mtext: ")))
  (setq e (vlax-ename->vla-object e))
  (vlax-property-available-p e 'textstring)
  (vla-put-textstring e (atof (rtos(cal (vla-get-textstring e)) 2 2)))
  (princ)
)

 

 

Thanks

 

Edited by prodromosm
Posted (edited)

Where is the "cal" function?

(cal (vla-get-textstring e))

Edited by 1958
  • Agree 1
Posted

If I run cal (autocad calculator) and do one simple calculation for example  3+2=5 then the lisp work without error. I don't kanow why this  code stop work. In the begining befor 2 years this code works fine. Any options?

 

Thanks

Posted

Thanks Tsuky. I add this line and I think is working. I will test it more. Thanks

 

(defun c:cal2 (/ e)
  (setq e (car (entsel "\Select text or mtext: ")))
  (setq e (vlax-ename->vla-object e))
  (vlax-property-available-p e 'textstring)
  (arxload "geomcal")
  (vla-put-textstring e (atof (rtos(cal (vla-get-textstring e)) 2 2)))
  (princ)
)
Posted

Pretty sure there is a formula lisp, you enter formula and it works it out rather than CAL.

Posted

You must load the application using the expression (arxload "geomcal")

Posted (edited)

Sorry, I already saw that it was also recommended by Tsuky

Edited by robierzo
Posted
15 hours ago, prodromosm said:

 

(vla-put-textstring e (atof (rtos(cal (vla-get-textstring e)) 2 2)))

 

 

Copy and paste does not work most of the time without understanding the procedure of codes at least, so here is the missing part of your codes.

 

(c:cal (vla-get-textstring e)) ;; note the c: before the cal command name

 

Posted (edited)
1 hour ago, Tharwat said:

 

Copy and paste does not work most of the time without understanding the procedure of codes at least, so here is the missing part of your codes.

 

(c:cal (vla-get-textstring e)) ;; note the c: before the cal command name

 

 

 

It works both ways for me, with a 'c:' and without it, AutoDesk help shows it both ways.

Edited by Steven P
  • Thanks 1
Posted

So this routine is fixed in this instance but it doesn't explain why it worked sometimes and not sometimes.

 

I might take a guess that you use some other calculations and if you haven't used one before in that session then 'geomcal' isn't loaded yet.

 

"; error: no function definition: CAL" tells us that the function 'CAL' hasn't been loaded into memory for that drawing.. if you get a similar error in the future it means even if you have it saved in a file somewhere it still needs loading for the LISP to use it.

 

Posted

Hi Steven P. I explain that cal command is Autocad cal command. I have no extra cal command to load. When i add this line

 

(arxload "geomcal")

 

The problem solved. I will add and Tharwat suggestion

 

(vla-put-textstring e (atof (rtos(c:cal (vla-get-textstring e)) 2 2)))

 

Thanks

Posted
1 hour ago, prodromosm said:

Hi Steven P. I explain that cal command is Autocad cal command. I have no extra cal command to load. When i add this line

 

(arxload "geomcal")

 

 

.... OK.... so don't load the command with arxload....

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