Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Autocad - VBA - Delete a selection and insert a text

Posted on 2009-06-27
1
Medium Priority
?
2,587 Views
Last Modified: 2013-12-04
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

0
Comment
Question by:joh90
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 11

Accepted Solution

by:
darrenmcwi earned 150 total points
ID: 24739072
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question