ade_expreval

AutoCAD Map 3D AutoLISP

Up a level
ade_expreval
 
 

Evaluates an expression.

(ade_expreval [ename] expr type)

Returns the value of the expression or nil.

ename Optional drawing object name. Required if the expression uses object properties or data.
expr Expression to evaluate (string)
type Expected return type (string): "short", "long", "real", "string", or "point".

If the expression uses object properties or data, you must specify the name of a drawing object. For example, if the the expr argument is "(+ 5 6)", no ename argument is required, but to evaluate "(+ ".COLOR" 6)" you need an object to supply the color.

The following example gets the area of a selected object:

(setq myobject (car (entsel "Select an object:")))
(setq value (ade_expreval myobject ".area" "real"))

Depending on what you specify for the type argument in the preceding example, the result can be an integer or a string, as the following two examples demonstrate. Suppose the area of myobject is 2.7. The first expression returns this area as 2; the second returns it as "2.7".

(ade_expreval myobject ".area" "short")

(ade_expreval myobject ".area" "string")

Note  If the expr argument is an integer calculation and you supply "string" for the type argument, the resulting string does not contain an integer, but a real. For example, the following expression returns "2.0", not "2".

(ade_expreval "(+ 1 1)" "string")

If you want the string to contain an integer, include the fix function in the expr argument.

(ade_expreval "(fix (+ 1 1))" "string")

The ade_expreval function can return an integer string so long as the return value is not the result of an integer calculation. For example, the following code returns an integer string without using fix.

(setq obj (car (entsel "Select an object:")))
(setq objcolor (ade_expreval obj ".color" "string")))

To get the centroid and the layer name of the same object, add these lines:

(setq objcentr (ade_expreval obj ".centroid" "point"))
(setq objlayer (ade_expreval obj ".layer" "string"))