Jump to content

Snapping to objects when zooming in Viewport


Recommended Posts

To snap to objects when zooming in a viewport, I set OSNAPCOORD = 0.

 

The issues is that this over-rides other setting/s. So far, it changes the following setting.

Tools/Options/User Preferences/Prioroty for Coordinate Data Entry ... "Keyboard Entry" is changed to "Running Object Snap".

I want to keep Keyboard Entry, but it changes the snap setting.

 

Is there a way to keep both settings?

Link to comment
Share on other sites

Actually, it was on 2 to begin with as a default.

But I can't get "Zoom Window" in paper space to snap. The 0 is for snapping ... I know it may not be the correct method but it works for me.

Edited by sketch11
Link to comment
Share on other sites

2 hours ago, sketch11 said:

Actually, it was on 2 to begin with as a default.

But I can't get "Zoom Window" in paper space to snap. The 0 is for snapping ... I know it may not be the correct method but it works for me.

Setting OSNAPCOORD to 0 would allow osnap settings to override emtered coordinates when they're close enough to snap to something.

 

Zoom Window ignores osnap settings by default but you can alway pick or enter an osnap if you want to use them.

Link to comment
Share on other sites

Sorry I don't quite follow.

Is it possible to snap for Zoom Window if OSNAPCOORD = 1 or OSNAPCOORD = 2?

Link to comment
Share on other sites

7 hours ago, sketch11 said:

Sorry I don't quite follow.

Is it possible to snap for Zoom Window if OSNAPCOORD = 1 or OSNAPCOORD = 2?

I never knew that worked for Zoom before!  

Quick lisp that allows you to Zoom Window using your Osnap settings by setting and resetting the OSNAPCOORD value to preserve "Keyboard Entry".

; https://www.cadtutor.net/forum/topic/72916-snapping-to-objects-when-zooming-in-viewport/?tab=comments#comment-580609
; Zoom Window using Osnap settings by Tom Beauford
(defun c:ZSnap ( / *error* osnapcoord)
 (defun *Error* (msg) ; embedded defun
   (setvar 'osnapcoord osnapcoord)
   (if (/= s "Function cancelled")
     (princ (strcat "\nError: " msg))
   )
   (princ)
 )
 (setvar "cmdecho" 0)
 (setq osnapcoord (getvar 'osnapcoord))
 (setvar 'osnapcoord 0)
 (command-s "zoom" PAUSE)
 (while (= 1 (logand 1 (getvar "cmdactive")))
   PAUSE
 )  ;null responce exits zoom
 (setvar 'osnapcoord osnapcoord)     ;reset osnapcoord
 (princ)
)

While command-s is needed for newer versions you will need to change 

(command-s "zoom" PAUSE)

to 

(command "zoom" PAUSE)

for older versions like 2013.

 

Save it as "ZSnap.lsp" in a support folder.

Load and run by entering 

(load "ZSnap.lsp")

then ZSnap at the command line.

 

You could alse add 

^P(or C:ZSnap (load "Leader.lsp"));ZSnap

as a command macro for easy access.

Edited by tombu
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

The "O" in zoom options is for OBJECT.  Use ZOOM then O then select the object to zoom to.  The viewport will then zoom and window itself centered on the object selected.

 

There is no need to change any setting or variable.  You will then have to click the object again to get the grips to show if you want to snap somewhere on the object, but it is still easier than resetting a critical variable each time.

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

18 hours ago, sketch11 said:

Would there be a simple macro to change this setting?

Create this macro:

Command name  Osnapcoord

Description           Toggle OSNAPCOORD overrides between "Keyboard entry except in scripts" & "Osnap settings".

Macro                    ^P'setvar;osnapcoord;$M=$(if,$(and,2,$(getvar,osnapcoord)),0,2) ^P 

Element ID            Osnapcoord

 

Add the macro to your Object Snap Cursor Menu then add:

Display Name       $(if,$(and,2,$(getvar,osnapcoord)),"Zoom Osnap","Keyboard entry except scripts")

which goes just above:

Command name  Osnapcoord

 

I'd recommend resetting OSNAPCOORD to 2 in acaddoc.lsp to avoid issues should you forget to toggle it back:

(if (/= (getvar 'osnapcoord) 2)(progn(setvar 'osnapcoord 2)(princ "\nKeyboard entry overrides object snap settings. OSNAPCOORD")))

 

  • Thanks 1
Link to comment
Share on other sites

Thanks tombu, I did try the macro, adding it to a command button:

^P'setvar;osnapcoord;$M=$(if,$(and,2,$(getvar,osnapcoord)),0,2) ^P

And this worked quite well.

I will look into the other parts at a later stage.

Cheers.

Link to comment
Share on other sites

tombu, your LISP for "ZSnap" is actually what I was looking for, as this does not override OSNAPCOORD.

It worked perfectly in AutoCAD 2021.

For older versions, I tried replacing (command-s "zoom" PAUSE) to (command "zoom" PAUSE) ... but I couldn't get it to work. There was no icon or prompts like in 2021.

This worked with the older version: Click one corner of object, press Escape, click the other corner.

Would it be possible to make it work like 2021?

Link to comment
Share on other sites

1 hour ago, sketch11 said:

tombu, your LISP for "ZSnap" is actually what I was looking for, as this does not override OSNAPCOORD.

It worked perfectly in AutoCAD 2021.

For older versions, I tried replacing (command-s "zoom" PAUSE) to (command "zoom" PAUSE) ... but I couldn't get it to work. There was no icon or prompts like in 2021.

This worked with the older version: Click one corner of object, press Escape, click the other corner.

Would it be possible to make it work like 2021?

You may need help from someone with an older version as I don't have access to one for testing.

Maybe (command "._zoom" "_Window" PAUSE)?

 

CAB's routine at: https://www.cadtutor.net/forum/topic/3460-zoom-window/?tab=comments#comment-28218 may work better:

 

  • Thanks 1
Link to comment
Share on other sites

Great thank you, this seems to offer prompts.

 

(defun c:ZSnapOlderVersions( / *error* osnapcoord)
    (defun *Error* (msg)
        (setvar 'osnapcoord osnapcoord)
        (if (/= s "Function cancelled")
            (princ (strcat "\nError: " msg))
        )
        (princ)
        )
        (setvar "cmdecho" 0)
        (setq osnapcoord (getvar 'osnapcoord))
        (setvar 'osnapcoord 0)
        (if
            (and
            (setq pt1 (getpoint "\nSelect First Window Point: "))
            (setq pt1 (osnap pt1 "_end"))
            (setq pt2 (getpoint "\nSelect Second Window Point: "))
            (setq pt2 (osnap pt2 "_end"))
            )
            (command "._zoom" "_w" "_non" pt1 "_non" pt2) ; end zoom
            )
        (princ)
        (while (= 1 (logand 1 (getvar "cmdactive")))
            PAUSE
        )
        (setvar 'osnapcoord osnapcoord)
    (princ)
)

 

Link to comment
Share on other sites

On 5/7/2021 at 8:12 PM, sketch11 said:

Great thank you, this seems to offer prompts.

If you change the both getpoint functions to getcorner functions it should work the same but display the rectangle for picking the second corner just like Zoom Window does.

Edited by tombu
Both getpoints needed to be changed
Link to comment
Share on other sites

OK, I was trying to make the rectangle show for a while but had no luck.

I tried the change you suggested but still got an error.

 

            (setq pt1 (getpoint "\nSelect First Window Point: "))
            (setq pt1 (osnap pt1 "_end"))
            (setq pt2 (getcorner "\nSelect Second Window Point: "))
            (setq pt2 (osnap pt2 "_end"))

 

 

The error in AutoCAD is:

Select First Window Point:
Error: base point is required

Link to comment
Share on other sites

On 5/8/2021 at 1:45 AM, sketch11 said:

OK, I was trying to make the rectangle show for a while but had no luck.

I tried the change you suggested but still got an error.

 


            (setq pt1 (getpoint "\nSelect First Window Point: "))
            (setq pt1 (osnap pt1 "_end"))
            (setq pt2 (getcorner "\nSelect Second Window Point: "))
            (setq pt2 (osnap pt2 "_end"))

 

 

The error in AutoCAD is:

Select First Window Point:
Error: base point is required

Sorry, you needed to change both getpoints to getcorner.

Help for getcorner (AutoLISP) https://help.autodesk.com/view/ACD/2021/ENU/?guid=GUID-21BE8290-7F11-400B-AC39-62A110F07545

Examples

(getcorner '(7.64935 6.02964 0.0))

(17.2066 1.47628 0.0)

(getcorner '(7.64935 6.02964 0.0) "\nPick a corner") Pick a corner

(15.9584 2.40119 0.0)

Link to comment
Share on other sites

OK thanks, I wasn't quite able to get it to work but will try again.

 

This is what I had.

(setq pt1 (getcorner "\nSelect First Window Point: "))
(setq pt1 (osnap pt1 "_end"))
(setq pt2 (getcorner "\nSelect Second Window Point: "))
(setq pt2 (osnap pt2 "_end"))

 

EDIT: Actually I have to test this on older versions.

Edited by sketch11
Link to comment
Share on other sites

I still get an error with the older version with code above.

Error message: Error: base point is required

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...