Arraypath with various step values

Arraypath with various step values

Anonymous
Not applicable
6,155 Views
41 Replies
Message 1 of 42

Arraypath with various step values

Anonymous
Not applicable

Hi,

I would create a LISP that draw a circle at the starting or ending point (depends where I click) of a existing line.

Then with this circle I would do an ARRAYPATH but with different value of distance between the circles. The value of the distance should be taken from a fixed pool of values.

 

Example

1. I click on the line in the side where I want the circle (with fixed radius)

2. LISP command draws the circle

3. LIPS command draws a second circle "VAR1" unit far from the first circle, LIPS command draws a third circle "VAR2" unit far from the second circle, and so on until the end of the line/path.

 

"VAR1" "VAR2" "VAR3"... are fixed values that the command should take randomly.

It could be plus if I could edit manually some values of distance (maybe with something like a input text box between the circles).

 

Is it possible to do this? Maybe at the least without the random distance value?

Where I could find guide of the ARRAYPATH parameters?

 

Thank you

 

PS: I would change the default distance of the arraypath command. There isn't any system variable to change? I see only solutions with "actions recording" or "lisp" for this...and it can't be!!!😅

 

 

0 Likes
Accepted solutions (2)
6,156 Views
41 Replies
Replies (41)
Message 21 of 42

Kent1Cooper
Consultant
Consultant

@pbejse wrote:

.... I guess "random" means any order of the four given distance [ 15 18 21 24 ] but no repeats Yes? ....


I hope not, because that would directly contradict Message 3.  So I'll be interested in what the intent really is -- it would have been better to have it all spelled out in detail from the beginning.

Kent Cooper, AIA
0 Likes
Message 22 of 42

pbejse
Mentor
Mentor

@Kent1Cooper wrote:

it would have been better to have it all spelled out in detail from the beginning.


 

Yes, and to quote @devitg

- For better understanding, and maybe get further help, please upload such sample.dwg -

🙂

 

**Off Topic***

From the month of October til today , our friend @devitg posted that same reply, an estimated number of 10 times .

Because you need to know 🙂

 

Message 23 of 42

Anonymous
Not applicable

Random "means" a random choice of one of setted distances. So "randomly" you could have also the same step distance for adjacent instances.

In my case only could be useful change manually some "distance step" with a custom lenght after the command. The change should take effect also on the following circles moving them along the path.

0 Likes
Message 24 of 42

Anonymous
Not applicable

Here below, what would be the optimal solution in my case.

 

Picture 01:

Draw the circles with random choice of a value from a pool of distance.

Picture 02:
Ability to edit manually one or more step with a custom value

Picture 03:
All circles are moved considering the new distance.

NOTE: The circles must remain along the path after the manually editing, it's a photo editing error

Hope this can be much clearer than my english😅

0 Likes
Message 25 of 42

pbejse
Mentor
Mentor

@Anonymous wrote:

All circles are moved considering the new distance.


That explains why you wanted Arraypath.

But anyway, the "move" can still be incorporated in the code if needed.

 

 

0 Likes
Message 26 of 42

ВeekeeCZ
Consultant
Consultant
Accepted solution

Try this if it helps. It's make-edit for the time being document open and created by this version of the routine.

 

(vl-load-com)

(defun c:ArrayOfCirclesRandom ( / LM:rand LM:randrange r d i p1 p2 dl d1 d2 o1 o2 el)
  
  ;; Rand  -  Lee Mac
  ;; PRNG implementing a linear congruential generator with
  ;; parameters derived from the book 'Numerical Recipes'
  
  (defun LM:rand ( / a c m )
    (setq m   4294967296.0
	  a   1664525.0
	  c   1013904223.0
	  $xn (rem (+ c (* a (cond ($xn) ((getvar 'date))))) m))
    (/ $xn m))
  
  (defun LM:randrange ( a b )
    (+ (min a b) (fix (* (LM:rand) (1+ (abs (- a b)))))))
    
  ; ----------------------------------------------------------------------
  
  (setq r 2.  				; radius
	d '(10 8 5 3.5 3.5)		; distances
	i -1
	dl 0)
  
  (and (setq p1 (getpoint "\nPlace initial circle: "))
       (setq p2 (getpoint p1 "\nPlace last circle: "))
       (or (setq pl (car (nentselp p1)))
	   (setq pl (car (nentselp p2))))
       (setq p1 (vlax-curve-getClosestPointTo pl (trans p1 1 0)))
       (setq d1 (vlax-curve-getDistAtPoint pl p1))
       (setq p2 (vlax-curve-getClosestPointTo pl (trans p2 1 0)))
       (setq d2 (vlax-curve-getDistAtPoint pl p2))
       (if (< d1 d2)
	 (setq o1 < o2 +)
	 (setq o1 > o2 -))
       (entmake (list (cons 0 "CIRCLE") (cons 10 p2) (cons 40 r)))
       (princ (strcat "\nOverall length: " (rtos (abs (- d2 d1)) 2 3) "\nIn between: "))
       (while (o1 d1 d2)
	 (setq el (cons (cons (entmakex (list (cons 0 "CIRCLE") (cons 10 (vlax-curve-getPointAtDist pl d1)) (cons 40 r))) dl) el)
	       d1 (o2 d1 (setq dl (nth (LM:randrange 0 (1- (length d))) d))))
	 (princ (vl-princ-to-string (cdar el))) (princ " - "))
       (setq *aocr-sde* (cons (list pl o1 o2 p1 p2) (reverse el))))
  (princ)
  )



(defun c:ArrayOfCirclesEdit ( / el en as pl o1 o2 p1 p2)
  
  (and (or *aocr-sde*
	   (prompt "Error: No previous setting found!"))
       (setq el (cdr *aocr-sde*))
       (setq en (car (entsel "\nPick a circle to move: ")))
       (or (setq as (assoc en el))
	   (prompt "Error: Object wasn't identified!"))
       (not (initget (+ 1 2 3)))
       (setq el (subst (cons (car as) (getreal (strcat "\nSet new distance for " (vl-princ-to-string (cdr as))" to: "))) as el))
       (setq el (vl-remove-if-not '(lambda (e) (and (car e) (entget (car e)))) el))
       (setq *aocr-sde* (cons (car *aocr-sde*) el))
       (mapcar 'set '(pl o1 o2 p1 p2) (car *aocr-sde*))
       (setq d1 (vlax-curve-getDistAtPoint pl p1))
       (setq d2 (vlax-curve-getDistAtPoint pl p2))
       (foreach e el
	 (if (o1 d1 d2)
	   (entmod (append (entget (car e)) (list (cons 10 (vlax-curve-getPointAtDist pl (setq d1 (o2 d1 (cdr e))))))))
	   (entdel (car e))))
       )
  (princ)
  )

 

Message 27 of 42

ВeekeeCZ
Consultant
Consultant

Since the previous routine edits only the last one, here is a more general routine to move objects along a path.

 

(vl-load-com)

(defun c:MoveAlongPath ( / s ps pl p1 p2 ds d1 d2 o2 i e p)
  
  (if (and (setq s (ssget '((0 . "POINT,CIRCLE,INSERT"))))
	   (setq ps (entsel "\nSelect path: "))
	   (setq pl (car ps))
	   (setq p1 (trans (cadr ps) 1 0))
	   (setq p1 (vlax-curve-getClosestPointTo pl p1))
	   (setq p2 (getpoint (trans p1 0 1) "\n2nd point to determine a direction: "))
	   (setq p2 (vlax-curve-getClosestPointTo pl (trans p2 1 0)))
	   (setq ds (getdist "\nSpecify delta length: "))
	   (setq d1 (vlax-curve-getDistAtPoint pl p1))
	   (setq d2 (vlax-curve-getDistAtPoint pl p2))
	   (setq o2 (if (< d1 d2) + -))
	   )
    (repeat (setq i (sslength s))
      (setq e (ssname s (setq i (1- i))))
      (if (setq p (vlax-curve-getPointAtDist pl (o2 (vlax-curve-getDistAtPoint pl (vlax-curve-getClosestPointTo pl (cdr (assoc 10 (entget e))))) ds)))
	(entmod (append (entget e) (list (cons 10 p))))
	(entdel e)))
    )
  (princ)
  )

 

Message 28 of 42

Anonymous
Not applicable

Absolutely lovely! 😁
I owe you a beer!🍺

0 Likes
Message 29 of 42

Anonymous
Not applicable

Hi,

 

using this routine there is no control on the last step/distance

mega-mini_0-1606397797904.png

 

Do you think could be possible to set the function to try several times to create the series of circles until the last distance is within the two value?

example: (taking a look on the image above) if the values ​​were 31 and 35, the first array would be good, the second would be erase and do again.

 

These two values ​​and the times the routine should try to do the operation can be fixed within the code (it is not necessary to enter them every time in the dialog box).

I know it's not always possibile have "a correct sequence of random distances" to get a good/valid value for the last distance, for this reason I decided to set a maximum of attempts. If no one of these attempts is valid, the routine will draw the last "sequence of random distances".
It could be very useful if in case of "no solution/not found a correct sequence of random distances" the last two circles changed color.

mega-mini_0-1606399389273.png



Thank you for any help!

0 Likes
Message 30 of 42

Anonymous
Not applicable

I know this is not the correct language, I wrote this just to explain better, I hope someone can help me "translate" it into LISP.

I don't know the LISP language well, I hope I put the fake-code in the correct places.

 

 

 

 

 

 

(vl-load-com)

(defun c:ArrayOfCirclesRandom ( / LM:rand LM:randrange r d i p1 p2 dl d1 d2 o1 o2 el)

  ;; Rand  -  Lee Mac
  ;; PRNG implementing a linear congruential generator with
  ;; parameters derived from the book 'Numerical Recipes'

  (defun LM:rand ( / a c m )
    (setq m   4294967296.0
	  a   1664525.0
	  c   1013904223.0
	  $xn (rem (+ c (* a (cond ($xn) ((getvar 'date))))) m))
    (/ $xn m))

  (defun LM:randrange ( a b )
    (+ (min a b) (fix (* (LM:rand) (1+ (abs (- a b)))))))

  ; ----------------------------------------------------------------------

  (setq r 15  				; radius
	d '(30 32 34 35)  	; distances
	i -1
	dl 0)

; SET MAX ATTEMPTS (example: max_attempts=10)
; SET A COUNTER FOR ATTEMPTS TO 0 (example: count=0)
; SET MINIMUN ACCEPTABLE VALUE DISTANCE FOR LAST CIRCLE (example: min_dist=31)
; SET MAXIMUN ACCEPTABLE VALUE DISTANCE FOR LAST CIRCLE (example: max_dist=36)


    
  (and (setq p1 (getpoint "\nPlace initial circle: "))
       (setq p2 (getpoint p1 "\nPlace last circle: "))
       (or (setq pl (car (nentselp p1)))
	   (setq pl (car (nentselp p2))))
       (setq p1 (vlax-curve-getClosestPointTo pl (trans p1 1 0)))
       (setq d1 (vlax-curve-getDistAtPoint pl p1))
       (setq p2 (vlax-curve-getClosestPointTo pl (trans p2 1 0)))
       (setq d2 (vlax-curve-getDistAtPoint pl p2))
       (if (< d1 d2)
	 (setq o1 < o2 +)
	 (setq o1 > o2 -))

; TRY DO DRAW A VALID ARRAY
; SET array_valid=false
;do until array_valid=true 

;        count=count+1
     
       (entmake (list (cons 0 "CIRCLE") (cons 10 p2) (cons 40 r)))
       (princ (strcat "\nOverall length: " (rtos (abs (- d2 d1)) 2 3) "\nIn between: "))
       (while (o1 d1 d2)
	 (setq el (cons (cons (entmakex (list (cons 0 "CIRCLE") (cons 10 (vlax-curve-getPointAtDist pl d1)) (cons 40 r))) dl) el)
	       d1 (o2 d1 (setq dl (nth (LM:randrange 0 (1- (length d))) d))))


;      if (last_distance>min_dist) and (last_distance>max_dist) do
;         array_valid=true
;      else if (count<max_attempts)
;          delete the previous array so I can try again
;      else if (count=max_attempts)             
;          draw last array 
;          change the color to the last two circle
;          array_valid=true 


          
	 (princ (vl-princ-to-string (cdar el))) (princ " - "))
       (setq *aocr-sde* (cons (list pl o1 o2 p1 p2) (reverse el))))
  (princ)
  )

 

 

 

 

 

 

 

0 Likes
Message 31 of 42

ВeekeeCZ
Consultant
Consultant

Ok, thanks. It might help. I'll look at that at some point.

0 Likes
Message 32 of 42

ВeekeeCZ
Consultant
Consultant

You still owe me a beer from my last attempt.

 

(defun c:ArrayOfCirclesRandom2 ( / LM:rand LM:randrange r d i p1 p2 dl d1 d2 o1 o2 el done dx-mix dxmax a)

  ;; Rand  -  Lee Mac
  ;; PRNG implementing a linear congruential generator with
  ;; parameters derived from the book 'Numerical Recipes'

  (defun LM:rand ( / a c m )
    (setq m   4294967296.0
	  a   1664525.0
	  c   1013904223.0
	  $xn (rem (+ c (* a (cond ($xn) ((getvar 'date))))) m))
    (/ $xn m))

  (defun LM:randrange ( a b )
    (+ (min a b) (fix (* (LM:rand) (1+ (abs (- a b)))))))

  ; ----------------------------------------------------------------------

  (setq r 15  				; radius
	d '(30 32 34 35)  	; distances
	i -1
	dx-min 31
	dx-max 36
	a 10)
   
  (and (setq p1 (getpoint "\nPlace initial circle: "))
       (setq p2 (getpoint p1 "\nPlace last circle: "))
       (or (setq pl (car (nentselp p1)))
	   (setq pl (car (nentselp p2))))
       (setq p1 (vlax-curve-getClosestPointTo pl (trans p1 1 0)))
       (setq d1 (vlax-curve-getDistAtPoint pl p1))
       (setq p2 (vlax-curve-getClosestPointTo pl (trans p2 1 0)))
       (setq d2 (vlax-curve-getDistAtPoint pl p2))
       (if (< d1 d2)
	 (setq o1 < o2 +)
	 (setq o1 > o2 -))
       (setq l (abs (- d2 d1)))

       (while (not done)
	 (setq x (nth (LM:randrange 0 (1- (length d))) d))
	 (setq dx (- l (+ d1 (apply '+ dl) x)))
	 (princ (strcat "\n" (rtos x 2 0) " for " (rtos dx 2 0)))

	 (cond ((< dx-min dx dx-max)		;; within the range
		(setq dl (cons dx dl)		;; add left length
		      done T))			;; done

	       ((> dx dx-max)			;; gap is still more than max
		(setq dl (cons x dl)		;; add length 
		      done nil))		;; not done yet

	       (T				;; gap is less than min
		(setq a (1- a)			;; lower the counter
		      dl nil)			;; reset length list
		(setq done (zerop a))))		;; done if reached max of attempts, else keep going
	 (print dl)
	 dl)
       (princ (strcat "by " (itoa a)))
       (foreach x (setq dl (cons 0 (reverse dl)))
	 (setq el (cons (cons (entmakex (list (cons 0 "CIRCLE") (cons 10 (vlax-curve-getPointAtDist pl (setq d1 (o2 d1 x)))) (cons 40 r))) x) el)))
       ;(princ (vl-princ-to-string dl))
       (setq *aocr-sde* (cons (list pl o1 o2 p1 p2) (reverse el))))
  (princ)
  )

 

0 Likes
Message 33 of 42

ВeekeeCZ
Consultant
Consultant

Some edits. Fixed last circle, better user listing, routine rearranged and variables renamed hopefully be more readable.

Also added an expression to possibly set 'min and 'max last gap from actual list of delta distances.

 

(vl-load-com)

(defun c:ArrayOfCirclesRandom2 ( / LM:rand LM:randrange rad dlt-lst1 pnt1 pnt2 dlt-lst2 dst1 dst2 opr1 opr2 ents-lst gap gap-min gap-max itr-max done)
  
  (setq rad 		15
	dlt-lst1 	'(30 32 34 35)
	gap-min 	31					;; also possible: (apply 'min dlt-lst1)
	gap-max 	36					;; also possible: (apply 'max dlt-lst1)
	itr-max 	99)
  
  ;; Random  -  Lee Mac           
  (defun LM:rand ( / a c m )
    (setq m   4294967296.0 a 1664525.0 c 1013904223.0
	  $xn (rem (+ c (* a (cond ($xn) ((getvar 'date))))) m))
    (/ $xn m))
  
  (defun LM:randrange ( a b ) (+ (min a b) (fix (* (LM:rand) (1+ (abs (- a b)))))))
  
  ; -----------------------------
  
  (and (setq pnt1 (getpoint "\nPlace initial circle: "))
       (setq pnt2 (getpoint pnt1 "\nPlace last circle: "))
       (or (setq ent (car (nentselp pnt1)))
	   (setq ent (car (nentselp pnt2))))
       
       (setq pnt1 (vlax-curve-getClosestPointTo ent (trans pnt1 1 0)))
       (setq dst1 (vlax-curve-getDistAtPoint ent pnt1))
       (setq pnt2 (vlax-curve-getClosestPointTo ent (trans pnt2 1 0)))
       (setq dst2 (vlax-curve-getDistAtPoint ent pnt2))
       (setq len-tot (abs (- dst2 dst1)))
       
       (if (< dst1 dst2)						;; if line is reversed
	 (setq opr1 < opr2 +)
	 (setq opr1 > opr2 -))     
       
       (while (not done)
	 (setq dlt (nth (LM:randrange 0 (1- (length dlt-lst1))) dlt-lst1)
	       gap (- len-tot (+ dst1 (apply '+ dlt-lst2) dlt)))
	 
	 (cond ((> gap gap-max)					;; gap is still more than max
		(setq dlt-lst2 (cons dlt dlt-lst2)		;; add length
		      done nil))				;; not done yet

	       ((< gap gap-min)					;; gap is less than min
		(princ (strcat "\n" (itoa itr-max) ": " (vl-princ-to-string (reverse (cons gap (cons dlt dlt-lst2)))) " failed"))
		(setq itr-max (1- itr-max)			;; lower the counter
		      dlt-lst2 nil)				;; reset length list
		(setq done (zerop itr-max)))			;; done if reached max of attempts, else keep going

	       (T						;; gap within the range
		(setq dlt-lst2 (cons gap (cons dlt dlt-lst2))	;; add length and remaining gap for last-one
		      done T)					;; done
		(princ (strcat "\n" (itoa itr-max) ": " (vl-princ-to-string (reverse dlt-lst2)) " OK"))))
	 dlt-lst2)
       
       (setq dlt-lst2 (cons 0. (reverse dlt-lst2))) 		;; add 0 for first-one
       
       (foreach dlt dlt-lst2					;; draw circles
	 (setq ents-lst (cons (cons (entmakex (list (cons 0 "CIRCLE") (cons 10 (vlax-curve-getPointAtDist ent (setq dst1 (opr2 dst1 dlt)))) (cons 40 rad))) dlt) ents-lst)))

       (setq *aocr-sde* (cons (list ent opr1 opr2 pnt1 pnt2) (reverse ents-lst))))  ;; save list for ArrayOfCirclesEdit
  (princ)
  )

 

0 Likes
Message 34 of 42

Anonymous
Not applicable

Thank you, again.

I think there is an issue with the curve direction. I send you a private message.

 

 

0 Likes
Message 35 of 42

ВeekeeCZ
Consultant
Consultant

The version that will fill up the entire curve/s. ArrayEdit disconnected.

 

(vl-load-com)

(defun c:ArrayOfCirclesRandom3 ( / LM:rand LM:randrange rad dlt-lst1 pnt1 pnt2 tmp dlt-lst2 dst ents-lst gap gap-min gap-max itr-max i s done)
  
  (setq rad 		15
	dlt-lst1 	'(30 32 34 35)
	gap-min 	31					;; also possible: (apply 'min dlt-lst1)
	gap-max 	36					;; also possible: (apply 'max dlt-lst1)
	itr-max 	99)
  
  ;; Random  -  Lee Mac           
  (defun LM:rand ( / a c m )
    (setq m   4294967296.0 a 1664525.0 c 1013904223.0
	  $xn (rem (+ c (* a (cond ($xn) ((getvar 'date))))) m))
    (/ $xn m))
  
  (defun LM:randrange ( a b ) (+ (min a b) (fix (* (LM:rand) (1+ (abs (- a b)))))))
  
  ; -----------------------------

  (if (setq s (ssget '((0 . "LWPOLYLINE,LINE,ARC,CIRCLE"))))
    (repeat (setq i (sslength s))
      (setq ent (ssname s (setq i (1- i))))

      (setq pnt1 (vlax-curve-getStartPoint ent)
	    pnt2 (vlax-curve-getEndPoint ent)
	    len-tot (vlax-curve-getDistAtParam ent (vlax-curve-getEndParam ent))
	    dst 0.
	    done nil)
       
       (while (not done)
	 (setq dlt (nth (LM:randrange 0 (1- (length dlt-lst1))) dlt-lst1)
	       gap (abs (- len-tot (+ (apply '+ dlt-lst2) dlt))))
	 
	 (cond ((> gap gap-max)					;; gap is still more than max
		(setq dlt-lst2 (cons dlt dlt-lst2)		;; add length
		      done nil))				;; not done yet

	       ((< gap gap-min)					;; gap is less than min
		(princ (strcat "\n" (itoa itr-max) ": " (vl-princ-to-string (reverse (cons gap (cons dlt dlt-lst2)))) " failed"))
		(setq itr-max (1- itr-max)			;; lower the counter
		      dlt-lst2 nil)				;; reset length list
		(setq done (zerop itr-max)))			;; done if reached max of attempts, else keep going

	       (T						;; gap within the range
		(setq dlt-lst2 (cons gap (cons dlt dlt-lst2))	;; add length and remaining gap for last-one
		      done T)					;; done
		(princ (strcat "\n" (itoa itr-max) ": " (vl-princ-to-string (reverse dlt-lst2)) " OK"))))
	 dlt-lst2)
       
       (setq dlt-lst2 (cons 0. (reverse dlt-lst2)))		;; add 0 for first-one
       
       (foreach dlt dlt-lst2					;; draw circles
	 (entmakex (list (cons 0 "CIRCLE") (cons 10 (vlax-curve-getPointAtDist ent (setq dst (+ dst dlt)))) (cons 40 rad))))))
       
  (princ)
  )

 

0 Likes
Message 36 of 42

ВeekeeCZ
Consultant
Consultant

@Anonymous wrote:

I would like to understand LISP code better, but I am noticing that the language syntax is completely different from my coding knowledge background...😅 I searched the internet for a while, but didn't find much about the syntax of loops (if, while, cases ...) or about object declarations (creation, selection, ...). Do you have any references to recommend?

 


 

Help is HERE  and HERE is a little visual manual of usage.

And THIS is the place often recommended to start. And HERE  is about the polish notation.

Good luck.

0 Likes
Message 37 of 42

Anonymous
Not applicable

Thank you.

 

There is an issue with the attempt counter when selecting multiple curves at once. The counter go to negative value, so the cycle goes on indefinitely.
I was trying resetting attempts (variable itr-max) before this point

(setq itr-max (1- itr-max)			;; lower the counter

with these two alternatives (the syntax of the IF loop condition is still not clear to me😥

    (if (itr-max<0)
    (setq itr-max 200))
    (setq itr-max (1- itr-max)			;; lower the counter
    (if (< itr-max 0)    ;;very strange for me this syntax
    (setq itr-max 200))
    (setq itr-max (1- itr-max)			;; lower the counter

 Is it the right point to edit?
Why syntax are wrong?

0 Likes
Message 38 of 42

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

..... The counter go to negative value, so the cycle goes on indefinitely.

I was trying resetting attempts (variable itr-max) ... with these two alternatives (the syntax of the IF loop condition is still not clear to me

    (if (itr-max<0)
    (setq itr-max 200))
    (setq itr-max (1- itr-max)			;; lower the counter
    (if (< itr-max 0)    ;;very strange for me this syntax
    (setq itr-max 200))
    (setq itr-max (1- itr-max)			;; lower the counter

 Is it the right point to edit?
Why syntax are wrong?


The second one is closer.  AutoLisp functions always start with the function name, followed by the arguments the function should use.  But if you don't want it to go below 0, it should check whether its less than 1, not whether it's less than 0 -- you don't want to wait until it's already a negative value before doing something to avoid a negative value.  Or if it's always stepping 1 at a time, you could just check whether it's equal to 0.  And you have one right parenthesis in the wrong place, and one missing.  Try this:

 

(if

  (= itr-max 0) ; the test expression

  (setq itr-max 200) ; the 'then' expression if the test returns anything other than nil

    ;; [I moved the other right parenthesis later]
  (setq itr-max (1- itr-max)) ; the 'else' expression if the test returns nil

    ;; [I added the right parenthesis to close the (setq) function]

) ; close the (if) function after both 'then' and 'else' expressions

Kent Cooper, AIA
0 Likes
Message 39 of 42

Anonymous
Not applicable

Thank you...my knowledge backgound is very different from LISP syntax 😃

 

Does LISP syntax would always the then and else istructions? Could I do a IF loop without the else instructions?


Done this edit:

 

(if
(= itr-max 0)
(setq itr-max 200)                              then instruction

((setq itr-max (1- itr-max) ;; lower the counter              else instructions
dlt-lst2 nil))) ;; reset length list

but got a syntax error on load...😢

0 Likes
Message 40 of 42

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... Does LISP syntax would always the then and else istructions? Could I do a IF loop without the else instructions?

....

(if
(= itr-max 0)
(setq itr-max 200)                              then instruction

((setq itr-max (1- itr-max) ;; lower the counter              else instructions
dlt-lst2 nil))) ;; reset length list

but got a syntax error on load...


Yes, you can do an (if) function with no 'else' expression, if you don't want it to do anything when the 'test' expression returns nil.  See >Help for (if)<, in which the [elseexpr] in the arguments list is in brackets, meaning it's optional.

 

Your blue parentheses are the problem there [and you need to add at least one semicolon to comment out the words "then instruction" at the end of that line].  The (setq) function without further wraparound is the 'else' expression.  If you added those parentheses because of the two variables in the (setq) function, they're not needed -- you can set any number of variables within one (setq) function.

 

EDIT:  But come to think of it....  Without studying dozens of earlier messages to know what you're doing with this, I wonder whether you don't want the length list set to nil along with jumping up the counter, rather than along with lowering the counter.  Should it be this instead?

 

(if
  (= itr-max 0) ; test -- when counting down reaches 0,
  (setq ; then

    itr-max 200 ; jump counter up

    dlt-lst2 nil ;; reset length list

  ) ; setq

  (setq itr-max (1- itr-max)) ;; lower the counter    else instructions

) ; if

Kent Cooper, AIA
0 Likes