Sharing Data Between Namespaces

AutoCAD AutoLISP & Visual LISP

 
Sharing Data Between Namespaces
 
 
 

VLISP provides a blackboard namespace for communicating the values of variables between namespaces. The blackboard is a namespace that is not attached to any document or VLX application. You can set and reference variables in the blackboard from any document or VLX. Use the vl-bb-set function to set a variable, and use vl-bb-ref to retrieve a variable's value.

For example, the following command sets the foobar blackboard variable to a string:

Command: (vl-bb-set 'foobar "Root toot toot")
"Root toot toot"

The vl-bb-ref function returns the specified string. The following example uses vl-bb-ref to retrieve the value of foobar from the blackboard:

Command: (vl-bb-ref 'foobar)
"Root toot toot"

Note that these functions require you to pass a symbol naming the variable you are referencing ('var-name), not the variable name (var-name).

Setting or retrieving variable values in the blackboard namespace has no effect on variables of the same name in any other namespace.

To demonstrate that document variables are unaffected by blackboard variables

  1. From the VLISP Console window (or the AutoCAD Command prompt), use vl-bb-set to set the *example* blackboard variable.
    _$ (vl-bb-set '*example* 0)
    0

    The *example* variable is set to 0 in the blackboard namespace.

  2. Use vl-bb-ref to verify the value of the variable you set in the previous step.
    _$ (vl-bb-ref '*example*)
    0
  3. See what value *example* has in the current AutoCAD document.
    _$ *example*
    nil

    The *example* variable is nil because it has not been set in the document namespace.

  4. Set *example* in the current document.
    _$ (setq *example* -1)
    -1

    The *example* variable is set to -1 in the document namespace.

  5. Check the current value of *example* in the blackboard.
    _$ (vl-bb-ref '*example*)
    0

    The blackboard variable named *example* is still set to the value assigned in step 1; setting the document variable of the same name in step 4 had no effect on the blackboard.

VLISP also provides the vl-doc-set and vl-doc-ref functions to set and retrieve document namespace variables from a separate-namespace VLX, and vl-propagate to set the value of a variable in all open document namespaces. These functions are described in Referencing Variables in Document Namespaces.