About Object Snaps (AutoLISP)

The osnap function can find a point by using one of the AutoCAD Object Snap modes.

You pass the function a three element list that represents a 3D point; if you want to specify a 2D point, set the Z axis to a value of 0 (zero). Snap modes are specified using a string value; multiple Snap modes can be specified by using a comma delimiter.

The following example code looks for the midpoint of an object near pt1:

(setq pt2 (osnap pt1 "_midp"))

The following example code looks for the midpoint, the endpoint, or the center of an object nearest pt1:

(setq pt2 (osnap pt1 "_midp,_endp,_center"))
Note: It is recommended to always add an underscore (_) in front of each Snap mode; this will help your program to work as expected when executed on an AutoCAD release other than the English language release.

In both examples, pt2 is set to the snap point if one is found that fulfills the osnap requirements. If more than one snap point fulfills the requirements, the point is selected based on the setting of the AutoCAD SORTENTS system variable. Otherwise, pt2 is set to nil.

Note: The AutoCAD APERTURE system variable determines the allowable proximity of a selected point to an object when you use Object Snap.