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

the while function

8 REPLIES 8
Reply
Message 1 of 9
Anonymous
276 Views, 8 Replies

the while function

could someone explain this please 

 while (<= (setq N (getint "\nNumber of bolt holes per side [N >= 3] : ")) 2))

 

what is meant by <= and [N]  >3] and the number 2

 

 

 

 thanks 

 

8 REPLIES 8
Message 2 of 9
pbejse
in reply to: Anonymous


@Anonymous wrote:

could someone explain this please 

 while (<= (setq N (getint "\nNumber of bolt holes per side [N >= 3] : ")) 2))

 

what is meant by <= and [N]  >3] and the number 2

 

 

 

 thanks 

 


(<= [input] 2)

 

if the result of the user input integer is Less Than or Equal 2. Statement is true and while will proceed and continue the loop/

 

as for [N >= 3] .. the program is reminding the user that N should not be more than or equal 3

 

 

 



 

Message 3 of 9
Anonymous
in reply to: pbejse

brilliant just as i thought, im getting the hang of this quicker than i thought 😄

Message 4 of 9
pbejse
in reply to: Anonymous


@Anonymous wrote:

brilliant just as i thought, im getting the hang of this quicker than i thought 😄



Good for you paul128

 

Cheers

 

Message 5 of 9
Anonymous
in reply to: pbejse

i have another question 

 

(setq p1 (polar (polar C (cvunit 240.0 "degrees" "radians") L) pi L)) what does the L) pi  L)) mean?

 

I know that its saying set P1 as the center point? and telling autocad to covert 240 degrees into radian measurement but what does the L and PI represent? I understand pi as 3.14? is that corect?

 

also (setq p2 (polar p1 pi (* 2.0 L))) what does the 0.0 and the (* 2.0 L ) - > that means 2.0 times by length? 

Message 6 of 9
pbejse
in reply to: Anonymous


@Anonymous wrote:

i have another question 

 

(setq p1 (polar (polar C (cvunit 240.0 "degrees" "radians") L) pi L)) what does the L) pi  L)) mean?

 

I know that its saying set P1 as the center point? and telling autocad to covert 240 degrees into radian measurement but what does the L and PI represent? I understand pi as 3.14? is that corect?

 

also (setq p2 (polar p1 0.0 (* 2.0 L))) what does the 0.0 and the (* 2.0 L ) - > that means 2.0 times by length? 


P1 will be the new point after evaluation
(cvunit 240.0 "degrees" "radians") - > You are correct , polar function requires an angle argument in radians
you can also use (* pi (/ 240.0 180.0))
L is variable representing distance -> third argument for polar function
pi is 180 degrees

 

so 0.0 is angle 0 degress

 (* 2.0 L ) - > that means 2.0 times by length?  <--- Correct

 

Message 7 of 9
Anonymous
in reply to: pbejse

brilliant slowly getting there 🙂

Message 8 of 9
Anonymous
in reply to: pbejse

pbejse this is where i get really confused 

 

(setq inpl (entmakex (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline") '(90 . 4) '(70 . 1)

                              (cons 10 p1) (cons 10 p2) (cons 10 p3) (cons 10 p4) '(210 0.0 0.0 1.0)

                       )

             )

  )

 

why are the brackets stepped like that? and the the whole setq line  and especiually the end number 210. 0.0 0.0 1.0 what do they represent. and entmakex is ... 

 

thanks for your time

Message 9 of 9
Kent1Cooper
in reply to: Anonymous


@Anonymous wrote:

.... 

why are the brackets stepped like that?....


I didn't find an obvious place in the AutoLISP reference documents that explains the stepping approach, or I would have referred you there, but briefly:

 

Indenting parentheses is optional, but a lot of people use it to help keep visual track of which parentheses go with which, to make it easier to "read" what's going on and to notice if you're missing parentheses.  Some use tabs for indenting, but because that often forces word wrapping unnecessarily, I prefer to use two spaces per indentation level [one space doesn't seem visually obvious enough].  Some also add comments to at least some of the right parentheses, identifying which function they are closing.

 

You could do this:

 

(if (and (or (test1) (test2) (test3)) (< numberA numberB) (and (test4) (test5))) (doA) (progn (doB) (alert "You idiot!")))

 

But most people find it easier to "read" what's happening if you do the same thing something like this:
 

(if

  (and

    (or (...test1...) (...test2...) (...test3...))

    (< numberA numberB)

    (and (...test4...) (...test5...))

  ); end and

  (...doOperationA...); 'then'

  (progn ; 'else'

    (...doOperationB...)

    (alert "You idiot!")

  ); end progn

); end if

 

[See the entries for (if), (and), (or) and (progn) in the AutoLISP Reference to understand better what they're doing in this silly example.]

 

In the example you cited, I would do the indenting differently, so that at least any right parenthesis on its own line is in the same horizontal position as the left parenthesis that opens the function it's closing, which to me is an important part of the readability purpose of it all.

Kent Cooper, AIA

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

Post to forums  

Autodesk Design & Make Report

”Boost