Jump to content

Help with lisp: Math calculation in TEXT or Mtext


Guest

Recommended Posts

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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)
)
Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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