September 16, 2008

Z-Coordinates of Aec Objects

A recent thread in the Autodesk AutoCAD® Architecture Discussion Group reminded me that I had never followed up on another thread, in which a solution to the inability to extract coordinate values from the Location property of an Aec Object. In particular, the Z-coordinate was of interest, because there is no automatic property for the elevation.

The VarType and TypeName functions indicate that the Location property contains an array of doubles, but the individual values could not be extracted directly. Thanks to the code that BHashman posted, the coordinate values can be extracted by making use of the ConvertToVariantArray method of the Utility object of the AecBaseDocument object. (The ConvertToVariantArray is not listed in the Help.) Here is a variation on that code, to extract the elevation of a Wall, with an added test for the current version running, so that the same Formula property can work in both 2008 and 2009.
Set acadApp = GetObject(,"AutoCAD.Application")
'ACADVER values:
'ACD-A2008 = "17.1s (LMS Tech)"
'ACD-A2009 = "17.2s (LMS Tech)"
acadVerString = acadApp.ActiveDocument.GetVariable("ACADVER")

'Set ADT application string, based on version running:
Select Case acadVerString
Case "17.1s (LMS Tech)"
aecBaseVer = "AecX.AecArchBaseApplication.5.5"
Case "17.2s (LMS Tech)"
aecBaseVer = "AecX.AecArchBaseApplication.5.7"
Case Else
aecBaseVer = "Unknown"
End Select

If aecBaseVer = "Unknown" Then
RESULT = "Unknown Version"
Set aecBase = acadApp.GetInterfaceObject(aecBaseVer)
aecBase.Init acadApp
Set wallObj = acadApp.ActiveDocument.ObjectIDToObject( [ObjectID] )
Set utilObj = aecBase.ActiveDocument.Utility
wallLocation = utilObj.ConvertToVariantArray(wallObj.Location)
RESULT = wallLocation(2)
End If
The code needed for this to work in 2007 is not exposed, so this will only work in 2008 or 2009. Assuming that the code will continue to work in future releases, all that would be necessary would be to determine the value of the ACADVER sytem variable and the AecX.AecArchBaseApplication version number and then add an additional Case statement to support that release.

A sample file can be found in a reply to this thread. I left in a lot of the test formulas I used along the way - the WallElevation-Location property has the Formula shown above, and there are three walls at three different elevations which show that the Z-coordinate is being extracted. The WallElevation-StartPoint property does the same thing, but uses the StartPoint property, which is the same as the Location property for Walls. Most AEC "real-world" objects have a Location property, so that may be a better starting point when adapting this for other objects. Be certain to check the properties available on the AEC object of interest in the AutoCAD Architecture ActiveX Reference section of the Help to determine what property to use.


Kevin Fielding said...

As discussed recently inthe Autodesk discussion group, change AecX.AecArchBaseApplication for AecX.AecBaseApplication.

faugustom said...

Hi David! Using this formula for years! Thank you! But isn't working with ACA 2008 in Windows 8, any suggestions? Thank's

faugustom said...

Hi David. Found the problem. The "new" UAC in windows 8 blocks the function. If i disable it, the formula works, but the metro apps not...