.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

HandleToObject fails

1 REPLY 1
Reply
Message 1 of 2
mdhutchinson
554 Views, 1 Reply

HandleToObject fails

 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")

1 REPLY 1
Message 2 of 2
Hallex
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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost