My LISP is a little rusty, please overlook the sloppy code of this WIP. This is an interesting problem however, first attempt posted in the .NET Forum.
I have a client with an extensive set of routines to set layer color, visibility, and other layer state properties in Viewports. These are standard LISP functions defined with (defun c:<name>()... We need to be able to automate the refreshing of Viewports by calling the last LISP function used on a particular viewport. I need to open and refresh dozens and dozens of View files.
I've been able to create a set of functions to record each command in a Dictionary keyed by the Viewports handle. I have a LISP routine created which loops through all Layouts present, activates each Viewport, then gets the appropriate command (actually a LISP function, do recall) from the stored library. One final sticking point I haven't been able to figure out...
When I retrieve the stored command, I've defined a string variable 'storedCommand' or something. I can't simply send this to the command line with (command storedCommand), the function definition isn't recognized. Neither can I call the function with (c:storedCommand) because this uses the text after the c:, not its evaluation. I also tried (c:(read storedCommand)) without luck, when in this form C: is not recognized as a function definition.
Even though it would be a bear to implement and maintain, I thought of defining a 2nd copy of the (defun c:.... functions without the C:, but you run into the same problem. (storedCommand) is not evaluated but looked at as the name itself. In other words if I have (setq storedCommand "blue") I cannot figure out how to access this function (blue) using the variable.
Difficult to explain, any questions & comments are welcome and appreciated.
Any ideas? Here's the code which is iterating through viewports and retreiving the stored commands.
(defun c:cvv (/ ViewDict eset cntr Viewports vp AcadApp AcadDoc Layouts lay vpHandle record ssl savedCommand)
(vl-load-com)
(setvar "cmdecho" 0 )
(setq ViewDict (get-or-create-Dict))
(setq AcadDoc (vla-get-activedocument (vlax-get-acad-object)))
(setq Layouts (layoutlist))
(foreach lay Layouts;get list of paperspace layouts
(setvar "ctab" lay);set Layout current
(command "mspace"); Enter model space in Layout Viewport
(if (setq Viewports ; Gather viewports from current Layout
(ssget "x"
(list (cons 0 "VIEWPORT") (cons 410 (getvar "ctab")))
)
)
(progn
(setq cntr (sslength Viewports)); cntr = number of Viewports
(while (> cntr 1); Viewport 1 is the Layout itself
(COMMAND "CVPORT" CNTR); set Viewport Current
(setq cntr (- cntr 1)); cntr decrimented, now equal to array index
(setq ssl (ssget "x" '((0 . "VIEWPORT") (68 . 1)))); get current viewport
(setq vp (entget (ssname ssl 0))); get the entity list
(setq vpHandle (cdr (assoc 5 vp))); get the viewport Handle from it's entity list
(setq record (dictsearch ViewDict vpHandle)); try to get a saved record
(setq savedCommand (cdr (assoc 1 record))); view saved command from record for debug
;(setq savedCommand (strcat "cmd_" savedCommand)) attempt at a workaround by defining new Lisp function without the C:
(if record (c:(read savedCommand))); this line gives "no function definition C:"
)
)
)
);end foreach
(setvar "cmdecho" 0 )
(princ)
)