View Full Version : Mysterious OSMODE
BoKirra
2008-11-20, 12:29 AM
Hi ALL,
One of my routines doesn't work properly.
I noticed that this problem could be solved only if OSMODE was reset to 0.
I want to set OSMODE to 111 because of the insertion purpose, obviously.
;---------------------------------------------------------------------------------;
(defun DTR (A) (* pi (/ A 180.0)))
;---------------------------------------------------------------------------------;
(defun c:TEST
(/ IPt sHigh sWidth sThick PT1 PT2 PT3 PT4 PT5 PT6 PT7)
(setvar "osmode" 111)
(setq IPt (getpoint "\nselect Insert Point: "))
(setq sHigh (getdist "\nEnter Section Height: "))
(setq sWidth (getdist "\nEnter Section Width: "))
(setq sThick (getdist "\nEnter Section Thickness: "))
(setq
PT1 (polar IPt (DTR 90) sHigh)
PT2 (polar PT1 (DTR 0) sWidth)
PT3 (polar IPt (DTR 0) sWidth)
PT4 (polar PT3 (DTR 180) sThick)
PT5 (polar PT4 (DTR 90) (- sHigh sThick))
PT6 (polar PT5 (DTR 180) (- sWidth (* sThick 2.0)))
PT7 (polar IPt (DTR 0) sThick)
) ;end setq
(command "pline" IPt PT1 PT2 PT3 PT4 PT5 PT6 PT7 IPt "")
(setvar "osmode" 695)
(princ)
)
It drives me crazy.
A drawing is attached.
3 sections in the drawing were drawn by the routine with same inputs:
High=100
Width=200
Thick=1.5
Thanks in advance.
kennet.sjoberg
2008-11-20, 02:03 AM
Then tiny distance grabs objects close to each others even them selves, so you have to set osmode 0 before the pline command,
OR reassigne the pline command to not grab.
(command "pline" "_none" IPt "_none" PT1 "_none" PT2 "_none" PT3 "_none" PT4 "_none" PT5 "_none" PT6 "_none" PT7 "_none" IPt "" )
: ) Happy Computing !
kennet
BTW osmode 111 is my favourite osmode number 8)
BoKirra
2008-11-20, 02:27 AM
Then tiny distance grabs objects close to each others even them selves, so you have to set osmode 0 before the pline command,
OR reassigne the pline command to not grab.
(command "pline" "_none" IPt "_none" PT1 "_none" PT2 "_none" PT3 "_none" PT4 "_none" PT5 "_none" PT6 "_none" PT7 "_none" IPt "" )
: ) Happy Computing !
kennet
BTW osmode 111 is my favourite osmode number 8)
Thanks!
It works...
But another mystery, I can't find "_none" under "PLINE" in HELP.
Could you please explain what does "_none" do exactly & where to find it in HELP?
If, if I have to place "_none" to each point in pline command, each routine, it will make my LISP life to hard.:roll:
It there a simple solution?
Thanks again.
RobertB
2008-11-20, 06:47 AM
But another mystery, I can't find "_none" under "PLINE" in HELP.
Could you please explain what does "_none" do exactly & where to find it in HELP?"None" is an OSnap override. Just the same as typing "Mid" and a prompt to select a point to force AutoCAD to find the midpoint of the selected object. None forces AutoCAD to ignore running OSnaps for the next point picked.
If you use the (command) function, the best mothod is as Kennet showed you: to use the "_None" override. However, you can also temporarily turn off running OSnaps by setting bit 16384 (?, working from memory) on the OSMode system variable. However, you mentioned wanting the set a running OSnap, so that's a lot of back-and-forth. If the user cancels the routine (or worse, it crashes) the user could well be left with a running OSnap they don't want.
So (command ... "_none" ...) is the "safest" way to code it.
BoKirra
2008-11-21, 01:10 AM
"None" is an OSnap override. Just the same as typing "Mid" and a prompt to select a point to force AutoCAD to find the midpoint of the selected object. None forces AutoCAD to ignore running OSnaps for the next point picked.
If you use the (command) function, the best mothod is as Kennet showed you: to use the "_None" override. However, you can also temporarily turn off running OSnaps by setting bit 16384 (?, working from memory) on the OSMode system variable. However, you mentioned wanting the set a running OSnap, so that's a lot of back-and-forth. If the user cancels the routine (or worse, it crashes) the user could well be left with a running OSnap they don't want.
So (command ... "_none" ...) is the "safest" way to code it.
Thanks, Robert.
In my situation,
1) if without using "_None", I have to set osmode /= 0 because I need to put the object to the right position.
2) and by following your idea, I only have one single choice of inserting "_none" to drawing commands - at every single vertex.
3) and if the object is complicate, say, it has 50 vertexes, then this would be a nightmare!
4) the difference between drawing on screen & LISP is that LISP may grab points together while drawing on screen certainly is perfect. - I am not saying putting LISPs to the bin.:?
5) I wish if it is possible to add a SV resolving this problem. I then could sleep all night.:lol:
kennet.sjoberg
2008-11-21, 05:48 PM
You can do like this as well. . .
(defun c:TEST (/ DTR OldOsm IPt sHigh sWidth sThick PT1 PT2 PT3 PT4 PT5 PT6 PT7 )
(defun DTR (A / ) (* pi (/ A 180.0 )) ) ; local function
(setq OldOsm (getvar "OSMODE" ) ) ; save user osmode setting
(setq IPt (getpoint "\nselect Insert Point: " ) )
(setq sHigh (getdist "\nEnter Section Height: " ) )
(setq sWidth (getdist "\nEnter Section Width: " ) )
(setq sThick (getdist "\nEnter Section Thickness: " ) )
(setq
PT1 (polar IPt (DTR 90 ) sHigh )
PT2 (polar PT1 (DTR 0 ) sWidth )
PT3 (polar IPt (DTR 0 ) sWidth )
PT4 (polar PT3 (DTR 180 ) sThick )
PT5 (polar PT4 (DTR 90 ) (- sHigh sThick ) )
PT6 (polar PT5 (DTR 180 ) (- sWidth (* sThick 2.0 )) )
PT7 (polar IPt (DTR 0 ) sThick )
) ;end setq
(setvar "OSMODE" 0 ) ; set program osmode
(command "._pline" IPt PT1 PT2 PT3 PT4 PT5 PT6 PT7 IPt "" )
(setvar "OSMODE" OldOsm ) ; restore user mode setting
(princ)
)
If you escape when the ._pline command is running the users osmode is not reset,
you must add an errorhandler to take care of that.
How to do it you will find in the "Anatomy of an AUTOLISP file" thread.
You may also make the errorhandler to take care if any of the getpoint/getdist values is missing.
Or use the initget function to make them secure.
: ) Happy Computing !
kennet
BoKirra
2008-11-23, 11:22 PM
You can do like this as well. . .
(defun c:TEST (/ DTR OldOsm IPt sHigh sWidth sThick PT1 PT2 PT3 PT4 PT5 PT6 PT7 )
(defun DTR (A / ) (* pi (/ A 180.0 )) ) ; local function
(setq OldOsm (getvar "OSMODE" ) ) ; save user osmode setting
(setq IPt (getpoint "\nselect Insert Point: " ) )
(setq sHigh (getdist "\nEnter Section Height: " ) )
(setq sWidth (getdist "\nEnter Section Width: " ) )
(setq sThick (getdist "\nEnter Section Thickness: " ) )
(setq
PT1 (polar IPt (DTR 90 ) sHigh )
PT2 (polar PT1 (DTR 0 ) sWidth )
PT3 (polar IPt (DTR 0 ) sWidth )
PT4 (polar PT3 (DTR 180 ) sThick )
PT5 (polar PT4 (DTR 90 ) (- sHigh sThick ) )
PT6 (polar PT5 (DTR 180 ) (- sWidth (* sThick 2.0 )) )
PT7 (polar IPt (DTR 0 ) sThick )
) ;end setq
(setvar "OSMODE" 0 ) ; set program osmode
(command "._pline" IPt PT1 PT2 PT3 PT4 PT5 PT6 PT7 IPt "" )
(setvar "OSMODE" OldOsm ) ; restore user mode setting
(princ)
)
If you escape when the ._pline command is running the users osmode is not reset,
you must add an errorhandler to take care of that.
How to do it you will find in the "Anatomy of an AUTOLISP file" thread.
You may also make the errorhandler to take care if any of the getpoint/getdist values is missing.
Or use the initget function to make them secure.
: ) Happy Computing !
kennet
Kennet,
Thanks for your explanation which is rich in details & certainly very helpful.
& I am reading "initget" in HELP, see if it make sense to me.
Now I can see that my LISP Kindy Certificate is not far away...
Cheers with :beer::beer::beer:
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.