ObjectSnap
from OpenCAD2D import ObjectSnap
class ObjectSnap(System.Object) ยท ObjectSnap in the .NET reference
Object snaps, ortho, polar and grid snap, as AutoCAD's: given the cursor, the size of the aperture and the point a rubber band is drawn from, the point a click takes. Snaps are worked out from the display items under the aperture, through a space's PickIndex, so an INSERT's lines and arcs are snapped to where it places them.
The snaps that work from more than the cursor: Extension, Parallel and object snap tracking from points acquired by resting the cursor on them, and Apparent Intersection from two objects under the cursor or one clicked first.
Constructors
__init__
def __init__(self, tolerance: Tolerance) -> None
Makes the snaps of AutoCAD's default: endpoint, midpoint, centre, quadrant and intersection, on.
Properties and fields
Acquired
@property
def Acquired(self) -> System.Collections.Generic.IReadOnlyList[CadAcquiredPoint]
Gets the points acquired, the oldest first; seven at most.
AcquiresWithShift
@property
def AcquiresWithShift(self) -> bool
@AcquiresWithShift.setter
def AcquiresWithShift(self, value: bool) -> None
Gets or sets whether a point is acquired for tracking only while Shift is held as the cursor rests on it, as AutoCAD's POLARMODE 8; off until set, when resting on it is enough. The window's canvas honours it.
AdditionalPolarAngles
@property
def AdditionalPolarAngles(self) -> System.Collections.Generic.IReadOnlyList[float]
@AdditionalPolarAngles.setter
def AdditionalPolarAngles(self, value: System.Collections.Generic.IReadOnlyList[float]) -> None
Gets or sets the additional polar angles, in radians from the X axis of the UCS, as AutoCAD's POLARADDANG while POLARMODE 4 is set: each held as it is beside the multiples of ObjectSnap.PolarAngle, but not its own multiples, and counted from the last segment too while ObjectSnap.PolarFromLastSegment is on; none until set. With a polar angle of 90 and 33 added, the cursor is held at 33 degrees from the base point, but not at 66.
AngleOverride
@property
def AngleOverride(self) -> float | None
@AngleOverride.setter
def AngleOverride(self, value: float | None) -> None
Gets or sets the direction an angle override typed at the prompt holds the cursor to, in radians counter-clockwise from the world's X axis, as CadCommandSession.AngleOverride gives it; null, as until set, for none. The cursor is held on the line through the base point at that angle, either side of it, over the grid, ortho and polar, and an object snap still wins, as AutoCAD 2021's help has it. With 30 degrees from the origin, the cursor at (100, 0) is held at (75, 43.3).
GridOrigin
@property
def GridOrigin(self) -> GeoPoint2
@GridOrigin.setter
def GridOrigin(self, value: GeoPoint2) -> None
Gets or sets the point the snap grid runs through, in the coordinates of ObjectSnap.Ucs, as AutoCAD's SNAPBASE; the origin until set.
GridSnap
@property
def GridSnap(self) -> bool
@GridSnap.setter
def GridSnap(self, value: bool) -> None
Gets or sets whether the cursor is put on the snap grid (SNAP, F9), or, while ObjectSnap.PolarSnap is on, on steps along the polar angles.
GridX
@property
def GridX(self) -> float
@GridX.setter
def GridX(self, value: float) -> None
Gets or sets the spacing of the snap grid along X; 10 until set.
GridY
@property
def GridY(self) -> float
@GridY.setter
def GridY(self, value: float) -> None
Gets or sets the spacing of the snap grid along Y; 10 until set.
IsOn
@property
def IsOn(self) -> bool
@IsOn.setter
def IsOn(self, value: bool) -> None
Gets or sets whether object snaps are on (OSNAP, F3).
Isoplane
@property
def Isoplane(self) -> CadIsoplane | None
@Isoplane.setter
def Isoplane(self, value: CadIsoplane | None) -> None
Gets or sets the plane of an isometric snap, as AutoCAD's SNAPSTYL 1 with SNAPISOPAIR; null, as until set, for the rectangular snap of SNAPSTYL 0. The snap points then lie where the 30, 90 and 150 degree lines cross, twice ObjectSnap.GridY apart along each, as AutoCAD keeps half the vertical spacing in the drawing: SNAP Style Isometric 5 keeps a spacing of 8.6603 by 2.5, and the points lie 5 apart. Ortho holds the cursor on the two axes of the plane, whether the snap grid is on or not.
LastSegment
@property
def LastSegment(self) -> GeoVector2 | None
@LastSegment.setter
def LastSegment(self, value: GeoVector2 | None) -> None
Gets or sets the direction of the last segment drawn, the way a line or the end of an arc ran, which the polar angles are counted from while ObjectSnap.PolarFromLastSegment is on; null, as until set, for none.
Magnet
@property
def Magnet(self) -> bool
@Magnet.setter
def Magnet(self, value: bool) -> None
Gets or sets whether the cursor is drawn locked on a snap's point, the rubber band running to it, as AutoCAD's AUTOSNAP 4 (the magnet); on until set. Off, the rubber band follows the cursor, and a click still takes the snap.
Modes
@property
def Modes(self) -> CadSnapModes
@Modes.setter
def Modes(self, value: CadSnapModes) -> None
Gets or sets the object snaps that may be taken.
Ortho
@property
def Ortho(self) -> bool
@Ortho.setter
def Ortho(self, value: bool) -> None
Gets or sets whether the cursor is held level or upright from the base point (ORTHO, F8).
Override
@property
def Override(self) -> CadSnapModes | None
@Override.setter
def Override(self, value: CadSnapModes | None) -> None
Gets or sets the object snaps of the next point alone, as AutoCAD's override typed at a point prompt (END, MID) or chosen from the Shift+right-click menu: taken in place of ObjectSnap.Modes, whether ObjectSnap.IsOn is on or off; CadSnapModes.None takes no object snap for that point (NONe). Null, as it is until set, for no override. The window clears it once the point is taken.
Polar
@property
def Polar(self) -> bool
@Polar.setter
def Polar(self, value: bool) -> None
Gets or sets whether the cursor is held on a polar angle from the base point when it comes near one (POLAR, F10).
PolarAngle
@property
def PolarAngle(self) -> float
@PolarAngle.setter
def PolarAngle(self, value: float) -> None
Gets or sets the polar increment in radians; a quarter turn until set.
PolarDistance
@property
def PolarDistance(self) -> float
@PolarDistance.setter
def PolarDistance(self, value: float) -> None
Gets or sets the step of ObjectSnap.PolarSnap, as AutoCAD's POLARDIST: nought, as until set, or below steps by ObjectSnap.GridX, the snap X spacing. It steps along the lines of object snap tracking from the points acquired too.
PolarFromLastSegment
@property
def PolarFromLastSegment(self) -> bool
@PolarFromLastSegment.setter
def PolarFromLastSegment(self, value: bool) -> None
Gets or sets whether the polar angles are counted from the last segment drawn (ObjectSnap.LastSegment), as AutoCAD's POLARMODE 1 (Relative to last segment): off until set, when they are counted from the X axis of the UCS turned by ObjectSnap.SnapAngle, as they are where no segment has been drawn. With a polar angle of 90 and the last line drawn at 30 degrees, the cursor is held at 30, 120, 210 and 300 degrees from the base point.
PolarSnap
@property
def PolarSnap(self) -> bool
@PolarSnap.setter
def PolarSnap(self, value: bool) -> None
Gets or sets whether SNAP steps along the polar angles in place of the grid, as AutoCAD's SNAPTYPE 1 (PolarSnap): off until set, as SNAPTYPE 0. With SNAP and POLAR on, the cursor held on a polar angle from the base point is put at a whole number of ObjectSnap.PolarDistance from it, so that with a distance of 25 a cursor 37 along the level line from (0, 0) is put at (25, 0); off a polar angle, or with POLAR off, the cursor goes free.
ShowsMarker
@property
def ShowsMarker(self) -> bool
@ShowsMarker.setter
def ShowsMarker(self, value: bool) -> None
Gets or sets whether the marker of a snap is drawn at its point, as AutoCAD's AUTOSNAP 1; on until set.
ShowsSnapTip
@property
def ShowsSnapTip(self) -> bool
@ShowsSnapTip.setter
def ShowsSnapTip(self, value: bool) -> None
Gets or sets whether the name of a snap is shown by the cursor, as AutoCAD's AUTOSNAP 2 (the AutoSnap tooltip); on until set.
ShowsTrackingTip
@property
def ShowsTrackingTip(self) -> bool
@ShowsTrackingTip.setter
def ShowsTrackingTip(self, value: bool) -> None
Gets or sets whether the tip by the cursor, "Ortho" with the distance and the angle from the base point, is shown while the cursor is held by ortho, polar or a tracking line, as AutoCAD's AUTOSNAP 32 (the tooltips of polar tracking, object snap tracking and Ortho mode); on until set.
SnapAngle
@property
def SnapAngle(self) -> float
@SnapAngle.setter
def SnapAngle(self, value: float) -> None
Gets or sets the angle the snap grid is turned by about ObjectSnap.GridOrigin, in radians from the X axis of ObjectSnap.Ucs, as AutoCAD's SNAPANG; nought until set. Ortho holds the cursor along the turned axes and the polar angles are counted from it, as AutoCAD's are. With a snap of 10 turned by 30 degrees, the cursor at (9, 4) is put on (8.6603, 5), the point 10 along the turned X axis.
Tolerance
@property
def Tolerance(self) -> Tolerance
Gets the tolerance of the comparisons.
Tracking
@property
def Tracking(self) -> bool
@Tracking.setter
def Tracking(self, value: bool) -> None
Gets or sets whether object snap tracking is on (OTRACK, F11): from each point acquired, lines run level and upright, or on every polar angle while ObjectSnap.Polar and ObjectSnap.TracksPolarAngles are on, and the cursor is held on one near it or where two cross.
TracksPolarAngles
@property
def TracksPolarAngles(self) -> bool
@TracksPolarAngles.setter
def TracksPolarAngles(self, value: bool) -> None
Gets or sets whether object snap tracking runs its lines from the points acquired on every polar angle while ObjectSnap.Polar is on, as AutoCAD's POLARMODE 2 (Track using all polar angle settings): off until set, when they run level and upright alone, as POLARMODE 0 (Track orthogonally only). With a polar angle of 45 and a point acquired at (100, 0), the cursor at (130, 30.4) is held on the line at 45 degrees only while it is on.
Ucs
@property
def Ucs(self) -> CadUcs
@Ucs.setter
def Ucs(self, value: CadUcs | None) -> None
Gets or sets the user coordinate system the grid, ortho and polar tracking follow, as AutoCAD's do: the grid runs along its axes, ortho holds the cursor along them, and polar angles are measured from its X axis. Object snaps give world points whatever it is. The world until set; null sets the world.
Methods
Acquire
def Acquire(self, index: PickIndex, cursor: GeoPoint2, aperture: float, basePoint: GeoPoint2 | None = ...) -> bool
The cursor has rested, as AutoCAD acquires a point when the cursor pauses on it: a point acquired before and within the aperture is let go; else, with object snap tracking on, the snap point under the cursor is acquired, and with Extension the end of a line or an arc there; else, with Parallel and a base point, the line under the cursor. A point acquired past the seventh lets the oldest go. A line 0,0 to 100,0 rested on at its end (99.6, 0.3) with Extension gives the end (100, 0) running on along +X.
AcquireTrackPoint
def AcquireTrackPoint(self, point: GeoPoint2) -> None
Acquires a point given rather than rested on, as AutoCAD's temporary track point (TT): while OTRACK is on, tracking lines run from it as from any point acquired, so that TT at (2 000, 0) holds the cursor near (2 000.3, 700) at (2 000, 700). It is drawn as a small cross and counts among the seven, the oldest let go first.
ClearAcquired
def ClearAcquired(self) -> None
Lets every acquired point go, and the object clicked first for an apparent intersection: the window calls it once a point is taken or the prompt goes.
Snap
def Snap(
self,
index: PickIndex,
cursor: GeoPoint2,
aperture: float,
basePoint: GeoPoint2 | None = ...,
drawnFrom: GeoPoint2 | None = ...,
) -> CadSnapResult
Gets the point a click at the cursor takes.
TakeFirstObject
def TakeFirstObject(self, result: CadSnapResult) -> bool
Picks the object an CadSnapKind.ExtendedApparentIntersection offers as the first of two, as a click on it does in AutoCAD: the point is not taken, and the object under the cursor after gives where the two would cross, run on. Two lines 0,0 to 10,0 and 20,5 to 20,10, the first picked, give (20, 0) from anywhere on the second.