Autocad - VBA - Delete a selection and insert a text

Hi,
I need your help,
in Autocad by a sub in vba. I try to delete some text by a windows selection on the layout tab. The zone of my selection will be always the same.
My selection does'nt work. What am I forgetting?
After, Ii'm gonna have to insert a text at a special point. Could you give me some hint to write this code?

Thanks
Joh

Private SubDelete()
 
    Dim startPoint(0 To 2) As Double
    Dim endPoint(0 To 2) As Double
 
    startPoint(0) = 34.93151714#
    startPoint(1) = 3.30691694#
    startPoint(2) = 0#
 
    endPoint(0) = 42.058499#
    endPoint(1) = -0.0687933#
    endPoint(2) = 0#
 
    On Error Resume Next
     objSelection.Select acSelectionSetWindow, startPoint, endPoint
     objSelection.AddItems 
    objSelection.Erase    
 
End Sub

Open in new window

joh90Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

darrenmcwiCommented:
1) Don't make the sub-private unless you need to. That's a little more indepth than we'll want to get into here.

2) Dimension and set a new Selection Set object. Here, I'm looking to see if the selection set name already exists and if it does, I clear it or it's contents. If it doesn't exist, I then create it.

3) AddItems method is not used. This is for adding individual items to an existing selection set.

If this still doesn't work, here's a few things to check, are you in the proper page you're trying to select in?

Have you manually tried drawing a box using the coordinates in your code? This might flush out a problem if it's not where you think it is, if the UCS is different than you expect, etc.

Add code to zoom out slightly from those coordinates. When you select via Window/Crossing, etc., AutoCAD translates the screen pixed coordinates into the graphical coordinates you specified. If those coordinates (the object you are trying to select) are outside the drawing editor, you're not going to be able to select it as AutoCAD ignores coordinates once outside the drawing editor. If it watched all the coordinates, on-screen selection would take forever because AutoCAD would have to continuously check the entire drawing, not just what's on screen. It's one of many ways AutoCAD keeps it's performance up.
ublic Sub SSDelete()
 
    Dim objSelection As AcadSelectionSet
    Set objSelection = ThisDrawing.SelectionSets.Item("SS1")
    If objSelection Is Nothing Then
        Set objSelection = ThisDrawing.SelectionSets.Add("SS1")
    Else
        objSelection.Clear
    End If
    
    Dim startPoint(0 To 2) As Double
    Dim endPoint(0 To 2) As Double
    
    Dim pts As Variant
    Dim pte As Variant
    
    startPoint(0) = 34.93151714
    startPoint(1) = 3.30691694
    startPoint(2) = 0#
    endPoint(0) = 42.058499
    endPoint(1) = -0.0687933
    endPoint(2) = 0#
    
    objSelection.Select acSelectionSetWindow, startPoint, endPoin
    objSelection.Erase
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
CAD/Architecture Software

From novice to tech pro — start learning today.