Method 'Origin' of object 'IAcadBlock' failed

Method 'Origin' of object 'IAcadBlock' failed

taras_zelensky
Contributor Contributor
1,422 Views
2 Replies
Message 1 of 3

Method 'Origin' of object 'IAcadBlock' failed

taras_zelensky
Contributor
Contributor

Hello


When creating a block, I want to add a polyline to it:

 

Sub Example_AddPolyline()
' This example creates a polyline in model space.

Dim blkDef1 As AcadBlock
Dim plineObj As AcadPolyline
Dim points(0 To 10) As Double
Dim Middle2(0 To 2) As Double


Middle2(0) = 1: Middle2(1) = 1

' Define the 2D polyline points
points(0) = 1: points(1) = 1
points(2) = 1: points(3) = 2
points(4) = 2: points(5) = 2
points(6) = 3: points(7) = 2
points(8) = 4: points(9) = 4

' Create a lightweight Polyline object in model space
Set blkDef1 = ThisDrawing.Blocks.Add(Middle2, "111")

blkDef1.AddPolyline (points) '<-- There is a mistake

Set plineObj = blkDef1.AddPolyline(points)
plineObj.Closed = True

End Sub

 

But an error occurs: "Method 'Origin' of object 'IAcadBlock' failed"
What is the possible solution to this problem?

0 Likes
Accepted solutions (2)
1,423 Views
2 Replies
Replies (2)
Message 2 of 3

grobnik
Collaborator
Collaborator
Accepted solution

Hi, @taras_zelensky 

I made a simple test with your code, the issue it's inside the amount of points, defining the polyline, these shall be multiple of 3, you defined the array of 11 points (0 to 10), and assigned array variable from 0 to 9.

Here below code reviewed

 

 

 

Sub Example_AddPolyline()
' This example creates a polyline in model space.

Dim blkDef1 As AcadBlock
Dim plineObj As AcadPolyline
Dim points(1 To 9) As Double 'You set Dim points(0 To 10) As Double
Dim Middle2(0 To 2) As Double


Middle2(0) = 1: Middle2(1) = 1

' Define the 2D polyline points
'points(0) = 1: ' point 0 deleted in order to reach 9 points
points(1) = 1
points(2) = 1: points(3) = 2
points(4) = 2: points(5) = 2
points(6) = 3: points(7) = 2
points(8) = 4: points(9) = 4

' Create a lightweight Polyline object in model space
Set blkDef1 = ThisDrawing.Blocks.Add(Middle2, "111")

blkDef1.AddPolyline (points) '<-- There is a mistake

Set plineObj = blkDef1.AddPolyline(points)
plineObj.Closed = True

End Sub

 

 

grobnik_0-1594534517939.png

Let us know

Message 3 of 3

taras_zelensky
Contributor
Contributor
Accepted solution

Many thanks for the help. Everything is working 🙂

 

Sub Example_AddPolyline()
' This example creates a polyline in model space.

Dim blkDef1 As AcadBlock
Dim plineObj As AcadPolyline
Dim points(0 To 11) As Double
Dim Middle2(0 To 2) As Double

Middle2(0) = 1: Middle2(1) = 1

' Define the 2D polyline points
points(0) = 1: points(1) = 1: points(2) = 0
points(3) = 1: points(4) = 2: points(5) = 0
points(6) = 2: points(7) = 2: points(8) = 0
points(9) = 2: points(10) = 1: points(11) = 0

Set blkDef1 = ThisDrawing.Blocks.Add(Middle2, "111")

' Create a lightweight Polyline object in model space
Set plineObj = blkDef1.AddPolyline(points)
plineObj.Closed = True

ThisDrawing.ModelSpace.InsertBlock Middle1, "111", 1, 1, 1, 0

End Sub