.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Toggle LWDISPLAY system variable

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
SRSDS
1567 Views, 9 Replies

Toggle LWDISPLAY system variable

Hi,

Can someone suggest why I would get an eInvalidInput error when toggling  a system variable.

I've tried a few things which is why it's 4 lines instead of 1.

 

        Dim lwdisplay As Object = Application.GetSystemVariable("LWDISPLAY")
        If CShort(lwdisplay) = 0 Then
            Application.SetSystemVariable("LWDISPLAY", CShort(1))
        End If

  It generally works but every so often produces an error and I can't figure out why. 

 

9 REPLIES 9
Message 2 of 10
Alfred.NESWADBA
in reply to: SRSDS

Hi,

 

at least the question is the line ... in which line does your code throw an exception?

 

And for doing that in one line ... use this (but it's not faster and it's not easier to read):

   <Runtime.CommandMethod("ADESK_ToggleLWDisp")> _
   Public Shared Sub ADESK_ToggleLWShow()
      Application.SetSystemVariable("LWDISPLAY", Math.Abs(CType(Application.GetSystemVariable("LWDISPLAY"), Integer) - 1))
   End Sub

 this command I have tried (many times) with 2010/32bit, 2010/64bit, 2012/64bit and I could not reproduce a crash. The difference might be that I run that from a command?

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 3 of 10
SRSDS
in reply to: Alfred.NESWADBA

Hi Alfred,

 

I must have forgotten to look into this but have rediscoverd the problem.

 

Even using 

 

        Dim lwdisplay As Object = Application.GetSystemVariable("LWDISPLAY")
        If CShort(lwdisplay) = 0 Then
            Application.SetSystemVariable("LWDISPLAY", Math.Abs(CType(Application.GetSystemVariable("LWDISPLAY"), Integer) - 1))
        End If

 I still get an eInvalidInput error.

 

Seems like a basic toggle. 2011/32bit here.

 

 

Message 4 of 10
Alfred.NESWADBA
in reply to: SRSDS

Hi,

 

.... your code is not the same I wrote, your code just turns ON LWDISPLAY but never OFF.

 

What line does crash? What message do you get as Exception.Message? Have you tried my command exactly in the way I prepared it?

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 5 of 10
SRSDS
in reply to: Alfred.NESWADBA

It should do the same I would have thought. If 0 the abs(-1) should turn it on.

 

 

            Try
                Application.SetSystemVariable("LWDISPLAY", CInt(1))
            Catch
                Try
                    Application.SetSystemVariable("LWDISPLAY", CShort(1))
                Catch
                    Try
                        Application.SetSystemVariable("LWDISPLAY", CBool(1))
                    Catch
                        MsgBox("?")
                    End Try
                End Try
            End Try

 I get either eInvalidInput or "Value does not fall within the expected range".

Message 6 of 10
Alfred.NESWADBA
in reply to: SRSDS

Hi,

 

>> It should do the same I would have thought. If 0 the abs(-1) should turn it on

My code did toogle LWDISPLAY, if it's 0 then I turn it to 1, if it's one I change it to 0.

Your previous code had an if LWDISPLAY = 0 then included, so if LWDISPLAY was 1 there was never changed back to 0.

 

However, that's not the problem at the moment. Your code never works? Let me know what AutoCAD you exactly have now:

  • AutoCAD .... or vertical Product (like Mech, Map3D, Civil3D, ...)
  • what release?
  • 32bit/64bit?
  • what servicepack is installed
  • what version of VisualStudio do you have?
  • what Framework does your App use?

...maybe we get any info that gives us a chance to work on/to check.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 7 of 10
Hallex
in reply to: SRSDS

How about avoid using VBA-like types

        Public Sub togglelwdisplay()


            Dim lwdisplay As Short = Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("LWDISPLAY")


            If lwdisplay = 0 Then


                Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("LWDISPLAY", 1)


            Else


                Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("LWDISPLAY", 0)


            End If


        End Sub

 

 VBA-like types:

 

 

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 8 of 10
SRSDS
in reply to: Hallex

I think it's got something to do with using code in a palette.

It works fine when I move it to  the initialize component.

 

Attached is a VERY simple example of what I'm experiencing if someone's got time to look. 

Message 9 of 10
gopinath.taget
in reply to: SRSDS

Hi,

 

If it works in the Iniitialize component and not in a palette, it usually means your having a problem with the contexts (application/document contexts). Can you please try locking the active document in the palette code before you try to change the variable?

 

<code>

using(DocumentLock lk = Application.DocumentManager.MdiActiveDocument.LockDocument())

{

    // Do your thing

}

</code>

Message 10 of 10
SRSDS
in reply to: SRSDS

That was the solution.

My thanks to you and also Alfred and & Hallex.

Sorry for the trouble.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost