The below VBScript code is from a property set definition in AutoCAD MEP...
The below works to return the effective name of a block that exists with a certain entity handle. How might I check if the blocks insertion point is at a particular coordinate by a fuz factor? ... and then if is not set then clear out the XData?
On Error Resume Next
Set AcadApp = GetObject(,"AutoCAD.Application")
AcadVerString = AcadApp.ActiveDocument.GetVariable("ACADVER")
Select Case AcadVerString
Case "18.1s (LMS Tech)"
aecBaseVer = "AecX.AecBaseApplication.6.5"
Case "18.2s (LMS Tech)"
aecBaseVer = "AecX.AecBaseApplication.6.7"
Case Else
aecBaseVer = "Unknown"
End Select
If aecBaseVer = "Unknown" Then
RESULT = "Unknown Version"
Else
Set RodObj = Nothing
Set RodObj = AcadApp.ActiveDocument.HandleToObject("[Handle]")
RodObj.GetXData "TWC-Hangers", xdataType, xdataValue
BlockHandle = xdataValue (2)
Set BlockObj = Nothing
Set BlockObj = AcadApp.ActiveDocument.HandleToObject(BlockHandle)
BlockName = BlockObj.EffectiveName
If Not BlockObj Is Nothing Then RESULT = BlockName Else RESULT = ""
End If
Solved! Go to Solution.
Solved by mdhutchinson. Go to Solution.
By the way... this is for AutoCAD MEP 2011
PSD Formula Property
So, I guess I'll answer my own question... here goes.
On Error Resume Next
Set AcadApp = GetObject(,"AutoCAD.Application")
AcadVerString = AcadApp.ActiveDocument.GetVariable("ACADVER")
Select Case AcadVerString
Case "18.1s (LMS Tech)"
aecBaseVer = "AecX.AecBaseApplication.6.5"
Case "18.2s (LMS Tech)"
aecBaseVer = "AecX.AecBaseApplication.6.7"
Case Else
aecBaseVer = "Unknown"
End Select
If aecBaseVer = "Unknown" Then
RESULT = "Unknown Version"
Else
' >>>> Setup to work with the coordinates
Set aecBase = AcadApp.GetinterfaceObject(aecBaseVer)
aecBase.Init AcadApp
Set Util = aecBase.ActiveDocument.Utility
' >>>> Get the Rod and the XData if there is any.
Set RodObj = Nothing
Set RodObj = AcadApp.ActiveDocument.HandleToObject("[Handle]")
RodObj.GetXData "My-Hangers", xdataType, xdataValue
BlockHandle = xdataValue (2)
Set BlockObj = Nothing
'>>>> Convert the Handle to an object.
Set BlockObj = AcadApp.ActiveDocument.HandleToObject(BlockHandle)
If Not BlockObj Is Nothing Then ' chk loc then use block name if okay.
Fuz = 0.02
RLoc = Util.ConverttoVariantArray(RodObj.EndPoint)
BLoc = Util.ConverttoVariantArray(BlockObj.InsertionPoint)
XCom = ((Abs (RLoc(0) - BLoc(0))) <= Fuz)
YCom = ((Abs (RLoc(1) - BLoc(1))) <= Fuz)
ZCom = ((Abs (RLoc(2) - BLoc(2))) <= 8.0)
If (XCom and YCom and ZCom) Then
BlockName = BlockObj.EffectiveName
RESULT = BlockName
Else
RESULT = ""
End If
Else
RESULT = ""
End If
End If
I would like to improve on this... make if faster, shorter, etc.
Any thoughts?