.NET

Reply
Valued Contributor
yaqiz
Posts: 86
Registered: ‎07-14-2010
Message 1 of 11 (391 Views)

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

391 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*
Alfred.NESWADBA
Posts: 9,417
Registered: ‎06-29-2007
Message 2 of 11 (390 Views)

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
yaqiz
Posts: 86
Registered: ‎07-14-2010
Message 3 of 11 (389 Views)

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*
Alfred.NESWADBA
Posts: 9,417
Registered: ‎06-29-2007
Message 4 of 11 (386 Views)

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
yaqiz
Posts: 86
Registered: ‎07-14-2010
Message 5 of 11 (385 Views)

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*
Alfred.NESWADBA
Posts: 9,417
Registered: ‎06-29-2007
Message 6 of 11 (373 Views)

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*
chiefbraincloud
Posts: 753
Registered: ‎02-13-2008
Message 7 of 11 (366 Views)

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
yaqiz
Posts: 86
Registered: ‎07-14-2010
Message 8 of 11 (349 Views)

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*
chiefbraincloud
Posts: 753
Registered: ‎02-13-2008
Message 9 of 11 (334 Views)

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
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 10 of 11 (328 Views)

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 Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!