VBA Based Formula Property in PSD (a Hanger solution example).

VBA Based Formula Property in PSD (a Hanger solution example).

mdhutchinson
Advisor Advisor
1,321 Views
7 Replies
Message 1 of 8

VBA Based Formula Property in PSD (a Hanger solution example).

mdhutchinson
Advisor
Advisor

VBA is no longer available except as a separate download... some have said that VBA in 2013 will not be supported at all - separate download or not.

It is my understanding however, that VBA based code will still work in VBScript even though the separate download VBA is not in place.... I've proven this with the below code that works.

 

I have found acadauto.chm (Acad ActiveX VBA Reference) for core AutoCAD VBA. 

The question: Where can I find the newest help file for AutoCAD MEP Active X VBA???

 

I painstackingly got the below code to work.

Essentially, I have a lisp app that inserts an AutoCAD Block at the top of user selected MEP Pipe objects (a pipe style created for All-Thread Rod for Hangers).

The lisp app inserts the block and adds XData to the Pipe with 1005 group code (Handle)... the below code snags the XData attached to the pipe and reads the Handle. If the Handle points to an existing Block and the Block insertion point exists within a fuzz factor from the top of the pipe (All-Thread rod)... then the value of the formula is the name of the AutoCAD Block. This will then be included in the MEP Schedule.

 

Side interest... any thoughts for improvment, or perthaps on the reliability of the below code would be appreciated. Note: The [Handle] field below is an automatic property taken from the pipe (All-Thread Rod).

 

 

'== Converts XData Handle (Block) on All-Thread Rod to an Obj. Tests location, if not there returns to empty String

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 "TWC-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 ' check insertion point first - then use block name if okay.

            Fuz = 0.02

            ZFuz = 8.3125

            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))) <= ZFuz)

            If (XCom and YCom and ZCom) Then

                        BlockName = BlockObj.EffectiveName

                        RESULT = BlockName

                  Else

                        RESULT = ""

            End If

      Else

            RESULT = ""

      End If

End If

0 Likes
1,322 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable

Is this for AutoCad Architecture 2014?

 

0 Likes
Message 3 of 8

mdhutchinson
Advisor
Advisor

Close... it is for AutoCAD MEP 2014.

 

why?

0 Likes
Message 4 of 8

Anonymous
Not applicable

I am trying to get the HANDLE id to display in a custom Table. using PSD and came across your post.

0 Likes
Message 5 of 8

mdhutchinson
Advisor
Advisor

I think Handle is a automatic property that is redily availiable... check your automatic properties.

What Arch object are you working with?

0 Likes
Message 6 of 8

Anonymous
Not applicable

Well its not in the General Properties. If you  list it, it displays. I am using Acad Arch And MeP.

0 Likes
Message 7 of 8

Anonymous
Not applicable

i wanted for all objects, Lines, plines, arcs, walls, space, MEP, doors etc.

0 Likes
Message 8 of 8

David_W_Koch
Mentor
Mentor

Handle is an automatic property for all graphic objects, AEC and AutoCAD.


David Koch
AutoCAD Architecture and Revit User
Blog | LinkedIn
EESignature

0 Likes