I would like to do something when my paletteset is closed. I took the C# code from here
I modified the code to VB.net
Dim WithEvents ps As Autodesk.AutoCAD.Windows.PaletteSet <Autodesk.AutoCAD.Runtime.CommandMethod("psTest")> _ Public Sub PSTest() If ps Is Nothing Then ps = New Autodesk.AutoCAD.Windows.PaletteSet("psTest") ps.Dock = Autodesk.AutoCAD.Windows.DockSides.Left ps.Visible = True End If End Sub Private Sub ps_StateChanged(ByVal sender As Object, ByVal e As Autodesk.AutoCAD.Windows.PaletteSetStateEventArgs) Handles ps.StateChanged If e.NewState = Autodesk.AutoCAD.Windows.StateEventIndex.Hide Then Application.DocumentManager.MdiActiveDocument.Send
StringToExecute("CHECKPALETTESETCLOSE", True, True, False) End If End Sub <Autodesk.AutoCAD.Runtime.CommandMethod("CHECKPALE TTESETCLOSE", CommandFlags.NoHistory)> _ Public Sub CheckPaletteSetState() If Not ps Is Nothing And ps.Visible = False Then Application.DocumentManager.MdiActiveDocument.Edit or.WriteMessage("closed") End If End Sub
My code crashed. If I catch exception it is eInvalidInput exception. I don't know what to do as it is a simple code segment I don't know hot to fix it.
first guess: don't check only for "Is Nothing" but also for "ps.IsDisposed"
HTH, - alfred -
Thanks for reply
the problem comes from here
Private Sub ps_StateChanged(ByVal sender As Object, ByVal e As Autodesk.AutoCAD.Windows.PaletteSetStateEventArgs) Handles ps.StateChanged If e.NewState = Autodesk.AutoCAD.Windows.StateEventIndex.Hide Then Application.DocumentManager.MdiActiveDocument.Send
StringToExecute("CHECKPALETTESETCLOSE", True, True, False) '--here is the exception End If End Sub
are you sure that you can run SendStringToExecute during this eventhandling? I fear NO ... to verify that: what happens if you send a _LINE-command?
PLUS: as it's a command defined by your app, why do you run this code with SendStringToExecute?
- alfred -
Thanks for reply. I don't know I took code from the post I found online(you can see in my main post). What I have done modify from c# to vb.net
I got reply from AutoCAD API support. They can replicate my issue. What I really want to do is to catch when user click paletteset "x" button rather than "-".
I don't know what to do
in most cases when using events where I need to run SendCommand (or similar) I usually redirect the event to a position when AutoCAD get's quiescent.
So in your eventhandler create a new one using AddHandler that points to a sub handling then the reached quiesent-state for AutoCAD.
HTH, - alfred -
From the next TTIF post after the one in the link above.
Something I should have mentioned about the reason for implementing a command, in the first place: the standard StateChanged event gets fired twice when undocking a palette set – once to hide it and once to display it again. This means we can’t assume a hide notification means the palette set is being closed – we really need to wait until the dust has settled before checking the state of the palette set in order to proclaim our verdict. Which is why we’re sending a command to be executed
Thanks for your reply.
Have you try to implement that code segement? Does that work as it should be?
Sorry, I don't really like palettes, and they don't really fit in with the kind of automations I am writing. So, no, I have not tried the code to verify it's operation. I just replied to try and answer Alfred's question about why the code uses a SendStringToExecute.
Start with some of our most frequented solutions to get help installing your software.