TheSwamp
Code Red => .NET => Topic started by: Eycki on December 02, 2011, 07:33:48 AM
-
Hello, I'm new here to the forum
I have a question: Is it possible to count your selection realtime (when making a fence in AutoCAD) ?
For instance, if you do a copy command in AutoCAD, you will see real-time on the command line how many you have selected.
e.g.:
1 found
2 found, 3 total
I would like to add these counted elements to a progressbar value.
-
Welcome. Editor.SelectionAdded Event might give you what you need
-
[CommandMethod("ssetwithcount")]
static public void SSet()
{
Document doc = acadApp.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
ed.SelectionAdded += new SelectionAddedEventHandler(sAdded);
PromptSelectionOptions SSO = new PromptSelectionOptions();
SSO.AllowDuplicates = false;
SSO.MessageForAdding = "Select:";
PromptSelectionResult PSR = ed.GetSelection(SSO);
if (PSR.Status != PromptStatus.OK) return;
SelectionSet SS = PSR.Value;
int i=0;
foreach (SelectedObject so in SS)
i++;
ed.WriteMessage("You selected " + i.ToString() + " objects");
ed.SelectionAdded -= new SelectionAddedEventHandler(sAdded);
}
private static void sAdded(object sender, SelectionAddedEventArgs e)
{
SelectionSet ss = e.AddedObjects;
int i = 0;
foreach (SelectedObject so in ss)
i++;
acadApp.DocumentManager.MdiActiveDocument.Editor.WriteMessage("You added " + i.ToString() + " objects");
}
-
Thanks a lot for the code, I converted it to VB.NET, it all works fine exept that "SelectionAdded" doesn't seem to be a part of the editor :s What am I doing wrong? If I type it straight after doc.editor.selectionadded it does exist but not like ed.selectionadded.
Look my code below in VB.NET
Thx in advance!
<CommandMethod("ssetwithcount")> _
Public Sub SSet()
Dim doc = Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = doc.Editor
ed.SelectionAdded += New SelectionAddedEventHandler(AddressOf sAdded)
Dim SSO As New PromptSelectionOptions()
SSO.AllowDuplicates = False
SSO.MessageForAdding = "Select:"
Dim PSR As PromptSelectionResult = ed.GetSelection(SSO)
If PSR.Status <> PromptStatus.OK Then
Return
End If
Dim SS As SelectionSet = PSR.Value
Dim i As Integer = 0
For Each so As SelectedObject In SS
i += 1
Next
ed.WriteMessage("You selected " & i.ToString() & " objects")
ed.SelectionAdded -= New SelectionAddedEventHandler(AddressOf sAdded)
End Sub
Private Sub sAdded(ByVal sender As Object, ByVal e As SelectionAddedEventArgs)
Dim ss As SelectionSet = e.AddedObjects
Dim i As Integer = 0
For Each so As SelectedObject In ss
i += 1
Next
Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("You added " & i.ToString() & " objects")
End Sub
-
What am I doing wrong?
AddHandler ed.SelectionAdded, New SelectionAddedEventHandler(AddressOf sAdded)
Try
... do your thing here ...
Finally
RemoveHandler ed.SelectionAdded, New SelectionAddedEventHandler(AddressOf sAdded)
End Try
And BTW, maybe you'd like to look into the SelectionRemoved event too.
-
What am I doing wrong?
AddHandler ed.SelectionAdded, New SelectionAddedEventHandler(AddressOf sAdded)
Try
... do your thing here ...
Finally
RemoveHandler ed.SelectionAdded, New SelectionAddedEventHandler(AddressOf sAdded)
End Try
And BTW, maybe you'd like to look into the SelectionRemoved event too.
That's it! Thank you so much for the help.