Jump to content

Recommended Posts

Posted (edited)

 

I am trying to set a variable with distance between 2 points. I am getting 2 points from user input but when I try to convert to feet (2nd line of code)

I am getting an error.  I cannot figure out what is wrong with this:
 

(setq distpcc (rtos(distance pt1 pt2) 2 8))
(setq distpcc2 (/ distpcc 12 ))

 

Thanks

Edited by Tbag
Posted

If you could post your whole code, that would be helpful.

 

Something like this maybe?

(defun c:ttt (/ P1 P2 Z1 Z2)
    (setq Pt1 (getpoint "\nSelect First Point"))
    (setq Pt2 (getpoint "\nSelect Second Point"))
    (setq Z1 (nth 2 Pt1))
    (setq Z2 (nth 2 Pt2))
    (setq VAL (rtos (- Z1 Z2)))
  )

 

Posted

I would like to divide distpcc variable in (setq distpcc (rtos(distance pt1 pt2) 2 8))  by 12

so I added (setq distpcc2 (/ distpcc 12 ))

but It does not work. Is it because distpcc is a string and it is not a real number?

Thanks,.

 

 

Posted (edited)
;Original Code:
(setq distpcc (rtos(distance pt1 pt2) 2 8))
(setq distpcc2 (/ distpcc 12 ))


;Just dont convert it to a string, do the following.
(setq distpcc2 (/ (distance pt1 pt2) 12.0))

;Also you should use decimal when dividing

;Test the following 
(rtos (/ 1 12) 2 8)
;versus
(rtos (/ 1.0 12.0) 2 8)

 

Edited by Hippe013
Posted
10 hours ago, Tbag said:

Is it because distpcc is a string and it is not a real number?

 

Simply put, you cannot perform an arithmetic function on a string stype value.

Unless of course you are working on some other programming language where the symbol  "+" also means concatenate. 

 

 

Posted
On 6/16/2020 at 3:26 PM, Hippe013 said:

;Original Code:
(setq distpcc (rtos(distance pt1 pt2) 2 8))
(setq distpcc2 (/ distpcc 12 ))


;Just dont convert it to a string, do the following.
(setq distpcc2 (/ (distance pt1 pt2) 12.0))

;Also you should use decimal when dividing

;Test the following 
(rtos (/ 1 12) 2 8)
;versus
(rtos (/ 1.0 12.0) 2 8)

 

Thanks so much, very helpful.

 

Posted
On 6/17/2020 at 1:07 AM, pBe said:

 

Simply put, you cannot perform an arithmetic function on a string stype value.

Unless of course you are working on some other programming language where the symbol  "+" also means concatenate. 

 

 

Thanks. makes sense.

 

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