Solved! Go to Solution.
Solved by Keith.Brown. Go to Solution.
Can you please share the answer. The links on post 2 of 3 do not take me there.
Thank you.
This should put you on the right track.
http://www.cadengineeredsolutions.com/autocad_mep/undocumented-property-set-definitions-continued/
Here is the actual completed code that I used in the property set to get the location of the mass element.
On Error Resume Next DecimalPlaces = 3 Set acadApp = GetObject(,"AutoCAD.Application") 'ACADVER values: 'ACA 2010 = "18.0s (LMS Tech)" 'ACA 2011 = "18.1s (LMS Tech)" 'ACA 2012 = "18.2s (LMS Tech)" 'ACA 2013 = "19.0s (LMS Tech)" 'ACA 2014 = "19.1s (LMS Tech)" 'ACA 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)" 'ACA-2010 aecBaseVer = "AecX.AecBaseApplication.6.0" Case "18.1s (LMS Tech)" 'ACA-2011 aecBaseVer = "AecX.AecBaseApplication.6.5" Case "18.2s (LMS Tech)" 'ACA-2012 aecBaseVer = "AecX.AecBaseApplication.6.7" Case "19.0s (LMS Tech)" 'ACA-2013 aecBaseVer = "AecX.AecBaseApplication.7.0" Case "19.1s (LMS Tech)" 'ACA-2014 aecBaseVer = "AecX.AecBaseApplication.7.5" Case "20.0s (LMS Tech)" 'ACA-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 = CStr(NormalX & ";" & NormalY & ";" & NormalZ) End If
Just remember to replace the [ObjectId] with the actual automatic property definition. I tested it on MEP 2013, 2014, 2015 and it worked in all versions.
I have included the dwg with the MASSELEMENT property set definition attached to the post.
One more thing that I thought I should mention. This method will only work if you have 1 instance of AutoCAD MEP running. If you open up a second instance then the property set will fail.
Keith,
First of all...Thank you for responding.
I am having trouble with replacing the [ObjectId] with the actual automatic property definition. I have attached a picture of what I am working with. Please advise.
Glad you got it working. For anyone else reading this thread and wanting an answer, I modified the code above to better reflect the elevation and not the location. The code is below as well as a drawing that has the working property set.
On Error Resume Next DecimalPlaces = 8 Set acadApp = GetObject(,"AutoCAD.Application") 'ACADVER values: 'ACA 2010 = "18.0s (LMS Tech)" 'ACA 2011 = "18.1s (LMS Tech)" 'ACA 2012 = "18.2s (LMS Tech)" 'ACA 2013 = "19.0s (LMS Tech)" 'ACA 2014 = "19.1s (LMS Tech)" 'ACA 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)" 'ACA-2010 aecBaseVer = "AecX.AecBaseApplication.6.0" Case "18.1s (LMS Tech)" 'ACA-2011 aecBaseVer = "AecX.AecBaseApplication.6.5" Case "18.2s (LMS Tech)" 'ACA-2012 aecBaseVer = "AecX.AecBaseApplication.6.7" Case "19.0s (LMS Tech)" 'ACA-2013 aecBaseVer = "AecX.AecBaseApplication.7.0" Case "19.1s (LMS Tech)" 'ACA-2014 aecBaseVer = "AecX.AecBaseApplication.7.5" Case "20.0s (LMS Tech)" 'ACA-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
Keith, I attached a snapshot of what I encountered. I do not have Z elevation for some reason, the result is still the whole formula. Please advise.
First I see is that you replaced the ObjectId incorrectly.
you have:
Set MassElementObject = acadApp.ActiveDocument.ObjectIDToObject[ObjectID]
and it should be
Set MassElementObject = acadApp.ActiveDocument.ObjectIDToObject([ObjectID])
Notice the parenthesis that you have missing?
Second you should format the code correctly. While techniqually not an issue it is difficult to read and to maintain. What happens when you need to come back to it in 2 months and you need to read and understand what you did? Good luck with that.
Here is the actual drawing. MEP 2014 and a snapshot.
Here you go.
FYI. All i did was copy the code from the drawing i supplied to the drawing you supplied, changed the ObjectID, and then set the units.
p.s. You must only have one AutoCAD open at a time or this will not work.
It works!!!
Keith, I truly appreciate that you took the time to help.
Thank you for that. Have a great weekend.