Author Topic: osnap question  (Read 8513 times)

0 Members and 1 Guest are viewing this topic.

ELOQUINTET

  • Guest
osnap question
« on: August 13, 2004, 11:01:03 AM »
i have this code in my acaddoc.lsp file to reset my osnaps. what i'm wondering is how could i make this work transparently?

(DEFUN C:DK ()
(COMMAND "OSMODE" "127"))
(PRINC)

ELOQUINTET

  • Guest
osnap question
« Reply #1 on: August 13, 2004, 11:01:46 AM »
whoops that's

Code: [Select]
(DEFUN C:DK ()
(COMMAND "OSMODE" "127"))
(PRINC)

Andrew H

  • Guest
osnap question
« Reply #2 on: August 13, 2004, 12:02:21 PM »
I don't know about transparent, but I have my F1 key remapped to be my standard osnape stettings. It seems to work great. Let me know if you want me to post how to do this.

ELOQUINTET

  • Guest
osnap question
« Reply #3 on: August 13, 2004, 12:24:37 PM »
i know how to do that thanks anyway andrew. i would like to be able to reset my osnaps to my preferred setting while in a command.

Andrew H

  • Guest
osnap question
« Reply #4 on: August 13, 2004, 12:33:00 PM »
I just ran a test and if you setup your F1 key with 'osmode instead of just osmode it will run transparent.

ELOQUINTET

  • Guest
osnap question
« Reply #5 on: August 13, 2004, 12:51:52 PM »
thanks andrew i actually redefined F4 to be 'osmode;127 works like a charm thanks man

Andrew H

  • Guest
osnap question
« Reply #6 on: August 13, 2004, 12:52:42 PM »
anytime!!

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
osnap question
« Reply #7 on: August 13, 2004, 12:56:23 PM »
(defun c:dk () (setvar "osmode" 127) (princ))
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Andrew H

  • Guest
osnap question
« Reply #8 on: August 13, 2004, 12:58:56 PM »
how is that different from what dan originally posted?

PDJ

  • Guest
osnap question
« Reply #9 on: August 13, 2004, 01:19:05 PM »
What's wrong with the shift/right click combo??

Is this how you want your osmode just for this particular command??  If so, you can capture your current osmode when you start the routine, switch to this mode, then go back to your previous one when you finish the routine if you like..  Takes a little more programming but, it's not uncommon to see this in a LOT of lisp routines..

Then there are some that just turn off ALL your osnaps, turn your blipmode on, and create text styles and layers that only the original author had a use for..

God I love this program..

Andrew H

  • Guest
osnap question
« Reply #10 on: August 13, 2004, 01:25:28 PM »
Shift/right click is very limited. Setting up an "F" key is very useful when people who think they know how to write lisp, but really don't mess up your osmode. Toggling osmode with a lisp is easy enough, but hitting one button and having my osmode go to exactly what I want is very handy.

And yes this program is the best.

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
osnap question
« Reply #11 on: August 13, 2004, 01:31:06 PM »
Quote from: Andrew H
how is that different from what dan originally posted?


quite a bit. Let me demonstrate.

Ill be right back.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

CADaver

  • Guest
Re: osnap question
« Reply #12 on: August 13, 2004, 01:35:21 PM »
Quote from: eloquintet
i have this code in my acaddoc.lsp file to reset my osnaps. what i'm wondering is how could i make this work transparently?

Code: [Select]
(DEFUN C:DK ()
(COMMAND "OSMODE" "127"))
(PRINC)


I know you've already gotten a better answer, but for future reference, lose the C: and make it
Code: [Select]
(defun dk ()
(COMMAND "OSMODE" "127"))
(PRINC)


Then add (dk) to the button

You can create entire toolbars to transparently set all kinds of stuff, I use

Code: [Select]
(defun su ()
 (setq sn (car (getvar "snapunit")))
(if
 (setq nsn (getdist (strcat "Enter New Snap Value <" (rtos sn) ">: ")))
 (setq sn nsn)
)
 (setq snp (list sn sn))
 (setvar "snapunit" snp)
(princ)
)

to transparently change my snap unit.  The possibilities are interesting.

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
osnap question
« Reply #13 on: August 13, 2004, 01:35:41 PM »
Here is a demonstration from my command line.

There is a big diff. using "setvar" over "command".
Code: [Select]
***********************
Command: *Cancel*

Command: (defun c:dk () (COMMAND "OSMODE" "127") (princ))
C:DK

Command: osmode

Enter new value for OSMODE <247>: 247

Command: l LINE Specify first point: 'dk

Invalid point.
Specify first point: 'osmode

>>Enter new value for OSMODE <247>:

Resuming LINE command.
Specify first point: *Cancel*

Command: *Cancel*

Command: *Cancel*

Command: (defun c:dk () (setvar "osmode" 127) (princ))
C:DK

Command: l LINE Specify first point: 'dk

Command: 'osmode

Enter new value for OSMODE <127>:

Resuming LINE command.
Specify first point: *Cancel*

Command: *Cancel*

Command: *Cancel*
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

CADaver

  • Guest
osnap question
« Reply #14 on: August 13, 2004, 01:38:45 PM »
oops, I only just noticed he was using (COMMAND instead of (SETVAR.

Andrew H

  • Guest
osnap question
« Reply #15 on: August 13, 2004, 01:40:22 PM »
oic, it changes it to a transparent command.

The "F" key which says: 'osmode 255 works geat too.

Andrew H

  • Guest
osnap question
« Reply #16 on: August 13, 2004, 01:42:33 PM »
me, too CADaver

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
osnap question
« Reply #17 on: August 13, 2004, 01:47:40 PM »
Now the $ 10,000 question is: "Why is there a diff.? What makes using 'setvar' better then 'command'? " (In this situation)
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Andrew H

  • Guest
osnap question
« Reply #18 on: August 13, 2004, 01:49:33 PM »
CAN'T MAKE 'COMMAND' TRANSPARENT. IS MY GUESS.

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
osnap question
« Reply #19 on: August 13, 2004, 01:50:42 PM »
Again, WHY?
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Andrew H

  • Guest
osnap question
« Reply #20 on: August 13, 2004, 01:52:30 PM »
good question, I dunno.

ELOQUINTET

  • Guest
osnap question
« Reply #21 on: August 13, 2004, 01:55:28 PM »
(smartass mode) umm cos it's one less letter to type

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
osnap question
« Reply #22 on: August 13, 2004, 01:56:45 PM »
What does "command" do?
Look it up in the help doc's.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Andrew H

  • Guest
osnap question
« Reply #23 on: August 13, 2004, 02:00:11 PM »
Not that good at lisps, yet. But I think it invokes an existing AutoCAD command and setvar assigns a value to a variable. and adding c in front of the defun name turns it into a command.

can you invoke an existing command with the 'command' function, but have it come in as transparent? as in "command" "'osmode"?

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
osnap question
« Reply #24 on: August 13, 2004, 02:07:16 PM »
Basicly, --Real basic-- Using "setvar" im not try to necessarly 'pass information to AutoCAD to make some changes' but instead we are just 'making changes to AutoCAD' ourselves. (does that make sence?)

No. (Well i should say: I guess ive never really tried, but i seriously doubt it.)
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

CADaver

  • Guest
osnap question
« Reply #25 on: August 13, 2004, 02:43:27 PM »
Quote from: Se7en
Basicly, --Real basic-- Using "setvar" im not try to necessarly 'pass information to AutoCAD to make some changes' but instead we are just 'making changes to AutoCAD' ourselves. (does that make sence?)

No. (Well i should say: I guess ive never really tried, but i seriously doubt it.)
Yeah , that makes sense, at least that's how I always looked at it COMMAND means yer fixin' to tell ACAD to do something SETVAR is just changing settings.

sinc

  • Guest
osnap question
« Reply #26 on: August 13, 2004, 04:41:08 PM »
In most cases, when a task can be performed in two different ways, and one of them is with "command", the other way is preferable, for two reasons:

The first reason is simply a matter of efficiency.  In the above example, using "command" to change osnap ends up doing the same thing as seting "osnap" directly, it just involves a lot more processing.  If your code performs a simple task that is quickly accomplished, this difference is not noticeable; it only makes a real difference if your code loops.

The second is that "command" means "run the command as if you were taking input from the user", in the same way as if you had written a macro.  This means that all the additional "features" that Autocad adds during user input, and which may affect the result, are also applied.  This can sometimes lead to unintended side-effects.  For example, if you use "command" to draw lines without turning off osnaps first, you can get unpredictable results.  It's usually best to perform each task in as explicit a fashion as possible.

Sometimes, however, it's preferable to use the "command" version.  For example, if you WANT all the extra user-input features applied, go ahead and use the "command" version.  And sometimes, the "command" version is much easier to use.  For example, when I was recently trying to write a program to offset entities to the current layer instead of the object's layer, I used 'command ".offset"'', because after messing in vain with directional vaguaries of the LightWeightPolyline's offset method for a while, I decided it was much easier use the existing offset command and change the layer of the resulting entities.

Columbia

  • Guest
osnap question
« Reply #27 on: August 17, 2004, 10:12:47 AM »
And just to throw in something really confusing and muddy up the waters a little bit here's this little tidbit of code...
Code: [Select]

(defun set_osnap () (setvar "osmode" 127) (princ)) ;; setup snap function

(vl-load-com) ;; initialize the VisualLisp Environment

(vlax-add-cmd "reset_snap" 'set_osnap "reset_snap" 1) ;; add the command to ACAD command stack



The end result is a that you can now use C:RESET_SNAP as if it were a native ACAD command.  Which now means that it will work transparently in other LISP functions as well as native ACAD commands.