Author Topic: Tool palette, Object selection and Event  (Read 23864 times)

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5241
Re: Tool palette, Object selection and Event
« Reply #75 on: June 15, 2007, 06:33:55 PM »
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Paul Richardson

  • Guest
Re: Tool palette, Object selection and Event
« Reply #76 on: June 15, 2007, 07:06:53 PM »

T.Willey

  • Needs a day job
  • Posts: 5241
Re: Tool palette, Object selection and Event
« Reply #77 on: June 15, 2007, 07:33:29 PM »
"CMACTIVE"?
Typo.  :-)
Was that the problem or just a typo here?
Just a typo here.  I didn't copy/paste Tony's code, I just made the change he suggested.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

TonyT

  • Guest
Re: Tool palette, Object selection and Event
« Reply #78 on: June 16, 2007, 05:13:30 AM »
Hi Tim. I didn't check what type GetVariable() returns for CMDACTIVE,
so I'll guess that its a short.

If it's a short, then just cast the literal 0 to a short, like this:

   if( ! AcadApp.GetSystemVariable("CMDACTIVE").Equals( (short) 0 ) )
      ...

IMHO, it was a big screw up for Autodesk to not promote all
ordinal values returned by GetVariable() to integers, because
of this very issue.
     

"CMACTIVE"?
Typo.  :-)
Was that the problem or just a typo here?
Just a typo here.  I didn't copy/paste Tony's code, I just made the change he suggested.

Chuck Gabriel

  • Guest
Re: Tool palette, Object selection and Event
« Reply #79 on: June 16, 2007, 09:20:06 AM »
It definitely is a short.  I had to cast it to short in my HotKeys program, though I was using operator== for the comparison.

T.Willey

  • Needs a day job
  • Posts: 5241
Re: Tool palette, Object selection and Event
« Reply #80 on: June 18, 2007, 11:08:21 AM »
Hi Tim. I didn't check what type GetVariable() returns for CMDACTIVE,
so I'll guess that its a short.

If it's a short, then just cast the literal 0 to a short, like this:

   if( ! AcadApp.GetSystemVariable("CMDACTIVE").Equals( (short) 0 ) )
      ...

IMHO, it was a big screw up for Autodesk to not promote all
ordinal values returned by GetVariable() to integers, because
of this very issue.
     

"CMACTIVE"?
Typo.  :-)
Was that the problem or just a typo here?
Just a typo here.  I didn't copy/paste Tony's code, I just made the change he suggested.
Thanks Tony!  That was the problem.

It definitely is a short.  I had to cast it to short in my HotKeys program, though I was using operator== for the comparison.
Thanks Chuck for the conformation.

How did you guys know it was a short?  Is there a way to test what base class an object is, without knowing for sure?  Or is this just experience to know it's one or the other?
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Chuck Gabriel

  • Guest
Re: Tool palette, Object selection and Event
« Reply #81 on: June 18, 2007, 11:17:37 AM »
How did you guys know it was a short?  Is there a way to test what base class an object is, without knowing for sure?  Or is this just experience to know it's one or the other?

Glenn R told me. :-)

T.Willey

  • Needs a day job
  • Posts: 5241
Re: Tool palette, Object selection and Event
« Reply #82 on: June 18, 2007, 11:19:55 AM »
How did you guys know it was a short?  Is there a way to test what base class an object is, without knowing for sure?  Or is this just experience to know it's one or the other?

Glenn R told me. :-)
Nice!  :lmao:
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

TonyT

  • Guest
Re: Tool palette, Object selection and Event
« Reply #83 on: June 19, 2007, 08:10:03 AM »


How did you guys know it was a short?  Is there a way to test what base class an
object is, without knowing for sure?  Or is this just experience to know it's one or
the other?


Object.GetType() returns the actual type.

You can also see types in the debugger's watch and locals windows.


T.Willey

  • Needs a day job
  • Posts: 5241
Re: Tool palette, Object selection and Event
« Reply #84 on: June 19, 2007, 11:04:51 AM »


How did you guys know it was a short?  Is there a way to test what base class an
object is, without knowing for sure?  Or is this just experience to know it's one or
the other?


Object.GetType() returns the actual type.
I thought I had tried the Object.GetType() before and it just said object, but I guess I am remembering wrong as that worked.  Thanks Tony.

You can also see types in the debugger's watch and locals windows.
Another reason to learn more about the debugger.  I will learn it one day.  :-)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

gswang

  • Newt
  • Posts: 114
Re: Tool palette, Object selection and Event
« Reply #85 on: June 18, 2010, 09:20:01 PM »
Tim Willey, what's the final code?
thank you very much.

T.Willey

  • Needs a day job
  • Posts: 5241
Re: Tool palette, Object selection and Event
« Reply #86 on: June 22, 2010, 12:33:50 PM »
Tim Willey, what's the final code?
thank you very much.

I haven't used this code in awhile, but this is the latest one on my system.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

gswang

  • Newt
  • Posts: 114
Re: Tool palette, Object selection and Event
« Reply #87 on: June 23, 2010, 09:22:53 PM »
Thank you, Tim Willey, i'll try it.. :-)

murrdpirate

  • Guest
Re: Tool palette, Object selection and Event
« Reply #88 on: June 27, 2010, 04:52:47 PM »
I've found an alternative way to do this.  It seems a lot easier to implement, but I am not sure if it is more efficient, reliable, etc, so I will leave that up to more knowledgeable people to discuss.

The techniques used in this thread seemed too beyond me, so I thought maybe instead of going too deep into the AutoCAD API, I could use the Windows API to first detect if the left mouse button was clicked, then use the AutoCAD API to see if any objects are selected.  It is slightly more involved than normal to detect a mouse click outside your form/control, but after a bit of searching I found an easy method that works.  Here is what I did:

1)  Declare function "GetAsyncKeyState" from the user32 library
2)  Add a timer to my control
3)  Within the Timer1_Tick sub, use GetAsyncKeyState to see if the left-mouse button is down.
4)  If the left mouse button is down, see if objects are selected, see if any of the objects are of the type I care about, display properties, etc.

Here's the code:

Code: [Select]
Imports Spaces.SpaceClass

Public Class SpaceControlForm

    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If GetAsyncKeyState(1) = 0 Then
            ' Label1.Text = "Left mouse button up"
        Else
            ' Label1.Text = "Left mouse button down"
            MouseOverControl()
        End If
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer1.Enabled = True
    End Sub

End Class

The MouseOverControl sub just checks what, if any, entities are selected (using myEditor.SelectImplied) and then displays some properties of the entities I care about. 


murrdpirate

  • Guest
Re: Tool palette, Object selection and Event
« Reply #89 on: June 28, 2010, 11:30:50 AM »
Actually, I'm not sure using a timer is such a good idea.  I'm now using an AutoCAD event handler as Tim Wiley used.  I think I'm doing something very similar to his code, but here it is:

I want to use the event "ImpliedSelectionChanged," which fires whenever the list of currently selected entities changes, obviously.  To use events, you have to reference the AutoCAD.Interop library and assign the event to a method.

Here's some info on using events:  http://docs.autodesk.com/ACD/2011/ENU/filesMDG/WS73099cc142f48755-5c83e7b1120018de8c0-2465.htm

Code: [Select]
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim acDoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
        AddHandler acDoc.ImpliedSelectionChanged, AddressOf GetSelectedObjectIDs
End Sub

Shared Function GetSelectedObjectIDs()
        Dim myDB As Database = HostApplicationServices.WorkingDatabase
        Dim myEditor As Editor = Application.DocumentManager.MdiActiveDocument.Editor
        Dim PossibleSelectionSet As PromptSelectionResult = myEditor.SelectImplied
        Dim mySelectionSet As SelectionSet = Nothing
        Dim myObjectIDs As New List(Of ObjectId)

        If PossibleSelectionSet.Status = PromptStatus.OK Then
            Using myTrans As Transaction = myDB.TransactionManager.StartTransaction
                mySelectionSet = PossibleSelectionSet.Value
                For Each mySelObj As SelectedObject In mySelectionSet
                   myObjectIDs.Add(mySelObj.ObjectId)
                Next
            End Using
        End If
        Return myObjectIDs
End Function