Setting OSnap to Node after EntSel

Setting OSnap to Node after EntSel

greglcroth
Contributor Contributor
516 Views
4 Replies
Message 1 of 5

Setting OSnap to Node after EntSel

greglcroth
Contributor
Contributor

This is what I want to do ... point blocks are at zero elevation in the drawing (but have elevations stored in the attribute list), so I want to select the point and read the elevation from the point attribute and get the elevation and coordinate as separate variables.    It works, except for one thing ... I want the "node" snap turned on to reduce the chances I pick the wrong entity.  Apparently, preset osnaps are ignored with entsel.  Any way to turn it bank on mid command?

 

(command "-osnap" "node")
(setq PT1 (car (entsel "\nPick Point: "))) ; Pick Point
(setq attlist (entget PT1))
(setq elpnt1 (cadddr (assoc 11 attlist))) ; Gets Elevation only
(setq snappt (cdr (assoc 10 attlist)))     ; Gets Full XYZ Coord

 

I'm at my wit's end here, and tried a lot of different ideas I've seen here and elsewhere, but can't seem to get it to work.  The code above is my original sort of working plan.

 

Thanks.

0 Likes
517 Views
4 Replies
Replies (4)
Message 2 of 5

Kent1Cooper
Consultant
Consultant

@greglcroth wrote:

. ... I want the "node" snap turned on to reduce the chances I pick the wrong entity.  ....


I don't think having it on will do what you're asking.  You could have it on and use (getpoint) instead of (entsel), and use the result of that to select, but while it would then pick at exactly that location, there could still be something else there that it might "see" instead of what you're after.  Consider using (ssget) in which you can filter for object type to ensure it doesn't see some other kind of thing.

Kent Cooper, AIA
0 Likes
Message 3 of 5

greglcroth
Contributor
Contributor

You are correct.  Even when I tested it by manually setting the osnap to node for the selection, it would still pick up lines around or near the node.  I took your advice and went with SSget and filtered everything that wasn't point blocks.  Works pretty well.  Thanks.

0 Likes
Message 4 of 5

jayhar
Advisor
Advisor

You can temporarily turn on the "node" osnap during your Lisp routine using the "osnap" function with the "node" argument, then turn it off again after the routine completes. Here is an example of how to modify your code to include the "osnap" function: ``` (setq oldosmode (getvar 'osmode)) ; Save current osmode (setvar 'osmode 512) ; Turn on "node" osnap (command "-osnap" "node") (setq PT1 (car (entsel "\nPick Point: "))) ; Pick Point (setq attlist (entget PT1)) (setq elpnt1 (cadddr (assoc 11 attlist))) ; Gets Elevation only (setq snappt (cdr (assoc 10 attlist))) ; Gets Full XYZ Coord (setvar 'osmode oldosmode) ; Restore previous osmode ``` In this modified code, the "osmode" variable is saved before turning on the "node" osnap, and then restored to its previous value after the "entsel" command completes. Note that some AutoCAD versions may have different values for "node" osnap, so you may need to check the AutoCAD documentation or use the "osnapmode" function to determine the correct value for your version.

Thanks and Regards

Jayhar M J 

 

 

Please Subscribe YouTube Channel
https://www.youtube.com/channel/UCclj8v9vHQiFa8_DriuAk3w

Please Mark the Post or Posts as Solution(s) to help others find the answer quickly.
0 Likes
Message 5 of 5

john.uhden
Mentor
Mentor

@greglcroth ,

I think your property of node depends on the type of object you are picking.  If it's only a block insertion (reference) then (assoc 10) should be enough.  And if you are looking for an elevation (Z) only then (last (assoc 10)).

If it's a Civl3D CogoPoint object, then (vlax-get object 'Elevation).

BTW, I love all the IDs we see around here.  You could be...
Greg Lcroth, OR

Gregl Croth, OR

Greg L. Croth.

I'm guessing the last.

Anyway, I haven't seen that ID before, so welcome to a new group of friends, where almost no question is stupid (as long as Tony T isn't responding).

John F. Uhden

0 Likes