.NET

.NET

Reply
Valued Contributor
86 Posts
1 Kudo
Registered: ‎07-14-2010
Post 1 of 11

Finding out when a custom PaletteSet is closed in AutoCAD using .NET code crash

416 Views, 10 Replies
07-03-2012 01:06 AM

Hi Guys,

 

I would like to do something when my paletteset is closed. I took the C# code from here

http://through-the-interface.typepad.com/through_the_interface/2011/12/finding-out-when-a-custom-pal...

 

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.SendStringToExecute("CHECKPALETTESETCLOSE", True, True, False)
        End If
    End Sub

    <Autodesk.AutoCAD.Runtime.CommandMethod("CHECKPALETTESETCLOSE", CommandFlags.NoHistory)> _
    Public Sub CheckPaletteSetState()
        If Not ps Is Nothing And ps.Visible = False Then
            Application.DocumentManager.MdiActiveDocument.Editor.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.

 

Any ideas?

 

Thanks

*Expert Elite*
9,832 Posts
1,218 Kudos
Registered: ‎06-29-2007
Post 2 of 11

Re: Finding out when a custom PaletteSet is closed in AutoCAD using .NET code cr

07-03-2012 01:11 AM in reply to: yaqiz

Hi,

 

first guess: don't check only for "Is Nothing" but also for "ps.IsDisposed"

 

HTH, - alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Valued Contributor
86 Posts
1 Kudo
Registered: ‎07-14-2010
Post 3 of 11

Re: Finding out when a custom PaletteSet is closed in AutoCAD using .NET code cr

07-03-2012 01:14 AM in reply to: Alfred.NESWADBA

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

 

*Expert Elite*
9,832 Posts
1,218 Kudos
Registered: ‎06-29-2007
Post 4 of 11

Re: Finding out when a custom PaletteSet is closed in AutoCAD using .NET code cr

07-03-2012 01:26 AM in reply to: yaqiz

Hi,

 

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 -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Valued Contributor
86 Posts
1 Kudo
Registered: ‎07-14-2010
Post 5 of 11

Re: Finding out when a custom PaletteSet is closed in AutoCAD using .NET code cr

07-03-2012 01:31 AM in reply to: Alfred.NESWADBA

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

*Expert Elite*
9,832 Posts
1,218 Kudos
Registered: ‎06-29-2007
Post 6 of 11

Re: Finding out when a custom PaletteSet is closed in AutoCAD using .NET code cr

07-03-2012 08:51 AM in reply to: yaqiz

Hi,

 

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 -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
*Expert Elite*
753 Posts
54 Kudos
Registered: ‎02-13-2008
Post 7 of 11

Re: Finding out when a custom PaletteSet is closed in AutoCAD using .NET code cr

07-03-2012 11:58 AM in reply to: Alfred.NESWADBA

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

 

Dave O.                                                                  Sig-Logos32.png
Valued Contributor
86 Posts
1 Kudo
Registered: ‎07-14-2010
Post 8 of 11

Re: Finding out when a custom PaletteSet is closed in AutoCAD using .NET code cr

07-04-2012 01:55 AM in reply to: chiefbraincloud

Thanks for your reply.

 

Have you try to implement that code segement? Does that work as it should be?

*Expert Elite*
753 Posts
54 Kudos
Registered: ‎02-13-2008
Post 9 of 11

Re: Finding out when a custom PaletteSet is closed in AutoCAD using .NET code cr

07-05-2012 12:31 AM in reply to: yaqiz

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.

Dave O.                                                                  Sig-Logos32.png
Valued Mentor
370 Posts
175 Kudos
Registered: ‎05-06-2012
Post 10 of 11

Re: Finding out when a custom PaletteSet is closed in AutoCAD using .NET code cr

07-05-2012 01:05 PM in reply to: yaqiz
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!