+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Super Member
    Computer Details
    wannabe's Computer Details
    Operating System:
    XP
    Using
    AutoCAD 2007
    Join Date
    Oct 2008
    Location
    Birmingham, UK
    Posts
    772

    Default VBA - Using IF and selection sets

    Registered forum members do not see this ad.

    Public Sub ScanForCircle()
    ''This sub will scan the drawing to determine if circles are present
    'First, select all the items in the drawings by:

    '1. Creating a selection set
    Dim sset1Obj As AcadSelectionSet
    Set sset1Obj = ThisDrawing.SelectionSets.Add("SSET4")

    '2. Adding all objects to the selection set
    sset1Obj.Select acSelectionSetAll

    '3. Filter so only circles are left
    Dim dataValue(0) As Variant
    dataValue(0) = "Circle"
    sset1Obj.Select

    '4. Ask if circles are present in the selection set

    'Delete the selction set
    sset1Obj.Delete
    End Sub
    I decided that I wanted to understand how to use 'If Then Else' statements, so my first task was to scan the drawing for circles and then have a statement on the command prompt that lets me know whether there are or arent.

    Above, in the code, you can see I have made a selection set that selects all the objects in a drawing. I then want to ask if there are any circles present in that selection set and then insert two lines of code which will be the answer to my question.

    Can anyone advise, please?
    Last edited by wannabe; 22nd Oct 2008 at 09:29 am.

  2. #2
    Super Member ASMI's Avatar
    Using
    AutoCAD 2008
    Join Date
    Nov 2005
    Location
    Oceanus Procellarum, Moon
    Posts
    1,427

    Default

    If sset1Obj.Count <> 0 Then

  3. #3
    Super Member ASMI's Avatar
    Using
    AutoCAD 2008
    Join Date
    Nov 2005
    Location
    Oceanus Procellarum, Moon
    Posts
    1,427

    Default

    Something like this:

    Code:
    Sub ScanForCircles()
    
    Dim sCol As AcadSelectionSets
    Dim sset1Obj As AcadSelectionSet
    Dim fTyp(0 To 0) As Integer
    Dim fDat(0 To 0) As Variant
    
    Set sCol = ThisDrawing.SelectionSets
    
    On Error Resume Next
    sCol.Item("SSET1").Delete
    
    Set sset1Obj = sCol.Add("SSET1")
    
    fTyp(0) = 0
    fDat(0) = "CIRCLE"
    
    sset1Obj.Select acSelectionSetAll, , , fTyp, fDat
    
    MsgBox "There is " & sset1Obj.Count & " circles."
    
    sset1Obj.Delete
    Set sset1Obj = Nothing
    
    End Sub

  4. #4
    Super Member
    Computer Details
    wannabe's Computer Details
    Operating System:
    XP
    Using
    AutoCAD 2007
    Join Date
    Oct 2008
    Location
    Birmingham, UK
    Posts
    772

    Default

    Quote Originally Posted by ASMI View Post
    Something like this:

    Code:
    Sub ScanForCircles()
     
    Dim sCol As AcadSelectionSets
    Dim sset1Obj As AcadSelectionSet
    Dim fTyp(0 To 0) As Integer
    Dim fDat(0 To 0) As Variant
     
    Set sCol = ThisDrawing.SelectionSets
     
    On Error Resume Next
    sCol.Item("SSET1").Delete
     
    Set sset1Obj = sCol.Add("SSET1")
     
    fTyp(0) = 0
    fDat(0) = "CIRCLE"
     
    sset1Obj.Select acSelectionSetAll, , , fTyp, fDat
     
    MsgBox "There is " & sset1Obj.Count & " circles."
     
    sset1Obj.Delete
    Set sset1Obj = Nothing
     
    End Sub

    That's great again, thanks.

    Just a quick question, mate:

    I Understand what the 'MsgBox' represents but I don't fully understand what the quote marks represent. Obviously the ones at either end are essential, but the ones in-between the text I am unsure exactly how they work in VBA along with the '&' aswell.

    Can you explain, please?

  5. #5
    Senior Member borgunit's Avatar
    Using
    Mechanical 2006
    Join Date
    May 2007
    Location
    Ohio USA
    Posts
    287

    Default

    Registered forum members do not see this ad.

    I can try and explain. A message box feeds a string to the screen via a dialog box. What is shown is a concatenation (joining) of a string. It shows a string, denoted by "There is " and then it is joining (&) it to a string value (actually a integer that VB converts to a string) sset1Obj.Count and then joining (&) another string to that " circles." WHat you end up with is a message box that shows "There is 2 circles" when the selection set has two items in it.
    AutoCAD Mechanical 2006
    XP PRO SP3
    http://mechcad-insider.blogspot.com/

Similar Threads

  1. VBA - Selection Sets
    By -KarL- in forum AutoLISP, Visual LISP & DCL
    Replies: 17
    Last Post: 3rd Mar 2009, 10:54 am
  2. Sheet Sets
    By Norts in forum AutoCAD Drawing Management & Output
    Replies: 7
    Last Post: 8th Aug 2007, 05:32 pm
  3. Little help on selection sets please
    By Galingula in forum AutoCAD Drawing Management & Output
    Replies: 2
    Last Post: 17th Apr 2006, 03:39 pm
  4. selection sets..........
    By rajanikrishna in forum AutoLISP, Visual LISP & DCL
    Replies: 1
    Last Post: 14th Nov 2005, 11:32 am
  5. delay in selection of objects/selection windows
    By RedRobMol in forum AutoCAD Drawing Management & Output
    Replies: 2
    Last Post: 31st May 2005, 01:34 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts