Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Random glitch ???

7 REPLIES 7
Reply
Message 1 of 8
DC-MWA
715 Views, 7 Replies

Random glitch ???

Hi all,

I have this little lisp that is part of a larger lisp I am working on.

Basically it gets the viewport scale and displays it either 1/16"=1'-0"  or  1"=20' depending on the scale factor.

It keeps glitching out on 360 (1"=30') and 720 (1"=60')

On the 360 it displays 1/32, 1/32 is 384?

I've tried using cond statement and if.

I'm hoping it's something obvious I'm missing.

See attached lisp

7 REPLIES 7
Message 2 of 8
Kent1Cooper
in reply to: DC-MWA

That may be one of those things resulting from calculation functions, in which the result could be something like 360.000000000000427, in which case the (=) function, which requires precise equality, will not  recognize it as equal to 360.  If that's the cause, the solution is to use (equal) with a small fuzz factor, rather than (=).  And since the scale factors are all multiples of 120, you don't need to list all of them separately.  Try replacing your long (or) function listing all those factors with this:

 

  (if (equal (rem vp_scale 120.0) 0.0 1e-4)

    (progn ….

Kent Cooper, AIA
Message 3 of 8
DC-MWA
in reply to: Kent1Cooper

Well,

I love the simplified code.. but..

360 still displays 1/32

and 720 displays 1/64...

????

 

Message 4 of 8
DC-MWA
in reply to: Kent1Cooper

Well it looks like 720 does actually calculate to 719.9999999999

So i tried to fool it with  (and (> vp_scale 719.0)(< vp_scale 721.0)) ... no luck

 

360 calculates out to 360.000000000 ???

Message 5 of 8
DC-MWA
in reply to: Kent1Cooper

I got this to work... seems a little hap-hazard though..

(if (or (= vp_scale 120.0)(= vp_scale 240.0)(and (> vp_scale 359.75)(< vp_scale 360.25))(= vp_scale 480.0)(= vp_scale 600.0)(and (> vp_scale 719.75)(< vp_scale 720.0))(= vp_scale
840.0)(= vp_scale 960.0)(= vp_scale 1200.0))

Message 6 of 8
ronjonp
in reply to: DC-MWA

Here's another way to skin the cat 🙂

(if (vl-some '(lambda (x) (equal x vp_scale 1e-4)) '(120 240 360 480 600 720 840 960 1200))
  (progn (setq vp_scale1 (strcat "1\" = " (rtos (/ vp_scale 12) 2 0) "\'")) (princ vp_scale1))
  (progn (setq vp_scale1 (strcat (rtos (/ 1 (* vp_scale (/ 1.0 12))) 4) " = 1\'-0\""))
	 (princ vp_scale1)
  )
)
Message 7 of 8
DC-MWA
in reply to: ronjonp

I'll try it.

Thanks!

Message 8 of 8
ronjonp
in reply to: DC-MWA


@DC-MWA wrote:

I'll try it.

Thanks!


Glad to help :). You could also use Kent's recommendation and test for two possible values. 

(setq vp_scale 719.9999999999)
(or (equal (rem vp_scale 120.) 0 1e-4) (equal (rem vp_scale 120.) 120 1e-4))
;; Example below what the two values return with REM
(alert (vl-princ-to-string (rem 719.9999999999 120.)))
(alert (vl-princ-to-string (rem 720.0000000001 120.)))

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Autodesk Design & Make Report