Jump to content

Removing Leading Numbers from Elevation


ktbjx

Recommended Posts

How do I remove leading Number after the decimal point from LINE elevation?
 

(defun c:test (/ ss obj elev lay)
(setq ss (ssget (list (cons 0 "LINE"))))
 (repeat (setq x (sslength ss))
   (setq obj (ssname ss (setq x (- x 1))))
   (setq elev (caddr (cdr (assoc 10 (entget obj)))))
   (setq lay (rtos elev 2 1))
   (command "-layer" "m" lay "")
   (command "._change" obj "" "p" "la" lay "")
 )
(princ)
)

Im so stupid, I know >.<"

Edited by ktbjx
Link to comment
Share on other sites

So you want 0.1 to be .1 ? You convert to a string above code Lay = "0.1" , check 1st character if 0 then remove using "substr" and "strlen" function. Very easy.

Edited by BIGAL
Link to comment
Share on other sites

5 minutes ago, BIGAL said:

So you want 0.1 to be .1 ? You convert to a string above code Lay = "0.1" , check 1st character if 0 then remove using "substr" and "strlen" function. Very easy.

im sorry, I made a mistake about my question,
I want to remove all numbers after the decimal point.

so for your example

0.1 would be 0

1.4000 will be 1

698.345 will be 698

 

just remove all numbers after decimal

Link to comment
Share on other sites

6 hours ago, ktbjx said:

I want to remove all numbers after the decimal point.

so for your example

0.1 would be 0

1.4000 will be 1

698.345 will be 698

just remove all numbers after decimal

 

1.55 → 1 or 1.55 → 2 ?

Edited by Lee Mac
Link to comment
Share on other sites

2 hours ago, Grrr said:

Neat trick, Lee! :thumbsup:


(mapcar 
  '(lambda (x) (fix (+ 1e-8 x))) 
  '(2.1 2.9 3.14 0.15)
)
>> (2 2 3 0)

 

 

Thanks - of course, fix on its own would yield the same -

_$ (mapcar 'fix '(2.1 2.9 3.14 0.15))
(2 2 3 0)

But the inclusion of the 1e-8 'fuzz' accounts for rounding of doubles and avoids situations like this:

_$ (fix (- 8.2 0.2))
7

Though, when used in practice, one should really account for the possibility of negatives since:

_$ (fix (+ -2 1e-8))
-1

And so, perhaps a better suggestion would be:

(setq lay (itoa (fix ((if (minusp elev) - +) elev 1e-8))))

 

Edited by Lee Mac
  • Like 1
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...