Defining External Functions

When an ObjectARX application receives a kLoadDwgMsg request from AutoCAD, it must define all of its external functions by calling acedDefun() once for each function. The acedDefun() call associates the external function's name (passed as a string value) with an integer code that is unique within the application. The integer code must not be negative, and it cannot be greater than 32,767 (in other words, the code is a short integer).

The following call to acedDefun() specifies that AutoLISP will recognize an external function called doit in AutoLISP, and that when AutoLISP invokes doit, it passes the function code zero (0) to the ObjectARX application:

acedDefun("doit", 0);

The string that specifies the name of the new external function can be any valid AutoLISP symbol name. AutoLISP converts it to all uppercase and saves it as a symbol of the type Exsubr.

External functions are defined separately for each open document in the MDI. The function gets defined when the document becomes active. For more information, see The Multiple Document Interface.

Danger: If two or more ObjectARX applications define functions (in the same document) that have the same name, AutoLISP recognizes only the most recently defined external function. The previously loaded function will be lost. This can also happen if the user calls defun with a conflicting name.

As in AutoLISP, the new function can be defined as an AutoCAD command by prefixing its name with “C:” or “c:”, as shown in the following example:

acedDefun("C:DOIT", 0);

In this case, DOIT can now be invoked from the AutoCAD Command prompt without enclosing its name in parentheses.

Functions defined as AutoCAD commands can still be called from AutoLISP expressions, provided that the “C:” prefix is included as a part of their names. For example, given the previous acedDefun() call, the AutoCAD user could also invoke the DOIT command as a function with arguments:

Command: (c:doit x y)

Danger: If the application defines a C:XXX command whose name conflicts with a built-in command or a command name defined in the acad.pgp file, AutoCAD does not recognize the external function as a command. The function can still be invoked as an AutoLISP external function. For example, after the call acedDefun("c:cp", 0), a user input of cp (an alias for COPY defined in acad.pgp) invokes the AutoCAD COPY command, but the user could invoke the external function with c:cp.
Note: Function names defined by acedDefun() can be undefined by calling acedUndef(). After a function has been undefined, an attempt to invoke it causes an error.