Author Topic: Sending point to running command and avoid osnaps?  (Read 2478 times)

0 Members and 1 Guest are viewing this topic.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Sending point to running command and avoid osnaps?
« on: August 31, 2010, 04:10:29 AM »
I'm working on, what I call, additional snaps. For example: VirtMid (virtual midpoint) to snap to the midpoint between two points.

: line
ENTER to use last point/Follow/<Start of line>: (vm)
VirtMid: first point:
VirtMid: second point: (6.94611 4.69301 0.0)
ENTER to use last point/Follow/<Start of line>:
Angle/Length/Undo/<End point>:
Angle/Length/Follow/Undo/<End point>: 


This works just fine unless there is a running osnap and an entity at the calculated point. If for instance osmode=1 and the two points picked for VirtMid are the endpoints of the same line, the result is one of the endpoints of the line.

This behaviour has recently been adopted by Bricscad for compatibility reasons.

As a workaround I have come up with VirtMid2 which uses a different method to send the point to the command.

: line
ENTER to use last point/Follow/<Start of line>: (vm2)
VirtMid: first point:
VirtMid: second point:
ENTER to use last point/Follow/<Start of line>: _none
 
Angle/Length/Undo/<End point>:
Angle/Length/Follow/Undo/<End point>:


The biggest disadvantage of this workaround is that you can no longer stack additional snaps. Of course it also looks ugly.

I've tried switching off osmode in the usual way (see VirtMid3) but that doesn't work.

So my question is:
Is there another way to bypass the running osnaps?

Code: [Select]
(defun VM () (VirtMid))
(defun VirtMid ( / pt1 pt2)
  (if
    (and
      (setq pt1 (getpoint "\nVirtMid: first point: "))
      (setq pt2 (getpoint pt1 "\nVirtMid: second point: "))
    )
    (MidPoint pt1 pt2)
  )
)

(defun VM2 () (VirtMid2))
(defun VirtMid2 ( / pt1 pt2)
  (if
    (and
      (setq pt1 (getpoint "\nVirtMid: first point: "))
      (setq pt2 (getpoint pt1 "\nVirtMid: second point: "))
    )
    (command "_none" (MidPoint pt1 pt2))
  )
  (princ)
)

(defun VM3 () (VirtMid3))
(defun VirtMid3 ( / pt1 pt2 oldOsmode)
  (setq oldOsmode (getvar "osmode"))
  (if
    (and
      (setq pt1 (getpoint "\nVirtMid: first point: "))
      (setq pt2 (getpoint pt1 "\nVirtMid: second point: "))
    )
    (progn
      (setvar "osmode" 0)
      (MidPoint pt1 pt2)
      (setvar "osmode" oldOsmode)
    )
  )
  (princ)
)

(defun MidPoint (pt1 pt2)
  (mapcar '(lambda (a b) (/ (+ a b) 2.0)) pt1 pt2)
)

(princ "\nUsage: (VM) or (VM2); (VM3) doesn't work... ")
(princ)

huiz

  • Swamp Rat
  • Posts: 919
  • Certified Prof C3D
Re: Sending point to running command and avoid osnaps?
« Reply #1 on: August 31, 2010, 04:15:22 AM »
Normally in scripts you can turn off Object Snap and restore after finishing.

Another option is to look closer at the system variable OSNAPCOORD which should be 1, not 2. See AutoCAD Help.
The conclusion is justified that the initialization of the development of critical subsystem optimizes the probability of success to the development of the technical behavior over a given period.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Sending point to running command and avoid osnaps?
« Reply #2 on: August 31, 2010, 04:36:05 AM »
Normally in scripts you can turn off Object Snap and restore after finishing.
Doesn't work see (VM3).

Another option is to look closer at the system variable OSNAPCOORD which should be 1, not 2. See AutoCAD Help.
Setting OSNAPCOORD to 1 makes no difference. Maybe because an autolisp-program is not a script?

Daniel Eiszele

  • Newt
  • Posts: 85
Re: Sending point to running command and avoid osnaps?
« Reply #3 on: August 31, 2010, 07:04:25 AM »
VM3 doesn't work because you've suppressed the answer with the (princ) command.  To echo it to the command line just alter as follows.  I'm afraid it doesn't fix the effect of the osnaps in bricscad though.


Code: [Select]
(defun VM3 () (VirtMid3))
(defun VirtMid3 ( / pt1 pt2 oldOsmode)
  (setq oldOsmode (getvar "osmode"))
  (if
    (and
      (setq pt1 (getpoint "\nVirtMid: first point: "))
      (setq pt2 (getpoint pt1 "\nVirtMid: second point: "))
    )
    (progn
      (setvar "osmode" 0)
      (setq mp (MidPoint pt1 pt2))
      (setvar "osmode" oldOsmode)
    )
  )
  (princ)
mp
)

Daniel Eiszele

  • Newt
  • Posts: 85
Re: Sending point to running command and avoid osnaps?
« Reply #4 on: August 31, 2010, 07:11:35 AM »
If you want it to be stackable include the c: directive and then when you call it from from within a command include an apostrophe in front of it to make it transparent ie 'vm3.  If you do this the osnaps will be ignored as intended.  Alternately if you use your function then '(vm3) will do the same thing  - just more typing!

Code: [Select]
(defun c:VM3 ( / pt1 pt2 oldOsmode)
  (setq oldOsmode (getvar "osmode"))
  (if
    (and
      (setq pt1 (getpoint "\nVirtMid: first point: "))
      (setq pt2 (getpoint pt1 "\nVirtMid: second point: "))
    )
    (progn
      (setvar "osmode" 0)
      (setq mp (MidPoint pt1 pt2))
      (setvar "osmode" oldOsmode)
    )
  )
  (princ)
mp
)

(defun MidPoint (pt1 pt2)
  (mapcar '(lambda (a b) (/ (+ a b) 2.0)) pt1 pt2)
)

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Sending point to running command and avoid osnaps?
« Reply #5 on: August 31, 2010, 08:19:44 AM »
VM3 doesn't work because you've suppressed the answer with the (princ) command.
Right. (princ) was put in to suppress the return value of (setvar "osmode" oldOsmode). Basically switching osmodes is not an option.

If you want it to be stackable include the c: directive ...
I think the reason VM2 is not stackable is the call to (command ...) used to send the point. VM is stackable and you can just type (VM), there is no need for an apostrophe. Your function c:VM3 is functionally identical to my VM because all the code related to osmode has become redundant.


Daniel Eiszele

  • Newt
  • Posts: 85
Re: Sending point to running command and avoid osnaps?
« Reply #6 on: August 31, 2010, 07:00:08 PM »

If you want it to be stackable include the c: directive ...
I think the reason VM2 is not stackable is the call to (command ...) used to send the point. VM is stackable and you can just type (VM), there is no need for an apostrophe.
Yes you are correct; through my testing I was led to the false assumption that the apostrophe was stopping CAD from recomputing the point with osnaps, but it seems the combination of snaps I had on was hiding the fact that it was in fact still using them. :(  Back to the drawing board.