1

When selecting a point is there a way to filter OSNAP to only snap onto a specific entity type and not an entity of another type. eg

Snap only to lines.

setq startpt (*SNAP FILTER CODE* "LINE" (getpoint "\nChoose Start Line : "))

Snap only to arcs.

setq startpt (*SNAP FILTER CODE* "ARC" (getpoint "\nChoose Start Arc: "))

Snap only to polyline.

setq startpt (*SNAP FILTER CODE* "POLYLINE" (getpoint "\nChoose Start Polyline: "))

I hope the fake lisp above helps in understanding what I'm trying to ask.

Thanks in advance.

Bigbob556677
  • 1,805
  • 1
  • 13
  • 38

2 Answers2

3

The AutoLISP osnap function can be used to return a point snapped to geometry using a supplied Object Snap modifier, however, this function will not filter the candidate geometry.

Therefore, you could alternatively supply the point returned by getpoint as the point argument for a filtered ssget selection, or test the entity returned by the nentselp function.

Here is a possible solution using ssget:

(defun c:test1 ( / pnt )
    (while
        (and
            (setq pnt (getpoint "\nSelect start point on arc: "))
            (not (ssget pnt '((0 . "ARC"))))
        )
        (princ "\nThe point does not lie on an arc.")
    )
    (if pnt
        (princ (strcat "\nThe user picked (" (apply 'strcat (mapcar 'rtos pnt)) ")."))
        (princ "\nThe user did not supply a point.")
    )
    (princ)
)

Here is a possible solution using nentselp:

(defun c:test2 ( / ent pnt )
    (while
        (and (setq pnt (getpoint "\nSelect start point on arc: "))
            (not
                (and
                    (setq ent (car (nentselp pnt)))
                    (= "ARC" (cdr (assoc 0 (entget ent))))
                )
            )
        )
        (princ "\nThe point does not lie on an arc.")
    )
    (if pnt
        (princ (strcat "\nThe user picked (" (apply 'strcat (mapcar 'rtos pnt)) ")."))
        (princ "\nThe user did not supply a point.")
    )
    (princ)
)
Lee Mac
  • 15,615
  • 6
  • 32
  • 80
0

It is possible to handle this issue, but it's very complicated. What I can tell is that You may use function (grread) to get user input (mouse move or keyboard pressed). Then You have to analyse returned value, considering osnaps. here You may filter for example like this:

(cond 
        ( ( = (vlax-get-property curve 'ObjectName ) "AcDbMLeader" ) ( progn
            ...
        ) )
        (  ( = (vlax-get-property curve 'ObjectName ) "AcDbPolyline"  ) ( progn
            ...
        ) )
        ( YOUR NEXT CASES ( progn
            ...
        ) )
        ( t  (progn
            (princ "\n*Error:NotImplementedYetForThisEntity\n" ) )
        ) )
    )

You have to draw Your own osnap markers (shapes draw for example by (grvecs) size based on system variables "VIEWSIZE" "SCREENSIZE". You need to handle polar tracking, ortho mode, keys pressed on the keyboard. I tried to do it some time ago, didn't handle every case, and my code was hundreds of lines of code. Sorry, but I can not share all the code.

So probably You will spend weeks if You are the beginner in AutoLISP maybe even months on this way of solving the problem. So consider if You can spend so many time on this issue. Maybe problem You met may be handled in another way than filtering osnaps.

CAD Developer
  • 1,532
  • 2
  • 21
  • 27