Incorrect entity name

Incorrect entity name

Anonymous
Not applicable
598 Views
3 Replies
Message 1 of 4

Incorrect entity name

Anonymous
Not applicable

Hello,

 

When I execute successively the sub named "Label" and after the sub named "Delete", I get the following error "-2145320958 (80210002): Incorrect entity name" on the line ssetObj.Erase

 

 

Sub Label()
  Dim Point1 As Variant
  Dim Point2 As Variant
  Dim LeaderPoints(0 To 5) As Double
  Dim Leader As AcadMLeader
  Dim i As Long

  Point1 = ThisDrawing.Utility.GetPoint(, "Enter a point: ")
  Point2 = ThisDrawing.Utility.GetPoint(Point1, "Enter a point: ")

  LeaderPoints(0) = Point1(0): LeaderPoints(1) = Point1(1): LeaderPoints(2) = Point1(2)
  LeaderPoints(3) = Point2(0): LeaderPoints(4) = Point2(1): LeaderPoints(5) = Point2(2)

  Set Leader = ThisDrawing.ModelSpace.AddMLeader(LeaderPoints, i)
  Leader.textString = "Example"
End Sub

 

 

Sub Delete()
  Dim ssetObj As AcadSelectionSet

  For Each ssetObj In ThisDrawing.SelectionSets
    If ssetObj.Name = "SSET" Then
      ThisDrawing.SelectionSets("SSET").Delete
      Exit For
    End If
  Next ssetObj

  Set ssetObj = ThisDrawing.SelectionSets.Add("SSET")
  ssetObj.SelectOnScreen
 

  If ssetObj.Count = 0 Then Exit Sub

  ssetObj.Erase

End Sub

 

 

If somebody have an idea, I will appreciate.

Thank you for your help

0 Likes
599 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

hi cduclaux

 

as long as I just call those two subs one after another, I don't see any error

which is the code after the "Delete" sub that throws the error?

0 Likes
Message 3 of 4

Anonymous
Not applicable

Hi Ricvba,

 

Thanks for your answer. All the code is here. I call the first sub to draw the mleader. And just after i call the sub delete to erase the leader drawn previously. I obtain an error on the line ssetObj.Erase

 

For your information, this error appears on Autocad 2015 / 2016. I haven't made a test on previous version of Autocad.

 

I try to replace the line ssetObj.Erase by the following code.

 

Dim obj As AcadEntity
For Each obj In ssetObj
  obj.Delete
Next obj

 

I obtain also an error named -2145386306 (802000be) elockviolation

 

The most strange in this problem if I save my drawing just before calling the sub delete, I haven't any error.

 

Thanks for your help

0 Likes
Message 4 of 4

Anonymous
Not applicable

I have Autocad 2104 so I can't track down that error

 

may be a workaround is putting all selectionset items in a (dynamic) array and then iterate through it in a separate loop and delete its elements, like follows

Sub Delete()
Dim i As Integer, nObj As Integer
Dim ssetObj As AcadSelectionSet

On Error Resume Next
Set ssetObj = ThisDrawing.SelectionSets.Item("SSET")
If Err <> 0 Then Set ssetObj = ThisDrawing.SelectionSets.Add("SSET")
On Error GoTo 0

With ssetObj
    .Clear
    .SelectOnScreen

    nObj = .Count
End With
    
If nObj > 0 Then
    ReDim ssetObjItems(0 To nObj - 1) As AcadEntity
    For i = 0 To nObj - 1
        Set ssetObjItems(i) = ssetObj.Item(i)
    Next i
    
    For i = 0 To nObj - 1
        ssetObjItems(i).Delete
    Next i
    
End If

End Sub

 

where I used a different selectionset handling technique. you mau also want to delete the selectionset after its exploitation.

hope this can help

 

0 Likes