wannabe Posted October 22, 2008 Posted October 22, 2008 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? Quote
ASMI Posted October 22, 2008 Posted October 22, 2008 Something like this: 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 Quote
wannabe Posted October 23, 2008 Author Posted October 23, 2008 Something like this: 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? Quote
borgunit Posted October 23, 2008 Posted October 23, 2008 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.