Hi, all. I have problem in late binding code. Because early binding gives compile error (even reference seems correct) so I am moving to late binding in my code.
Here is my sample code:
The error occurs in almost last line: "LineCoords(i) = LineObj.StartPoint(0)", the error is "Run-time error '451': Property let procedure not defined and property get procedure did not return an object".
Assigning values for non-array type of this object works fine, for example the "LineLayers(i) = LineObj.Layer" works fine.
The "LineObj.StartPoint" is Double type with size of (0 To 2).
I tried couple things, but failed:
Any suggestion?
Thank you in advance.
Here is my sample code:
VBA Code:
Sub LateBindingCAD()
'Declaration and late binding the application objects
Dim AcadApp As Object
Dim AcadDoc As Object
Dim AcadObj As Object
Dim LineObj As Object
Dim LineLayers(), LineCoords()
Dim i
Set AcadApp = GetObject(, "AutoCAD.Application")
Set AcadDoc = AcadApp.ActiveDocument
'Select objects in targeted layers, works fine, not important to the question
SSName = Array("COLUMN","BEAM","WALL","FLOOR")
For i = 0 To 3
AcadDoc.SelectionSets.Item(SSName(i)).Delete
AcadDoc.SelectionSets.Add SSName(i)
FilterType(0) = 8
FilterData(0) = SSName(i)
AcadDoc.SelectionSets.Item(SSName(i)).Select 5, , , FilterType, FilterData
Next i
'Extract data from selected object, by late binding the objects inside application objects
ReDim LineLayers(100), LineCoords(100)
i = 0
For Each SSObj In AcadDoc.SelectionSets
For Each AcadObj In SSObj
If AcadObj.Layer = "COLUMN" And AcadObj.ObjectName = "AcDbLine" Then
Set LineObj = AcadObj
LineLayers(i) = LineObj.Layer
LineCoords(i) = LineObj.StartPoint(0) 'error here <------------------------------------------------------------------
i = i + 1
End If
Next
Next
End Sub
The error occurs in almost last line: "LineCoords(i) = LineObj.StartPoint(0)", the error is "Run-time error '451': Property let procedure not defined and property get procedure did not return an object".
Assigning values for non-array type of this object works fine, for example the "LineLayers(i) = LineObj.Layer" works fine.
The "LineObj.StartPoint" is Double type with size of (0 To 2).
I tried couple things, but failed:
VBA Code:
'Variant array type direct assignment
Dim StartPoint()
StartPoint = LineObj.StartPoint 'error here
LineCoords(i) = StartPoint(i)
'Dummy late binding object
Dim StartPoint As Object
Set StartPoint = LineObj.StartPoint 'error here
LineCoords(i) = StartPoint(i)
Any suggestion?
Thank you in advance.