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.
Solved! Go to Solution.
Solved by gopinath.taget. Go to Solution.
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 -
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.
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 -
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".
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:
...maybe we get any info that gives us a chance to work on/to check.
- alfred -
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:
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.
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>