Author Topic: The osnap function  (Read 2240 times)

0 Members and 1 Guest are viewing this topic.

Grrr1337

  • Swamp Rat
  • Posts: 812
The osnap function
« on: December 07, 2016, 05:58:35 PM »
Hi guys,
I wondered whats the proper use of the osnap function ?
Used this as a test:
Code: [Select]
_$ (setq pick (entsel))
(<Entity name: 7ff606207370> (397.146 165.971 0.0))
_$ (entmake (list (cons 0 "POINT") (cons 62 2) (cons 10 (cadr pick))))
((0 . "POINT") (62 . 2) (10 397.146 165.971 0.0))
_$ (entmake (list (cons 0 "POINT") (cons 62 1) (cons 10 (osnap (cadr pick) "_NEA"))))
((0 . "POINT") (62 . 1) (10 397.146 165.971 0.0))
I expected the snapping point to be directly on the line, and the pickpoint from the entsel's pickbox to be aside from the curve.
But as you can see the coordinates are the same, and in the picture the points are overlapping (after zooming in above the picked location).

Any information how/when/why its used ? Any practical examples?  :rolleyes2:
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

Rod

  • Newt
  • Posts: 185
Re: The osnap function
« Reply #1 on: December 07, 2016, 07:27:08 PM »
I think the osnap works almost the same as if you picked the point yourself. So it will depend on
  • how zoomed in you are
  • What the APERTURE sysvar is set to
  • What objects are visible
  • For NEAREST what is the nearest object

In your example you will get different results if you are zoomed in (object is outside the aperture box) or zoomed out (object is within the size of the aperture box)

Also the OSNAPCOORD sysvar can come into play if you are entering a point into a command eg (command "line" pt)

Hope that helps, Rod.
"All models are wrong, some models are useful" - George Box

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: The osnap function
« Reply #2 on: December 08, 2016, 05:23:14 AM »
Comparing the PICKBOX with the APERTURE may be useful.
Using this is probably more reliable:
Code: [Select]
(setq pt (vlax-curve-getclosestpointto obj (trans pt 1 0)))

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: The osnap function
« Reply #3 on: December 08, 2016, 05:45:09 AM »
Thanks for the input, Rod
After posting this thread I immediately assumed that the NEAREST might snap to the point I just emaked with (cadr pick), and not the actual curve.
Did some re-test, and unfortunatelly the point didn't snap on the spline, although it was the nearest object. (alternatively I know this is doable with vlax-curve-getClosestPointTo)
Even with getpoint doesn't seem to make a difference:
Code: [Select]
(entmake (list (cons 0 "POINT") (cons 62 1) (cons 10 (osnap (getpoint) "_NEA"))))
(entmake (list (cons 0 "POINT") (cons 62 1) (cons 10 (getpoint))))
When I zoom-in enough I can see that the point is not located on the curve.
If this matters: My PICKBOX value is 3 and APPERTURE is 10.

Thanks Roy, I was already aware of this (I'm just thinking about the osnap funciton).
Still no idea when its used, and when can become handy.
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: The osnap function
« Reply #4 on: December 08, 2016, 06:17:11 AM »
@Grrr1337:
Testing this I see that the _nea snap will also snap to point entities. So in your test the 2n point will snap to the 1st point. I think this is the cause for your confusion.

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: The osnap function
« Reply #5 on: December 08, 2016, 06:41:56 AM »
@Roy,
Thats why I did the re-test, as mentioned in my Reply #3, without entmakeiing the 1st point.
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: The osnap function
« Reply #6 on: December 08, 2016, 09:45:39 AM »
My apologies, I didn't read properly.
Could this be a display issue?
Maybe if you compare the result of vlax-curve-getclosestpointto with that of osnap you will find that they are in fact the same.

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: The osnap function
« Reply #7 on: December 08, 2016, 02:43:46 PM »
My apologies, I didn't read properly.
Could this be a display issue?
Maybe if you compare the result of vlax-curve-getclosestpointto with that of osnap you will find that they are in fact the same.
Thanks Roy, you were correct.. the result of vlax-curve-getclosestpointto and osnap "NEA" is the same:
Code: [Select]
_$ (setq pick (entsel))
(<Entity name: 7ff614707330> (194.919 160.49 0.0))
_$ (defun MkPt ( p col ) (entmake (list (cons 0 "POINT") (cons 62 col) (cons 10 p))) )
MKPT
_$ (MkPt (vlax-curve-getclosestpointto (car pick) (trans (cadr pick) 1 0)) 3)
((0 . "POINT") (62 . 3) (10 193.414 162.184 0.0))
_$ (MkPt (osnap (cadr pick) "_NEA") 2)
((0 . "POINT") (62 . 2) (10 193.414 162.184 0.0))
_$ (MkPt (cadr pick) 1)
((0 . "POINT") (62 . 1) (10 194.919 160.49 0.0))
_$
As you can see in the image, they are lying ontop of each other:

However, when I zoom in:

Perhaps this issue occurs when a "real curve" is selected (like circle/arc/bulge/spline).
I performed the same test on a line/straight segment, and the vlax-curve-getclosestpointto and osnap "NEA" are located correctly on the line.
Seems to be a display issue, like you said.  :-o

Still I've rarely seen the osnap function being used by one, I'll give it my shot with grread.
 I know about LM's grsnap and seems a tedious combo, but I'll try something simple.  :|
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

ronjonp

  • Needs a day job
  • Posts: 7527
Re: The osnap function
« Reply #8 on: December 08, 2016, 03:17:49 PM »
Did not read the whole thread so if I'm off base disregard :) .

If you're picking an arc segment & you zoom in close, regen then it should look ok.
Look into VIEWRES & WHIPARC variables to control how accurate arcs are displayed.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: The osnap function
« Reply #9 on: December 09, 2016, 04:03:14 PM »
Did not read the whole thread so if I'm off base disregard :) .

If you're picking an arc segment & you zoom in close, regen then it should look ok.
Look into VIEWRES & WHIPARC variables to control how accurate arcs are displayed.
I tried this - no success, although I appreciate your suggestion (also was aware about the zoom-in + regen thingy).
But nevermind, I don't worry anymore when I know its not an osnap issue.
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg