All about Snapping (Templates and Reusability) (AutoCAD VBA)

The snap mode makes the crosshairs cursor jump from snap point to snap point as you move the cursor around the screen. This is an excellent tool for ensuring that any lines that need to join up will actually meet, because snap mode snaps any point clicked to the nearest snap point.

tmp89fa-126_thumb

To turn the snap mode on from the AutoCAD window, simply click the SNAP button located on the status bar next to the GRID button.

Even when snap mode is turned on, the snap points are invisible. In order to see where the snap points are located, you’ll need to display a grid with the same space settings.

Enabling snap mode from a macro is quite straightforward—you set the SnapOn property to True or False. The following SnapToGrid macro shows how easy it is to activate the snap-to-grid points in the active viewport. This is another macro for your ShowGrid project.

tmp89fa-127_thumb


Setting the Snap Spacing

The setting for snap spacing determines the level of accuracy for positioning the points selected from the Model Space. To set the snap spacing from the AutoCAD window, follow these steps:

1. Choose Tools – Drafting Settings to open the Drafting Settings dialog box (shown earlier in Figure 8.6).

2. Enter 12 into the Snap X Spacing and Snap Y Spacing boxes and click OK. You return to the AutoCAD window. Now, as you move the crosshairs cursor around, it appears to jump from grid point to grid point.

The snap point spacing need not be the same as the grid point spacing. Figures 8.7 through 8.10 provide examples of some of the various configurations possible.

The smallest square that can be drawn when the grid spacing and the snap spacing are the same

Figure 8.7 The smallest square that can be drawn when the grid spacing and the snap spacing are the same

The smallest square that can be drawn when the snap spacing is twice the grid spacing in both directions

Figure 8.8 The smallest square that can be drawn when the snap spacing is twice the grid spacing in both directions

Setting the Snap Spacing from a Macro

The SetSnapSpacing method allows you to specify the horizontal and vertical snap spacing for the active viewport by passing their values as arguments. The AdjustSnapSpacing macro shows you how; add it to your ShowGrid project and try it out.

tmp89fa-130_thumb

 

The smallest rectangle that can be drawn when the snap spacing is set to 1 in the horizontal direction and 3 in the vertical direction

Figure 8.9 The smallest rectangle that can be drawn when the snap spacing is set to 1 in the horizontal direction and 3 in the vertical direction

The smallest rectangle that can be drawn when the snap and grid spacing are set to 1 in the horizontal direction and 3 in the vertical direction

Figure 8.10 The smallest rectangle that can be drawn when the snap and grid spacing are set to 1 in the horizontal direction and 3 in the vertical direction

Next post:

Previous post: