Recently a question was asked on the AutoCAD MEP forums about how to put the elevation of a Mass Element in a property set definition when neither the location or the elevation was available as an automatic property. You can view the original post here. Since this was very similar to a post that was covered previously on this blog it was an easy solution. First I created a new property set definition that referenced a mass element and then added the automatic property definition OBJECTID. Once that was complete I created a new formula definition and added the following code. Make sure to replace the [OBJECTID] in the code below with a reference to the automatic property!
[frame bgcolor=”#DDDDDD” version=”light”]
On Error Resume Next DecimalPlaces = 8 Set acadApp = GetObject(,"AutoCAD.Application") 'ACADVER values: 'MEP 2010 = "18.0s (LMS Tech)" 'MEP 2011 = "18.1s (LMS Tech)" 'MEP 2012 = "18.2s (LMS Tech)" 'MEP 2013 = "19.0s (LMS Tech)" 'MEP 2014 = "19.1s (LMS Tech)" 'MEP 2015 = "20.0s (LMS Tech)" acadVerString = acadApp.ActiveDocument.GetVariable("ACADVER") 'Set ACA application string, based on version running: Select Case acadVerString Case "18.0s (LMS Tech)" 'MEP-2010 aecBaseVer = "AecX.AecBaseApplication.6.0" Case "18.1s (LMS Tech)" 'MEP-2011 aecBaseVer = "AecX.AecBaseApplication.6.5" Case "18.2s (LMS Tech)" 'MEP-2012 aecBaseVer = "AecX.AecBaseApplication.6.7" Case "19.0s (LMS Tech)" 'MEP-2013 aecBaseVer = "AecX.AecBaseApplication.7.0" Case "19.1s (LMS Tech)" 'MEP-2014 aecBaseVer = "AecX.AecBaseApplication.7.5" Case "20.0s (LMS Tech)" 'MEP-2015 aecBaseVer = "AecX.AecBaseApplication.7.7" Case Else aecBaseVer = "Unknown" End Select If aecBaseVer = "Unknown" Then RESULT = "Unknown Version" Else Set aecBase = acadApp.GetInterfaceObject(aecBaseVer) aecBase.Init acadApp Set MassElementObject = acadApp.ActiveDocument.ObjectIDToObject([ObjectID]) Set UtilityObject = aecBase.ActiveDocument.Utility ' Get the Normal of the Object and break down into individual X, Y, and Z parts MassElementObjectNormal = UtilityObject.ConvertToVariantArray(MassElementObject.Location) NormalX = Round(MassElementObjectNormal(0), DecimalPlaces) NormalY = Round(MassElementObjectNormal(1), DecimalPlaces) NormalZ = Round(MassElementObjectNormal(2), DecimalPlaces) 'Return the results RESULT = Cdbl(NormalZ) End If[/frame]