.NET

Reply
Valued Mentor
mdhutchinson
Posts: 2,319
Registered: ‎11-18-2003
Message 1 of 2 (217 Views)

HandleToObject fails

217 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

AcadApp.ActiveDocument.Activate

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

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 2 of 2 (181 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")
            Else
                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
            Try
                AcadApp = TryCast(Marshal.GetActiveObject(progID), AcadApplication)

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

            MsgBox("Wait!...")

            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...")
                Return
            Else
                MsgBox(Room.ObjectName)
                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

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!