Expression.Execute method

AutoCAD Map 3D ActiveX

Expression.Execute method

Executes the expression.

Execute( _
 AcDbID as Long, _
 ResultValue As Variant _
 ) As Boolean

Returns True on success.

AcDbID

The target object of the expression, entered as a parameter of MapUtil.NewExpression.

If the argument is 0, the expression is evaluated without using an object; otherwise, the expression is evaluated with the object identified by the AcDbObjectID. Expressions fail if the target object is illogical. For example, if you add the expression (".AREA") to a report template, the expression reports the area of objects if the objects have area. When the expression executes on target objects without area, no output is sent to the report. The report on two objects, a stream without an area and a water body with an area, that uses a template with expressions, ".LENGTH", ".LAYER", and ".AREA" looks like this:

362,STREAM,

2496,WATER,459170

ResultValue

The result of the execution of the expression.

The following example.creates and executes an expression that finds the area of all objects in model space.

Dim amap As AcadMap

Dim prj As Project

Dim exp As Expression

Dim i As Integer

Dim varVal As Variant

Dim obj As Object

Dim lngAry() As Long

ReDim lngAry(ThisDrawing.ModelSpace.Count)

Dim strVal As String

 

Set amap = ThisDrawing.Application. _

GetInterfaceObject("AutoCADMap.Application") 

Set prj = amap.Projects(ThisDrawing)

Set exp = prj.MapUtil.NewExpression(".AREA")

For Each obj In ThisDrawing.ModelSpace

lngAry(i) = obj.ObjectID 

exp.Execute lngAry(i), varVal 

i = i + 1 

strVal = strVal & varVal & Chr(13) 

Next

MsgBox strVal