"The values defined in the routine" are called variables. The variables can
be local and/or global. If you declare them as local, i.e. writing them on
the right side of the forward slash within the defun statement, they live
only for the time the routine is running and at the end, they are cleared.
In the other hand, the global variables, those who are not declared as
local, will "float" in the environment, keeping their last assigned value.
This can be good, but can be harmful also, because they can interfere with
some other global variables with the same name, left by some other LISP
routine. So if you need global variables for whatever reason, just make sure
they have unique and hard to duplicate names.
On the left side of that forward slash within the defun statement, you are
passing the arguments, i.e. kind of self declared variables that bring
values from outside the function into the function. This is handy when you
have a function that performs something but you don't know all the data from
the very beginning. Let's assume you need a function that prints all the
elements of a list, but you don't know that list yet.
(defun print_list_elements (the_list)
(if (= (type the_list) 'LIST)
(foreach element the_list
(print element)
)
(alert "Invalid argument type !")
)
(princ)
)
The above function will work with any valid list, no matter the length and
the type of the elements of that list. In order to use it, you have to call
it by passing the list as a variable or directly as a list:
(setq my_list (list 1 2 3))
(print_list_elements my_list)
or
(print_list_elements (list 1 2 3))
This allows for greater flexibility when writing the code.
Hope all this is clear enough,
Constantin
a écrit dans le message de news:
5415758@discussion.autodesk.com...
Thanks for the advise Constantin. I managed to re-write the code slightly
to get what I need. I now have the following and it works.
FYI the C:test2 was just so I could test the partial routine, it is far from
done.
(defun c:test2 ()
(if
(progn
(setq en (entlast))
(setq enlist (entget en))
(if
(= (cdr (assoc 0 enlist)) "INSERT")
(progn
(if
(= (cdr (assoc 66 enlist)) 1)
(progn
(setq en2 (entnext en))
(setq enlist2 (entget en2))
(while
(/= (cdr (assoc 2 enlist2)) "LEVEL_01")
(princ "\n ")
(princ enlist2)
(setq en2 (entnext en2))
(setq enlist2 (entget en2))
)
)
)
)
)
)
)
(setq pnl_01_ht_change 5000)
(setq ins_pt (cdr (assoc 11 enlist2)))
(setq new_ins_pt (list (car ins_pt) (+ (cadr ins_pt) pnl_01_ht_change)
(caddr ins_pt)))
(setq enlist2 (subst (cons 11 new_ins_pt) (assoc 11 enlist2) enlist2))
(entmod enlist2)
(entupd en2)
)
A question of interest ... I noticed that you put the following in the
brackets after defun C:test2 'ent / en enlist en2 enlist2 pnl_01_ht ins_pt
new_ins'. If I am not mistaken doing this clears the values defined in the
routine, is this good to do? Does it cause any problems if you don't do it?
Andrew