Author Topic: SHIFT Ortho Temp override break my OSmode reset.  (Read 3491 times)

0 Members and 1 Guest are viewing this topic.

BazzaCAD

  • Guest
SHIFT Ortho Temp override break my OSmode reset.
« on: May 20, 2013, 07:38:27 PM »
OK, given my little sample code below, if you pick the first point & then hold down shift (to get the temp ortho override) then pick the send point, you'll notice that the osmode never gets reset back to it's original value. It says at 555. How can I get my code to work with the temp override, but still reset the osmode?

Code - Auto/Visual Lisp: [Select]
  1.   (Setq oldMode (getvar "OSMODE"))
  2.   (setvar "OSMODE" 555)
  3.   (setq p1 (getpoint "\nFirst point: "))
  4.   (setq p2 (getpoint "\nSecond point: " p1))
  5.   (command ".LINE" p1 p2 "")
  6.   (setvar "OSMODE" oldMode)
  7.  

I guess I should note that I'm on Acad 2012, as this feature seems to be different per version.

In CUI, my Macro 1 for "Toggle Ortho Mode" - SHIFT:
Code: [Select]
^P'_.orthomode $M=$(if,$(and,$(getvar,orthomode),1),$(-,$(getvar,orthomode),1),$(+,$(getvar,orthomode),1))
« Last Edit: May 20, 2013, 07:45:09 PM by BazzaCAD »

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: SHIFT Ortho Temp override break my OSmode reset.
« Reply #1 on: May 21, 2013, 01:59:30 AM »
Very strange. I can't see a "problem" with the code. Have you tried using VLIDE to see if the last setvar gets reached? Lee's got a great tutorial on how to use VLIDE to debug code: http://www.lee-mac.com/debugvlide.html

Only one suggestion: When sending the points to the line command, use the "_Non" object snap to ensure it doesn't inadvertently snap to something else.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Russelltimk

  • Guest
Re: SHIFT Ortho Temp override break my OSmode reset.
« Reply #2 on: May 21, 2013, 03:34:17 AM »
I think that when you hold down the "shift" key it may put the OSMODE into some sort of read only state. I modified your command to run 'osmode transparently after generating the points, and although everything looked like it worked from the command line, it still wouldn't change the OSMODE back.... the command executes faster than shift can be released.

The only thing I found that works is to break the process with an alert window. Try this, will alert if shift key is held down on last line created:
Code: [Select]
(defun C:test1 ()

(Setq oldMode (getvar "OSMODE"))
(setvar "OSMODE" 555)
(setq p1 (getpoint "\nFirst point: "))   
(setq p2 (getpoint "\nSecond point: " p1))
(command ".LINE" p1 p2 "")

(if (acet-sys-shift-down) (alert "Release Shift Key Please"))
 
(setvar "OSMODE" oldMode)
(princ)

       )

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: SHIFT Ortho Temp override break my OSmode reset.
« Reply #3 on: May 21, 2013, 05:39:32 AM »
That might be a posibility. Perhaps adding a pause command just before the setvar might help in allowing the Shift lock to be released.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

BazzaCAD

  • Guest
Re: SHIFT Ortho Temp override break my OSmode reset.
« Reply #4 on: May 21, 2013, 12:52:32 PM »
Thanks for the replies guys.
Yes the alert does work, but my users would get very annoyed if that popped up every time.

I also tried adding:
(command PAUSE)
Just before the last setvar & it didn't help.
I'm starting to think this is an Acad bug...

andrew_nao

  • Guest
Re: SHIFT Ortho Temp override break my OSmode reset.
« Reply #5 on: May 21, 2013, 01:10:47 PM »
i dont have a solution but i can confirm this does the same thing in 2014

Russelltimk

  • Guest
Re: SHIFT Ortho Temp override break my OSmode reset.
« Reply #6 on: May 21, 2013, 10:07:47 PM »
Understood about the alert pop-up. Not sure if its a bug, it might be acting as designed to protect snap modes from getting lost in between commands...

What about this?
Code: [Select]
(defun C:test1 ()

(Setq oldMode (getvar "OSMODE"))
(setvar "OSMODE" 555)
(setq p1 (getpoint "\nFirst point: "))   
(setq p2 (getpoint "\nSecond point: " p1))
(command ".LINE" p1 p2 "")

(while (acet-sys-shift-down) (command "delay" 1))
 
(setvar "OSMODE" oldMode)
(princ)

       )


You can cmdecho out the status line updates, just left in to give you an idea how long it takes to register shift release.

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: SHIFT Ortho Temp override break my OSmode reset.
« Reply #7 on: May 22, 2013, 01:20:03 AM »
The same problem here with Autocad 2014 ( not resetting the osmode back if the shift button pressed down while picking the second point )

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: SHIFT Ortho Temp override break my OSmode reset.
« Reply #8 on: May 22, 2013, 01:50:02 AM »
Oops! Not "pause", but "delay" ... sorry!
You can cmdecho out the status line updates, just left in to give you an idea how long it takes to register shift release.
You mean something lie this?
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test (/ settings p1 p2)
  2.   ;; Set and save setvar settings
  3.   (foreach s '((OSMode 555) (CmdEcho 0))
  4.     (setq settings (cons (list (car s) (getvar (car s))) settings))
  5.     (apply 'setvar s))
  6.  
  7.   ;; Get the points & draw line
  8.   (if (and (setq p1 (getpoint "\nFirst point: "))
  9.            (setq p2 (getpoint "\nSecond point: " p1)))
  10.     (command "_.LINE" "_Non" p1 "_Non" p2 ""))
  11.  
  12.   ;; Wait for the shift key to be released
  13.   (while (acet-sys-shift-down) (command "delay" 1))
  14.  
  15.   ;; Reset the setvar settings
  16.   (mapcar 'setvar settings)
  17.   (princ))
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: SHIFT Ortho Temp override break my OSmode reset.
« Reply #9 on: May 22, 2013, 01:51:21 AM »
BTW, if you don't have Express tools the acet-* functions aren't available. You might want to look at using these instead.
http://www.theswamp.org/index.php?topic=19644.5
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: SHIFT Ortho Temp override break my OSmode reset.
« Reply #10 on: May 22, 2013, 08:34:06 AM »
Odd, I just ran the following code in 2011 and 2012 and never had an issue. I executed in once just picked two points and once holding shift down for temp ortho. Always displayed the same osmode number.

Code: [Select]
(defun c:test (/ oldmode p1 p2)
  (Setq oldMode (getvar "OSMODE"))
  (setvar "OSMODE" 555)
  (setq p1 (getpoint "\nFirst point: "))
  (setq p2 (getpoint "\nSecond point: " p1))
  (command ".LINE" p1 p2 "")
  (print (setvar "OSMODE" oldMode))
  (princ)
)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: SHIFT Ortho Temp override break my OSmode reset.
« Reply #11 on: May 22, 2013, 08:52:37 AM »
I know there was some issue with the Shift key and temporary OSnap overrides: http://forums.augi.com/showthread.php?142257-Temp-Osnap-Overrides

Perhaps that's still the issue. I've tried this a few times in 2013. Sometimes it works, and other times it doesn't. I've changed that to show the OSMode at more points in the code:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test  (/ oldmode p1 p2)
  2.   (print (Setq oldMode (getvar "OSMODE")))
  3.   (print (setvar "OSMODE" 555))
  4.   (setq p1 (getpoint "\nFirst point: "))
  5.   (setq p2 (getpoint "\nSecond point: " p1))
  6.   (print (getvar "OSMODE"))
  7.   (command ".LINE" p1 p2 "")
  8.   (print (getvar "OSMODE"))
  9.   (print (setvar "OSMODE" oldMode))
  10.   (print (getvar "OSMODE"))
  11.   (princ))
Here's the command line history:
Code: [Select]
Command: test
111
555
First point:
Second point:
555 .LINE
Specify first point:
Specify next point or [Undo]:
Specify next point or [Undo]:
Command:
555
111
111

Command:  TEST

111
555
First point:
Second point:
555 .LINE
Specify first point:
Specify next point or [Undo]:
Specify next point or [Undo]:
Command:
555
111
111

Command:  TEST

555
555
First point:
Second point:
555 .LINE
Specify first point:
Specify next point or [Undo]:
Specify next point or [Undo]:
Command:
555
555
555
The 2nd happened with Shift held down for the 2nd point only. With that last one I held the Shift down before picking the 1st point. But notice the "change" from 111 to 555 - which definitely "shouldn't" happen between the 2nd try finishing and the 3rd try starting ... should it? This is really vexing me - I can't understand why such should happen.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Russelltimk

  • Guest
Re: SHIFT Ortho Temp override break my OSmode reset.
« Reply #12 on: May 22, 2013, 09:05:45 PM »
Yup. Everything looks fine from the command line, as it did when i tested it, but its tricky...

Found this older article, explains what is going on here. Short story is it when shift is released it resets variables back to the point they were when key was pressed, so when its is released after a command is finished, it is restoring the wrong settings.

http://www.cadalyst.com/cad/autocad/bug-watch-losing-your-autocad-2006-settings-here039s-why-5382


I think the delay workaround is the best option to control this...

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: SHIFT Ortho Temp override break my OSmode reset.
« Reply #13 on: May 23, 2013, 01:17:10 AM »
Another alternative might be to use a reactor to reset the variables back to what they should be. But I think that might be complex as you'd need to have some mode global variable to stop the reactor from firing when you actually want to have the syvar changed.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

BazzaCAD

  • Guest
Re: SHIFT Ortho Temp override break my OSmode reset.
« Reply #14 on: May 24, 2013, 03:24:23 PM »
Thanks guys, the delay works great.