TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: jsr on October 15, 2012, 02:01:47 AM
-
Hi all
I have a routine which iterates through the paper space layouts 1 by 1. I want to be able to call different functions through this routine so that when a layout is activated I can perform different operations before siwtching to next layout. For example for each layout I may want to write some text in it or insert a table or scale a block etc.
For same function call I can do so by mentioning its name in the layout iteration routine. But depending on the situation I may need to call different functions (without changing the iteration lisp file every time).
Thanks.
-
Pass the functions as arguments to the 'layout iteration routine'?
-
You could also pass a list of integers, with each mapped to a specific function call. Inside the body of the main function use a (cond...) call to call the appropriate function as you iterate over the list.
-
My crude example:
For same function call I can do so by mentioning its name in the layout iteration routine. But depending on the situation I may need to call different functions (without changing the iteration lisp file every time).
(setq its_name "special case")
(layout_iteration_routine its_name)
(defun layout_iteration_routine (flag / )
(if (= flag "special case")
(do_special)
;; else
(do_normal)
)
)
-
I was thinking...
(defun c:hello ( )
(alert "Hello World!")
(princ)
)
(defun c:goodbye ( )
(alert "Goodbye Cruel World!")
(princ)
)
(defun layout_iteration_routine ( func )
;; ... < do something > ...
(func)
;; ... < do something > ...
)
(layout_iteration_routine c:hello)
(layout_iteration_routine c:goodbye)
Or, for multiple functions, perhaps:
(defun layout_iteration_routine ( funcs )
;; ... < do something > ...
(mapcar 'eval funcs)
;; ... < do something > ...
)
(layout_iteration_routine '((c:hello) (c:goodbye)))
Or even:
(defun layout_iteration_routine ( funcs )
;; ... < do something > ...
(foreach func funcs ((eval func)))
;; ... < do something > ...
)
(layout_iteration_routine '(c:hello c:goodbye))
The possible structures / calling methods are endless...
-
Good explanation Lee.
My other approach would be to use a global variable to steer the routine.
Obviously you may expand the choices and use a COND ILO IF. 8-)
(setq its_name "special case")
(defun layout_iteration_routine ( )
(if (= its_name "special case")
(do_special)
;; else
(do_normal)
)
)
-
Dear Members
Thank you very much for the valuable comments.