Message 1 of 2
AppendInner(Outer)Loop throws an exception when passing in an object (an array of member type object)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
First of all, I would be very grateful if you can reply to my question!
I am Using COM API to Programming!
Now, I am Append a Hatch, this is my code:
Protected Sub DealHatch(ByRef HoleHatch As Object,
strHatchName As String,
Optional objCicle As Object = Nothing,
Optional dBottomEndPoint As Double() = Nothing,
Optional dUpperEndPoint As Double() = Nothing
)
If TypeName(HoleHatch) <> "Nothing" Then
If Left(strHatchName, 1) = "半" Then
Dim dArcCenterPoint() As Double = {dUpperEndPoint(0), (dUpperEndPoint(1) + dBottomEndPoint(1)) / 2, 0}
Dim dArcRadius As Double = (dUpperEndPoint(1) - dBottomEndPoint(1)) / 2
Dim objLine As Object = AcModelSpace.AddLine(dUpperEndPoint, dBottomEndPoint)
Dim objArc As Object = AcModelSpace.AddArc(dArcCenterPoint, dArcRadius, Math.PI / 2, 3 * Math.PI / 2)
'The commented code can run correctly
'Dim OuterLoop As Object = New AcadEntity() {objLine, objArc}
'HoleHatch.AppendOuterLoop(OuterLoop)
'HoleHatch.AppendInnerLoop(objCicle)
'But the following code cannot run correctly, it throws an exception
'The only difference is that the array member types of OuterLoop are different.
Dim OuterLoop As Object = New Object() {objLine, objArc}
HoleHatch.AppendOuterLoop(OuterLoop) 'Throw an exception. "Object Array Invalid!"
'The combination of objLine and objArc is the semicircle of objCicle
HoleHatch.AppendInnerLoop(objCicle)
HoleHatch.Evaluate()
AcDocument.Regen(True)
Else
HoleHatch.AppendInnerLoop(objCicle)
HoleHatch.Evaluate()
End If
End If
End Sub
You will find that I define all AutoCAD data types as Object, because of the compatibility of the CAD version(this is the only way I can think of). But it is because of this Object that my program is stuck in this place.
So where is the problem? I thought for a long time, and of course I checked the content in the forum, but I didn’t find such a problem.
Thank you very much for answering my question!