Selection Set length

Selection Set length

Anonymous
Not applicable
825 Views
6 Replies
Message 1 of 7

Selection Set length

Anonymous
Not applicable
Hi,
If u do not mind than please tell me in the program below how to calculate the length of selection set.
thanks

Private Sub cmdBt1_Click()

On Error Resume Next
Dim ss As AcadSelectionSet
Dim Pt1 As Variant
Dim Pt2 As Variant
Dim sslength As Integer
Form1.hide
Pt1 = ThisDrawing.Utility.GetPoint(, "Select First Point")
Pt2 = ThisDrawing.Utility.GetPoint(, "Select Second Point")

'create Sset object first
ss.Select acSelectionSetCrossing, Pt1, Pt2

Set ss = ThisDrawing.SelectionSets.Item("MySSet")
If ss Is Nothing Then
Set ss = ThisDrawing.SelectionSets.Add("MySSet")
End If
sslength = AutoCAD.Application.ActiveDocument.SelectionSets.SelectionSet.count
End Sub
0 Likes
826 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable
This is from a post I made on August 5.

Joe ...

Option Explicit

Public Sub Test()
Dim Pt1 As Variant
Dim Pt2 As Variant
Dim Sset As AcadSelectionSet

Pt1 = ThisDrawing.Utility.GetPoint(, "Select the First Point")
Pt2 = ThisDrawing.Utility.GetPoint(, "Select the Second Point")

'create Sset object first
Set Sset = ThisDrawing.SelectionSets.Add("Sset")

Sset.Select acSelectionSetCrossing, Pt1, Pt2

MsgBox "Count = " & Sset.Count

'get rid of selection set
Sset.Delete
Set Sset = Nothing
End Sub



wrote in message news:6016911@discussion.autodesk.com...
Hi,
If u do not mind than please tell me in the program below how to calculate
the length of selection set.
thanks

Private Sub cmdBt1_Click()

On Error Resume Next
Dim ss As AcadSelectionSet
Dim Pt1 As Variant
Dim Pt2 As Variant
Dim sslength As Integer
Form1.hide
Pt1 = ThisDrawing.Utility.GetPoint(, "Select First Point")
Pt2 = ThisDrawing.Utility.GetPoint(, "Select Second Point")

'create Sset object first
ss.Select acSelectionSetCrossing, Pt1, Pt2

Set ss = ThisDrawing.SelectionSets.Item("MySSet")
If ss Is Nothing Then
Set ss = ThisDrawing.SelectionSets.Add("MySSet")
End If
sslength =
AutoCAD.Application.ActiveDocument.SelectionSets.SelectionSet.count
End Sub
0 Likes
Message 3 of 7

Anonymous
Not applicable
hi,
in the program below i am getting one error that is "The Name Selection Set Exist"
Can u tell what is that and why this problem is appearing while in the this problem is not there.

Private Sub cmdBt1_Click()
'On Error Resume Next
Dim Pt1 As Variant
Dim Pt2 As Variant
Dim Sset As AcadSelectionSet
Dim Count As Integer

Form1.hide
Pt1 = ThisDrawing.Utility.GetPoint(, "Select the First Point")
Pt2 = ThisDrawing.Utility.GetPoint(Pt1, "Select the Second Point")
'Create Sset object first
Set Sset = ThisDrawing.SelectionSets.Add("Sset")

Sset.Select acSelectionSetCrossing, Pt1, Pt2
'Form1.Show
'TxtBox1.Text = Sset.Count

MsgBox "Count = " & Sset.Count

'get rid of selection set
Sset.Delete
Set Sset = Nothing
End Sub
0 Likes
Message 4 of 7

Anonymous
Not applicable
hi,
IN the begning it is wroking good but later on error is coming and also nothing is highlighted in the text box1.
Please Tell me where the problem is.
thanks
Private Sub cmdBt1_Click()
On Error Resume Next
Dim Pt1 As Variant
Dim Pt2 As Variant
Dim Sset As AcadSelectionSet
Dim Count As Integer

Form1.hide
Pt1 = ThisDrawing.Utility.GetPoint(, "Select the First Point")
Pt2 = ThisDrawing.Utility.GetPoint(Pt1, "Select the Second Point")
'Create Sset object first
Set Sset = ThisDrawing.SelectionSets.Item("Myss")
If Sset Is Nothing Then
Set Sset = ThisDrawing.SelectionSets.Add("Myss")
Else
Sset.Clear
End If
Sset.Select acSelectionSetCrossing, Pt1, Pt2
Form1.Show
txtbox1.Text = Str(Sset.Count)
MsgBox "Count = " & Sset.Count

'get rid of selection set
Sset.Delete
Set Sset = Nothing
End Sub
0 Likes
Message 5 of 7

Anonymous
Not applicable
one way is to replace

Set Sset = ThisDrawing.SelectionSets.Item("Myss")
If Sset Is Nothing Then
Set Sset = ThisDrawing.SelectionSets.Add("Myss")
Else
Sset.Clear
End If

with

On Error Resume Next
ThisDrawing.SelectionSets.Item("Myss").delete
On Error GoTo 0
Set sset = ThisDrawing.SelectionSets.Add("Myss")

also
Form1.txtbox1.Text = Str(Sset.Count)
might be needed
0 Likes
Message 6 of 7

Anonymous
Not applicable
hi, i am just new to VBA so please do not mind
here i want to go through the selection set and display the name every entity of the selection set please can u help.
thanks

Private Sub cmdBt1_Click()
Dim Pt1 As Variant
Dim Pt2 As Variant
Dim Sset As AcadSelectionSet
Dim Count As Integer
Dim Eobject As AcadEntity


Form1.hide
Pt1 = ThisDrawing.Utility.GetPoint(, "Select the First Point")
Pt2 = ThisDrawing.Utility.GetPoint(Pt1, "Select the Second Point")
On Error Resume Next
ThisDrawing.SelectionSets.Item(Sset).Delete
On Error GoTo 0
Set Sset = ThisDrawing.SelectionSets.Add("Sset")
Sset.Select acSelectionSetCrossing, Pt1, Pt2
Form1.Show
Form1.txtbox1.Text = str(Sset.Count)
'MsgBox "Count = " & Sset.Count
Unload Form1

'Type of Entities
Dim objstring As String
For Each Eobject In Sset
objstring = objstring & vbCr & Sset.Name
Next
MsgBox objstring, , "List of Selection Sets"
End Sub
0 Likes
Message 7 of 7

Anonymous
Not applicable
Hi kulfi,

If you want to be a programmer, you are going to have to learn to do
some work and think for yourself.

Why do you expect every time you clipboard something together that
readers of this newsgroup are going to do the work for you?

I suggest you step through this code yourself with the F8 key and find
the errors and THINK about what may be causing them. Then try to fix
them yourself if you can. That way you will learn something.

If you are really stumped then post an explanation of what you did to
fix your problem and make it easier for others to help you.

Admittedly the error in the line:

ThisDrawing.SelectionSets.Item(Sset).Delete

may prove hard to find as you are bypassing the error in it with the line:

On Error Resume Next.

Look at the sample code you were given by Cadger and fix this error
yourself before moving on the the errors of logic and common sense in
the rest of the code. All of these will be obvious as you step through
the code.



Regards


Laurie Comerford

kulfi wrote:
> hi, i am just new to VBA so please do not mind
> here i want to go through the selection set and display the name every entity of the selection set please can u help.
> thanks
>
> Private Sub cmdBt1_Click()
> Dim Pt1 As Variant
> Dim Pt2 As Variant
> Dim Sset As AcadSelectionSet
> Dim Count As Integer
> Dim Eobject As AcadEntity
>
>
> Form1.hide
> Pt1 = ThisDrawing.Utility.GetPoint(, "Select the First Point")
> Pt2 = ThisDrawing.Utility.GetPoint(Pt1, "Select the Second Point")
> On Error Resume Next
> ThisDrawing.SelectionSets.Item(Sset).Delete
> On Error GoTo 0
> Set Sset = ThisDrawing.SelectionSets.Add("Sset")
> Sset.Select acSelectionSetCrossing, Pt1, Pt2
> Form1.Show
> Form1.txtbox1.Text = str(Sset.Count)
> 'MsgBox "Count = " & Sset.Count
> Unload Form1
>
> 'Type of Entities
> Dim objstring As String
> For Each Eobject In Sset
> objstring = objstring & vbCr & Sset.Name
> Next
> MsgBox objstring, , "List of Selection Sets"
> End Sub
0 Likes