List manipulation

List manipulation

GeryKnee
Advocate Advocate
301 Views
2 Replies
Message 1 of 3

List manipulation

GeryKnee
Advocate
Advocate

There are errors here


(defun LM:SubstNth ( a n l );;Lee Mac,Copyright © 2011
(if l
(if (zerop n)
(cons a (cdr l))
(cons (car l) (LM:SubstNth a (1- n) (cdr l)))
)
)
)


(defun fnPrinNumListValues(aNumList / count Num)
(if aNumList
(progn
(setq count 0)
(repeat (sslength aNumList)
(setq Num (nth count aNumList))
(princ (strcat "\n" (vla-get-textString count) (vla-get-textString Num)))
(setq count (1+ count))
) ; repeat
);;progn
(princ "\nNo Num List");; else
);;if
(princ)
)


(defun c:xx()
(princ)
(setq ExIDList (list 0 0 0 0 0 0 0))
(fnPrinNumListValues ExIDList)
;;(xW (vl-list-length ExIDList))
;;Change 3rd item
;;(LM:SubstNth 1 3 ExIDList)
(princ)
)

0 Likes
Accepted solutions (1)
302 Views
2 Replies
Replies (2)
Message 2 of 3

Kent1Cooper
Consultant
Consultant

@GeryKnee wrote:

There are errors here

....


That is never enough information.

Kent Cooper, AIA
0 Likes
Message 3 of 3

Moshe-A
Mentor
Mentor
Accepted solution

@GeryKnee ,

 true, what's that?

(princ (strcat "\n" (vla-get-textString count) (vla-get-textString Num)))

the argument of (vla-get-textString) is VLA-OBJECT 

what type Count and Num ???

 

the following fix is working 😀

note the use of (foreach) here.

 

Moshe

 

 

 


@GeryKnee wrote:

There are errors here


(defun c:xx()
(princ)
(setq ExIDList (list 0 0 0 0 0 0 0))
(fnPrinNumListValues ExIDList)
;;Change 3rd item
(LM:SubstNth 1 3 ExIDList)
(setq ExIDList (list 0 0 0 0 0 0 0))
(princ)
)


 

 

(defun LM:SubstNth (a n l );;Lee Mac,Copyright © 2011
 (if l
  (if (zerop n)
   (cons a (cdr l))
   (cons (car l) (LM:SubstNth a (1- n) (cdr l)))
  )
 )
)


(defun fnPrinNumListValues( aNumList / count Num)
 (if (null aNumList) 
  (princ "\nNo Num List");
  (progn ; else  
   (setq count 0) 
   (foreach Num aNumList
    (setq count (1+ count)) 
    (princ (strcat "\n" (itoa count) " " (itoa Num)))
   ); foreach
  ); progn
 ); if
  
;| (if aNumList
  (progn
   (setq count 0)
   (repeat (sslength aNumList)
    (setq Num (nth count aNumList))
    (princ (strcat "\n" (vla-get-textString count) (vla-get-textString Num)))
    (setq count (1+ count))
   ); repeat
  ); progn
  (princ "\nNo Num List");; else
 ); if |;
)


(defun c:xx (/ ExIDLIst)
 (setq ExIDList (list 0 0 0 0 0 0 0))
 (fnPrinNumListValues ExIDList)
 ; Change 3rd item
 (terpri)
 (setq ExIDList (LM:SubstNth 1 3 ExIDList))
 ; (setq ExIDList (list 0 0 0 0 0 0 0))
 (fnPrinNumListValues ExIDList)
  
 (princ)
)