Valued Mentor
Posts: 2,292
Registered: ‎11-18-2003
Message 1 of 2 (201 Views)

HandleToObject fails

201 Views, 1 Replies
06-14-2013 12:42 PM

 Set Room = AcadApp.ActiveDocument.HandleToObject("22add")


This line fails with an error... everything works as it should up to this line.

"22add" is a known entity handle...

AcadApp.ActiveDocument.HandleToObject response with intellesence as it should.  The error I get is... Run-time error '48': Error in loading DLL


Dim Room As AcadEntity


Set Room = AcadApp.ActiveDocument.HandleToObject("22add")

*Expert Elite*
Posts: 1,569
Registered: ‎10-08-2008
Message 2 of 2 (165 Views)

Re: HandleToObject fails

06-15-2013 08:26 AM in reply to: mdhutchinson

Try this code, it's working on A2010, I could not have other

version to test

        Public Sub testHandleToObject()
            Dim appver As Object = TryCast(My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\Autodesk\AutoCAD", "CurVer", Nothing), Object)
            If appver IsNot Nothing Then
                MsgBox("You have " + "Autocad.Application." + appver.ToString() + " installed")
                MsgBox("Out of luck, sorry, use your other code to get Application")
            End If

            Dim vernum As Integer = CInt(Math.Floor(Convert.ToDouble(appver.ToString().Substring(1), CultureInfo.InvariantCulture)))

            Dim progID As String = "Autocad.Application." & vernum.ToString()
            Dim AcadApp As AcadApplication = Nothing
                AcadApp = TryCast(Marshal.GetActiveObject(progID), AcadApplication)

                MsgBox("Cannot create object of type """ & progID & """")
                Exit Sub
            End Try
            AcadApp.Visible = True


            Dim acdoc As AcadDocument = AcadApp.ActiveDocument

            Dim Room As Common.AcadEntity

            Dim oEnt As Object
            oEnt = AcadApp.ActiveDocument.HandleToObject("618")
            Room = TryCast(oEnt, Common.AcadEntity)
            If Room Is Nothing Then
                MsgBox("Object did not recognised, exit...")
                If Room.ObjectName = "AcDbPolyline" Then
                    Dim oPoly As Common.AcadLWPolyline
                    oPoly = TryCast(Room, Common.AcadLWPolyline)
                    If oPoly IsNot Nothing Then
                        MsgBox("Area: " + oPoly.Area.ToString)
                    End If
                End If
                End If
        End Sub


Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.