Evaluate Once on Startup

Function Syntax (LM:evalonceonstartup <expr>)
Current Version 1.0
Download EvalOnceOnStartup.lsp
View HTML Version EvalOnceOnStartup.html
Donate
Arguments
Symbol Type Description
expr (any) Quoted expression or data to be evaluated.
Returns
Type Description
Boolean Returns T if the supplied expression is written successfully.

Function Description

This function will write a supplied expression to an existing or temporary acaddoc.lsp file to be evaluated on drawing startup, with the new or existing acaddoc.lsp file deleted or restored to its original state following evaluation.

As a consequence of this operation, the expression supplied to the function will be evaluated only on the next drawing startup, and not subsequently.

Such a function may be useful for use in applications which open a specific drawing or template and then need to perform a number of operations on the opened drawing.

Since AutoLISP runs in the document namespace, evaluation of any AutoLISP program will cease when another drawing becomes active. One way to circumvent this restriction is to include the expression that is to be evaluated in the acaddoc.lsp file (if it exists), which is automatically loaded every time a drawing is opened in AutoCAD (see my tutorial on Loading Programs Automatically for more information).

However, since you would not necessary want the expression to be evaluated for every drawing that is subsequently opened, this function provides a facility to automatically write the expression to a new or existing acaddoc.lsp (which is created in an AutoCAD Support File Search Path if the file doesn't already exist); the written expressions are then evaluated using the post-initialisation s::startup function, which will restore or delete the modified or new acaddoc.lsp file to restore the user's environment and ensure that the expressions are not evaluated when subsequent drawings are opened.

Example Function Call

The following example will perform the necessary operations such that upon opening a new or existing drawing, a single-line text object displaying the content 'This will only appear once.' will be automatically created at the drawing origin and the drawing will be zoomed to extents.

However, as described above, these operations will only be performed on the drawing next opened or created following evaluation of the below expression.

Select all
(LM:evalonceonstartup
   '(progn
        (entmake
            (list
               '(00 . "TEXT")
               '(10 0.0 0.0 0.0)
                (cons 40 (getvar 'textsize))
               '(01 . "This will only appear once.")
               '(62 . 2)
            )
        )
        (vla-zoomextents (vlax-get-acad-object))
    )
)

textsize

increase · reset · decrease

Designed & Created by Lee Mac © 2010