Run-Time Error '424" Object Required

Run-Time Error '424" Object Required

mconley
Enthusiast Enthusiast
1,299 Views
1 Reply
Message 1 of 2

Run-Time Error '424" Object Required

mconley
Enthusiast
Enthusiast
I have a huge amount of VBA code that needs to be converted to VB.Net. I am going through the code and trying to change all the late binding to early binding.

I have a function that mirrors all the entities in the active document. In this function you will see a line of code that says Dim objent As Object. I changed this line of code to Dim objent As AcadEntity. When I compile the code there are no errors. However, when I run the application, I get a Run-Time Error '424' Object Required messge.

I took the function out of the larger project and tested it on its own by calling it from a small sub routine. When I test it this way, it works fine. When I reinsert it back into the larger application, the run-time error occurs.
----------------------------------------------------------------------------------------------------------------------------------------------------------
Public Sub TestMirrorObjects()

'routine to test MirrorDoorModel function

Dim destinationdocument As AcadDocument
Set destinationdocument = Application.ActiveDocument
Dim bSuccess As Boolean
bSuccess = MirrorDoorModel("LH", destinationdocument)
MsgBox bSuccess

End Sub
----------------------------------------------------------------------------------------------------------------------------------------------------------
Public Function MirrorDoorModel(psDoorHand As String, pobjDocument As AcadDocument) As Boolean

On Error GoTo MirrorError
If psDoorHand = "LH" Or psDoorHand = "CPLH" Then
Dim SSetName As String
Dim objSset As AcadSelectionSet
Dim intMode As Integer
Dim dblPoint1(0 To 2) As Double
Dim dblPoint2(0 To 2) As Double

Dim dblMirrorPoint3(0 To 2) As Double
Dim dblMirrorpoint4(0 To 2) As Double
Dim objent As AcadEntity 'used to be Dim objent As Object

pobjDocument.ActiveLayout = pobjDocument.Layouts.Item("MODEL")
pobjDocument.Application.ZoomExtents

dblPoint1(0) = -70#: dblPoint1(1) = -60#: dblPoint1(2) = 0
dblPoint2(0) = 600: dblPoint2(1) = 600: dblPoint2(2) = 0

pobjDocument.Application.ZoomWindow dblPoint1, dblPoint2

SSetName = "DoorModel"

' Create the selection set
Set objSset = pobjDocument.SelectionSets.Add(SSetName)
'Add all entities that lie within a crossing area
intMode = acSelectionSetCrossing

dblMirrorPoint3(0) = 0: dblMirrorPoint3(1) = 10: dblMirrorPoint3(2) = 0
dblMirrorpoint4(0) = 0: dblMirrorpoint4(1) = 0: dblMirrorpoint4(2) = 0
objSset.Select intMode, dblPoint1, dblPoint2
For Each objent In objSset
objent.Mirror dblMirrorPoint3, dblMirrorpoint4
Next objent
objSset.Erase

pobjDocument.SelectionSets.Item(SSetName).Delete
pobjDocument.Application.Update

End If

MirrorDoorModel = True
Exit Function
MirrorError:
MirrorDoorModel = False
MsgBox Err.Description
End Function
0 Likes
1,300 Views
1 Reply
Reply (1)
Message 2 of 2

mconley
Enthusiast
Enthusiast
After shutting down AutoCAD and trying again this afternoon, the code is working correctly.
0 Likes