PDA

View Full Version : osnap's problem



j_r_auden
21st Dec 2004, 04:00 pm
This is a small function that breaks a line. The problem is that when o-snaps are on, it doesn't work. Any reason for this?? Is there some way to save the o-snap settings, turn them all off, and then restore them?? I would like to make this function work with o-snaps, but I just can't figure it out.

Also, I am not really sure why this function even works. When I call the break function from the command line, I have to enter "f" to specify first break point. I never send "f" to the command line in this function. What's going on there???

PLEASE HELP !!!!!!!!!!!!!!

(defun C:break ()
(setq myobject(ssget "_:S")) ;let user select object
(setq mypoint(getpoint "\nSelect Break Point")) ;let user select point
(command "break" myobject mypoint mypoint) ;break
(princ)
)

Kate M
21st Dec 2004, 05:28 pm
I'm gonna give this a shot (using what I learned at AU :-D)...if I'm wrong, I'm sure someone here can set me straight. :-)

I also changed the name of the function -- it's not generally a good idea to redefine core AutoCAD commands.


(defun C:mybreak ()
(setq o:os (getvar "osmode")) ;retrieves current osnap settings
(setvar "osmode" 0) ;turns off osnaps
(setq myobject(ssget "_:S")) ;let user select object
(setq mypoint(getpoint "\nSelect Break Point")) ;let user select point
(command "break" myobject mypoint mypoint) ;break
(setvar "osmode" o:os) ;resets original osnap settings
(princ)
)

j_r_auden
21st Dec 2004, 05:30 pm
I accidentally posted in the General forum, when i realized, I posted in the LISP/customization area.

Thanks for the help.
The routine you described works, but I am still not sure why it won't work with o-snaps on. Anybody know???

Fantomas
21st Dec 2004, 07:17 pm
1) Command Break has special syntax. As the first argument the list from a line and points is transferred. Try so, should work:

(command "_.break" (list myobject mypoint) mypoint)
2) Before any geometrical constructions with help AutoLISP OSNAP should be switched - off and then it is restored.

(defun C:break (/ myobject mypoint)
(setq myobject(ssget "_:S")) ;let user select object
(setq (getpoint "\nSelect Break Point")) ;let user select point
(setq oldOsnap(getvar "osmode")); SAVE OLD OSNAP
(setvar "osmode" 0); SWITCH OFF OSNAP
(command "break" (list myobject mypoint) mypoint) ;break
(setvar "osmode" oldOsnap) ;RESTORE OLD OSNAP
(princ)
)

hyposmurf
21st Dec 2004, 07:34 pm
Kate I've deleted that thread from before in the general forum to keep the forum tidy and re-attached the code you posted to your post above.

Fantomas
21st Dec 2004, 08:03 pm
>Kate M

(defun C:mybreak (/ *error* o:os myobject mypoint)

(defun *error* (msg)
(setvar "osmode" o:os)
(princ)
); end of *error*

.
.
.
.
.
(setvar "osmode" o:os)
(princ)
); end of C:mybreak


This better...

Kate M
21st Dec 2004, 08:08 pm
Fantomas,

Is the *error* function there so that it will reset even if you cancel/crash the program?

Fantomas
21st Dec 2004, 08:43 pm
Yes Kate. You swich off OSNAP, and have then created a situation when the user can press ESC. This function enables to restore OSNAP. Pay attention that function is located a kind of a local variable, it allows to not keep old value of GLOBAL function *ERROR*. Not everyone know this tip and write long global *ERROR* functions.

All kind. Excuse that has corrected you. :)

j_r_auden
21st Dec 2004, 09:03 pm
Does anybody know why this function won't work with o-snaps on??

Fantomas
21st Dec 2004, 10:18 pm
Does anybody know why this function won't work with o-snaps on??

It is general problem of AutoCAD+AutoLISP. Unfortunately at use of functions AutoLISP at included OSNAP commands of drawing and the instruction of points are carried out conformity with the nearest point on which specifies OSNAP, for example Endpoint. The great value on it is rendered with system variable APERTURE. However if that is required is possible to swich on and off selectively necessary OSNAPs. Value of variable OSMODE will consist of the sum of bit flags:

1-Endpoint
2-Midpoint
4-Center
8-Node
16-Quadrant
32-Intersection
64-Insert
128-Perpendicular
256-Tangent
512-Nearest
1024-Quick
2048-Apparent Intersection
4096-Extension
8192-Parallel

For exampe (setvar "osmode" 10) Swich on Midpoint and Node osnaps.

Try reduse APPERTURE and swich on only needed osnaps you need select point and swich of when COMMAND function in use.

All aforesaid can matter and at manual work. By the way all works for me...

The real programmer should understand that AutoCAD environment as far as is friendly so and hostile for his programs. Advice. Buy the good directory with system variables. Particularly I shall advise nothing because I read books in Russian.

Kate M
21st Dec 2004, 11:11 pm
Yes Kate. You swich off OSNAP, and have then created a situation when the user can press ESC. This function enables to restore OSNAP. Pay attention that function is located a kind of a local variable, it allows to not keep old value of GLOBAL function *ERROR*. Not everyone know this tip and write long global *ERROR* functions.
That's great -- I didn't know about *error* functions before. One thing, though -- if you select an object, then hit ESC, the OSNAP settings are not restored. Should the *error* function also be included somewhere else in the code?

(defun C:mybreak ()
(defun *error* (msg)
(setvar "osmode" o:os)
(princ)
); end of *error*
(setq o:os (getvar "osmode")) ;retrieves current osnap settings
(setvar "osmode" 0) ;turns off osnaps
(setq myobject(ssget "_:S")) ;let user select object
(setq mypoint(getpoint "\nSelect Break Point")) ;let user select point
(command "break" myobject mypoint mypoint) ;break
(setvar "osmode" o:os) ;resets original osnap settings
(princ)
)

Fantomas
22nd Dec 2004, 09:18 am
Yes Kate. In my example function *error* is included in the list of local variables:

(defun C:mybreak (/ *error* o:os myobject mypoint)
Function *error* is the built - in function of processing of errors and she is present at a standard kind. However the programmer can redefine actions of this function. In my example *error* it is located inside the basic function and consequently does not redefine the built - in function but only works on any mistake in program (include Esc).

If *error* that its redefinition without the subsequent restoration is not located can a source big problems in AutoCAD environment. However standard function is restored in the following session. Read this for more details http://www.afralisp.com/lispa/lisp6.htm

On this page you will not find an example with inclusion *error* in the list of local variables. However it shortens a code. Can consider it as Trick.

:)