AutoCAD

Temporarily change the running object snap mode

Ease of Use

Intermediate

Version tested with

2004, 2005 

Submitted by:

malik641

Description:

Stores the Object Snaps you have running at Run-Time and resets the Object Snap mode to specific settings. Once the code is run again, the original settings are restored. 

Discussion:

At my job, I design pools. And when I dimension the pool I like to use the Center object snap and everything else off. I usually have a lot more snaps running than just Center, so it becomes tedious to keep checking on/off the same check boxes everytime I dimension a pool. So I made this code as sort of a "switch" for when I dimension pools, specifically. But you can set it to whatever you prefer, just follow the code. 

Code:

instructions for use

			

Option Explicit Public intSnapSetting As Integer Public SettingChanged As Boolean Sub Change_Snaps() 'Sets running Object Snap modes to whatever you choose, 'then back to the original setting. '-----------------From the HELP file-------------------------------------- 'Bitcodes for Object Snap Modes: ' 0 NONe ' 1 ENDpoint ' 2 MIDpoint ' 4 CENter ' 8 NODe ' 16 QUAdrant ' 32 INTersection ' 64 INSertion ' 128 PERpendicular ' 256 TANgent ' 512 NEArest ' 1024 QUIck ' 2048 APParent Intersection ' 4096 EXTension ' 8192 PARallel ' 'To specify more than one object snap, enter the sum of their values. 'To find out the current bitcode combination you have, simply enter OSMODE 'and the number will be inside < > '------------------------------------------------------------------------- If SettingChanged = False Then intSnapSetting = ThisDrawing.GetVariable("OSMODE") SettingChanged = True End If If ThisDrawing.GetVariable("OSMODE") = 4 Then 'Returns object snap mode to previous state and resets the boolean value ThisDrawing.SetVariable "OSMODE", intSnapSetting SettingChanged = False AutoCAD.Application.ActiveDocument.Utility.Prompt vbCrLf & "Snaps Restored" Else ThisDrawing.SetVariable "OSMODE", 4 'Sets the Object Snap mode to CENter AutoCAD.Application.ActiveDocument.Utility.Prompt vbCrLf & "Snap set to Center" End If End Sub

How to use:

  1. Open the VBE (Alt+F11)
  2. Insert a new module (or use an existing if you prefer) Insert --> Module
  3. Copy and Paste code into the new module (be sure no duplicates of "Option Explicit" exist)
  4. Change the Snap Settings in the code to your needs
  5. Save the project
  6. Close the VBE
  7. OR
  8. If you are going to download the attachment, then do the following:
  9. Download file
  10. Extract the file to any destination (Desktop, My Documents, etc)
  11. In AutoCAD, type VBALOAD
  12. Select the file you extracted, press enter
 

Test the code:

  1. In AutoCAD, choose Tools --> Macro --> Macros... (or Alt+F8) and choose "Change_Snaps" to change the Object Snap setting to the desired settings
  2. Repeat step 1 to restore the previous snap settings
  3. If you like, create a user defined button and in the Button Properties under "Macro Associated with this Button" paste the following (without quotes): "-vbarun Change_Snaps"
 

Sample File:

ChangeSnaps.zip 4.28KB 

Approved by mdmackillop


This entry has been viewed 53 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express