Zoom-Jump to next vertex

Zoom-Jump to next vertex

ebsoares
Collaborator Collaborator
1,968 Views
13 Replies
Message 1 of 14

Zoom-Jump to next vertex

ebsoares
Collaborator
Collaborator

Hi, all.

 

Does anyone know of a routine where, while having a polyline/3dpoly/spline selected and having just edited one of its vertices, one would call such routine and it would jump/zoom to the next vertex, keeping the same view scale and the object still selected?

 

It would work great when having to re-edit an element with many vertices. We have to always zoom around and pan while doing this type of work...

 

Thanks in advance

 

Edgar

0 Likes
Accepted solutions (2)
1,969 Views
13 Replies
Replies (13)
Message 2 of 14

Kent1Cooper
Consultant
Consultant

How are you editing vertices?  Within PEDIT's Edit-vertex option?  Just grip-editing?  Stretch, perhaps?

Kent Cooper, AIA
0 Likes
Message 3 of 14

ebsoares
Collaborator
Collaborator

Hi, Kent.

 

No PEdit, just grip-editing. I select a pline (usually 3dpline, actually, but could be a spline as well) and, from a plan view (looking straight from above), move the grips to a more desirable location...

0 Likes
Message 4 of 14

ebsoares
Collaborator
Collaborator

Hi again.


I’ve been talking to one of our coworkers and we came with a sort of pseudocode that might help understand what the routine could go through. It’s already a little different from my original post because we think AutoCAD does not keep track of element edit history down to what vertex was edited last, aside from the undo/redo list.

 

Before calling the command, the element would already be highlighted.

 

Here’s the process:

. Call lisp command;
    . Get selected element;
    . Create list of vertex coordinates for that element (with their vertex numbers as well);
    . Prompt: “Click near current vertex”;
    . Get coordinate of click/pick pt;
    . Calculate difference (distance) from click pt’s coordinates to each vertex of selected element to find out closest vertex on element – that is the current vertex;
    . Get current vertex number;
    . Copy current zoom/view settings;
    . Zoom (or pan) to the next vertex (current + 1) using previous zoom/view settings;
    . Re-select element (if it’s not highlighted anymore);
. End lisp routine;

In bold and underlined are the two only interactions with the user - calling the command and clicking on the screen.


Attached is a small screenshot that might help visualize what’s going on.

 

Thanks one more time for any input.

 

Edgar

0 Likes
Message 5 of 14

Kent1Cooper
Consultant
Consultant

I think it could be fairly simple, but unfortunately what I was hoping would be the easiest way doesn't work as I had hoped.  When I grip-edit a Polyline, the location represented by "@" or (getvar 'lastpoint) is the place where the vertex was before, not the place where you move it to -- if it were the latter, it would be really easy.  But it raises the question:  How drastically are you re-positioning vertices?  If they're not being moved too far in relation to the geometry, a routine could probably find the closest point on the object to the "@" place [in lieu of the User needing to pick near the vertex], find which vertex is closest to that [assuming that's always still the one you just grip-edited], and Zoom-Center on the next vertex.

Kent Cooper, AIA
0 Likes
Message 6 of 14

marko_ribar
Advisor
Advisor

Here is my version... BTW. It has noting to do with gripediting but rather I used STRETCH command... Try it and see if you're satisfied...

 

(defun c:zvv ( / *error* ucsf es e pl p pp n )

  (vl-load-com)

  (defun *error* ( msg )
    (if ucsf
      (command "_.UCS" "_P")
    )
    (if msg
      (prompt msg)
    )
    (princ)
  )

  (if (eq (getvar 'worlducs) 0)
    (progn
      (command "_.UCS" "_W")
      (setq ucsf t)
    )
  )
  (setq es (entsel "\nPick 2d curve with vertices to edit-stretch them..."))
  (setq e (car es))
  (command "_.ZOOM" "_C" "_non" (cadr es))
  (while (< 0 (getvar 'cmdactive)) (command ""))
  (prompt "\nZoom&edit vertex... ESC to finish...")
  (while t
    (cond
      ( (eq (cdr (assoc 0 (entget e))) "LWPOLYLINE")
        (setq pl (mapcar '(lambda ( p ) (trans (list (car p) (cadr p) (cdr (assoc 38 (entget e)))) e 0)) (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (eq (car x) 10)) (entget e)))))
      )
      ( (eq (cdr (assoc 0 (entget e))) "POLYLINE")
        (setq v e)
        (while (setq v (entnext v))
          (if (eq (cdr (assoc 0 (entget v))) "VERTEX")
            (setq pl (cons (cdr (assoc 10 (entget v))) pl))
          )
        )
        (setq pl (reverse pl))
      )
      ( (eq (cdr (assoc 0 (entget e))) "SPLINE")
        (setq pl (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (eq (car x) 10)) (entget e))))
      )
      ( (or (eq (cdr (assoc 0 (entget e))) "ARC") (eq (cdr (assoc 0 (entget e))) "ELLIPSE") (eq (cdr (assoc 0 (entget e))) "LINE"))
        (setq pl (cons (vlax-curve-getendpoint e) pl) pl (cons (vlax-curve-getstartpoint e) pl))
      )
    )
    (if (null p)
      (progn
        (setq p (cadr (grread t)))
        (setq pl (vl-sort pl '(lambda ( a b ) (< (distance p a) (distance p b)))))
        (setq n 0)
      )
      (repeat (setq n (1+ n))
        (setq pl (cdr (reverse (cons (car pl) (reverse pl)))))
      )
    )
    (setq pp (car pl))
    (command "_.ZOOM" "_C" "_non" pp)
    (while (< 0 (getvar 'cmdactive)) (command ""))
    (command "_.STRETCH" "_CP" "_non" (mapcar '- pp (list (* (/ (getvar 'viewsize) (cadr (getvar 'screensize))) 10.0) (* (/ (getvar 'viewsize) (cadr (getvar 'screensize))) 10.0))) "_non" (mapcar '+ pp (list (* (/ (getvar 'viewsize) (cadr (getvar 'screensize))) 10.0) (- (* (/ (getvar 'viewsize) (cadr (getvar 'screensize))) 10.0)))) "_non" (mapcar '+ pp (list (* (/ (getvar 'viewsize) (cadr (getvar 'screensize))) 10.0) (* (/ (getvar 'viewsize) (cadr (getvar 'screensize))) 10.0))) "_non" (mapcar '+ pp (list (- (* (/ (getvar 'viewsize) (cadr (getvar 'screensize))) 10.0)) (* (/ (getvar 'viewsize) (cadr (getvar 'screensize))) 10.0))) "" "")
    (while (< 0 (getvar 'cmdactive)) (command "\\"))
  )
  (princ)
)

HTH, M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 7 of 14

marko_ribar
Advisor
Advisor

I had an issue with SPLINE, also some other fixes too... Now should work as desired... Test it...

 

(defun c:zvv ( / *error* ucsf es e pl ppl p pp n )

  (vl-load-com)

  (defun *error* ( msg )
    (if ucsf
      (command "_.UCS" "_P")
    )
    (if msg
      (prompt msg)
    )
    (princ)
  )

  (if (eq (getvar 'worlducs) 0)
    (progn
      (command "_.UCS" "_W")
      (setq ucsf t)
    )
  )
  (setq es (entsel "\nPick 2d curve with vertices to edit-stretch them..."))
  (setq e (car es))
  (command "_.ZOOM" "_C" "_non" (cadr es))
  (while (< 0 (getvar 'cmdactive)) (command ""))
  (prompt "\nZoom&edit vertex... ESC to finish...")
  (while t
    (cond
      ( (eq (cdr (assoc 0 (entget e))) "LWPOLYLINE")
        (setq pl (mapcar '(lambda ( p ) (trans (list (car p) (cadr p) (cdr (assoc 38 (entget e)))) e 0)) (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (eq (car x) 10)) (entget e)))))
      )
      ( (eq (cdr (assoc 0 (entget e))) "POLYLINE")
        (setq v e)
        (while (setq v (entnext v))
          (if (eq (cdr (assoc 0 (entget v))) "VERTEX")
            (setq pl (cons (cdr (assoc 10 (entget v))) pl))
          )
        )
        (setq pl (reverse pl))
      )
      ( (eq (cdr (assoc 0 (entget e))) "SPLINE")
        (setq pl (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (eq (car x) 11)) (entget e))))
      )
      ( (or (eq (cdr (assoc 0 (entget e))) "ARC") (eq (cdr (assoc 0 (entget e))) "ELLIPSE") (eq (cdr (assoc 0 (entget e))) "LINE"))
        (setq pl (cons (vlax-curve-getendpoint e) pl) pl (cons (vlax-curve-getstartpoint e) pl))
      )
    )
    (if (null p)
      (progn
        (setq p (cadr es))
        (setq ppl (vl-sort pl '(lambda ( a b ) (< (distance p a) (distance p b)))))
        (setq n (vl-position (car ppl) pl))
      )
      (repeat (setq n (rem (1+ n) (length pl)))
        (setq pl (cdr (reverse (cons (car pl) (reverse pl)))))
      )
    )
    (if (null pp)
      (setq pp (car ppl))
      (setq pp (car pl))
    )
    (command "_.ZOOM" "_C" "_non" pp)
    (while (< 0 (getvar 'cmdactive)) (command ""))
    (command "_.STRETCH" "_CP" "_non" (mapcar '- pp (list (* (/ (getvar 'viewsize) (cadr (getvar 'screensize))) 10.0) (* (/ (getvar 'viewsize) (cadr (getvar 'screensize))) 10.0))) "_non" (mapcar '+ pp (list (* (/ (getvar 'viewsize) (cadr (getvar 'screensize))) 10.0) (- (* (/ (getvar 'viewsize) (cadr (getvar 'screensize))) 10.0)))) "_non" (mapcar '+ pp (list (* (/ (getvar 'viewsize) (cadr (getvar 'screensize))) 10.0) (* (/ (getvar 'viewsize) (cadr (getvar 'screensize))) 10.0))) "_non" (mapcar '+ pp (list (- (* (/ (getvar 'viewsize) (cadr (getvar 'screensize))) 10.0)) (* (/ (getvar 'viewsize) (cadr (getvar 'screensize))) 10.0))) "" "")
    (while (< 0 (getvar 'cmdactive)) (command "\\"))
  )
  (princ)
)
Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 8 of 14

marko_ribar
Advisor
Advisor

WHY THIS ISN'T ACCEPTED AS A SOLUTION?

 

(defun c:zvv ( / *error* getinfo ucsf es e pl ppl p pp n 10px )

  (vl-load-com)

  (defun *error* ( msg )
    (if ucsf
      (command "_.UCS" "_P")
    )
    (if msg
      (prompt msg)
    )
    (princ)
  )

  (defun getinfo ( es )
    (setq e (car es))
    (cond
      ( (eq (cdr (assoc 0 (entget e))) "LWPOLYLINE")
        (setq pl (mapcar '(lambda ( p ) (trans (list (car p) (cadr p) (cdr (assoc 38 (entget e)))) e 0)) (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (eq (car x) 10)) (entget e)))))
        es
      )
      ( (eq (cdr (assoc 0 (entget e))) "POLYLINE")
        (setq v e)
        (while (setq v (entnext v))
          (if (eq (cdr (assoc 0 (entget v))) "VERTEX")
            (setq pl (cons (cdr (assoc 10 (entget v))) pl))
          )
        )
        (setq pl (reverse pl))
        es
      )
      ( (eq (cdr (assoc 0 (entget e))) "SPLINE")
        (setq pl (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (eq (car x) 11)) (entget e))))
        es
      )
      ( (or (eq (cdr (assoc 0 (entget e))) "ARC") (eq (cdr (assoc 0 (entget e))) "ELLIPSE") (eq (cdr (assoc 0 (entget e))) "LINE"))
        (setq pl (cons (vlax-curve-getendpoint e) pl) pl (cons (vlax-curve-getstartpoint e) pl))
        (if (not (equal (car pl) (cadr pl) 1e-8))
          es
          (progn
            (prompt "\nWrong entity pick...")
            (setq es (entsel "\nPick 2d curve with vertices to edit-stretch them..."))
            (setq es (getinfo es))
          )
        )
      )
      ( t
        (prompt "\nWrong entity pick...")
        (setq es (entsel "\nPick 2d curve with vertices to edit-stretch them..."))
        (setq es (getinfo es))
      )
    )
  )

  (if (eq (getvar 'worlducs) 0)
    (progn
      (command "_.UCS" "_W")
      (setq ucsf t)
    )
  )
  (setq es (entsel "\nPick 2d curve with vertices to edit-stretch them..."))
  (setq e (car es))
  (print)
  (prompt "\nZoom&edit vertex... ESC to finish...")
  (while (and es (setq es (getinfo es)))
    (if (null p)
      (progn
        (setq p (cadr es))
        (setq ppl (vl-sort pl '(lambda ( a b ) (< (distance p a) (distance p b)))))
        (setq n (vl-position (car ppl) pl))
      )
      (repeat (setq n (rem (1+ n) (length pl)))
        (setq pl (cdr (reverse (cons (car pl) (reverse pl)))))
      )
    )
    (if (null pp)
      (setq pp (car ppl))
      (setq pp (car pl))
    )
    (command "_.ZOOM" "_C" "_non" pp)
    (while (< 0 (getvar 'cmdactive)) (command ""))
    (setq 10px (* (/ (getvar 'viewsize) (cadr (getvar 'screensize))) 10.0))
    (command "_.STRETCH" "_CP" "_non" (mapcar '- pp (list 10px 10px)) "_non" (mapcar '+ pp (list 10px (- 10px))) "_non" (mapcar '+ pp (list 10px 10px)) "_non" (mapcar '+ pp (list (- 10px) 10px)) "" "")
    (while (< 0 (getvar 'cmdactive)) (command "\\"))
  )
  (princ)
)

M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 9 of 14

ebsoares
Collaborator
Collaborator
Hi, Marko.

Thanks for the routine you've put together, it works fantastic!

I was wondering if you could implement 3D polylines (it didn't work with them when I tried) and an option to skip editing (suppose we don't need to edit the vertex we're zoomed in to).

Thanks again,

Edgar
0 Likes
Message 10 of 14

marko_ribar
Advisor
Advisor
Accepted solution

I was busy, but I thought you'd figure it... I forgot to nil pl variable inside (getinfo) at the beginning of subfunction...

 

Here, test it now... (Isn't this a solution?)

 

(defun c:zvv ( / *error* getinfo ucsf es e pl ppl p pp n 10px )

  (vl-load-com)

  (defun *error* ( msg )
    (if ucsf
      (command "_.UCS" "_P")
    )
    (if msg
      (prompt msg)
    )
    (princ)
  )

  (defun getinfo ( es )
    (setq e (car es) pl nil)
    (cond
      ( (eq (cdr (assoc 0 (entget e))) "LWPOLYLINE")
        (setq pl (mapcar '(lambda ( p ) (trans (list (car p) (cadr p) (cdr (assoc 38 (entget e)))) e 0)) (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (eq (car x) 10)) (entget e)))))
        es
      )
      ( (eq (cdr (assoc 0 (entget e))) "POLYLINE")
        (setq v e)
        (while (setq v (entnext v))
          (if (eq (cdr (assoc 0 (entget v))) "VERTEX")
            (setq pl (cons (cdr (assoc 10 (entget v))) pl))
          )
        )
        (setq pl (reverse pl))
        es
      )
      ( (eq (cdr (assoc 0 (entget e))) "SPLINE")
        (setq pl (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (eq (car x) 11)) (entget e))))
        es
      )
      ( (or (eq (cdr (assoc 0 (entget e))) "ARC") (eq (cdr (assoc 0 (entget e))) "ELLIPSE") (eq (cdr (assoc 0 (entget e))) "LINE"))
        (setq pl (cons (vlax-curve-getendpoint e) pl) pl (cons (vlax-curve-getstartpoint e) pl))
        (if (not (equal (car pl) (cadr pl) 1e-8))
          es
          (progn
            (prompt "\nWrong entity pick...")
            (setq es (entsel "\nPick 2d curve with vertices to edit-stretch them..."))
            (setq es (getinfo es))
          )
        )
      )
      ( t
        (prompt "\nWrong entity pick...")
        (setq es (entsel "\nPick 2d curve with vertices to edit-stretch them..."))
        (setq es (getinfo es))
      )
    )
  )

  (if (eq (getvar 'worlducs) 0)
    (progn
      (command "_.UCS" "_W")
      (setq ucsf t)
    )
  )
  (setq es (entsel "\nPick 2d curve with vertices to edit-stretch them..."))
  (setq e (car es))
  (print)
  (prompt "\nZoom&edit vertex... ESC to finish...")
  (while (and es (setq es (getinfo es)))
    (if (null p)
      (progn
        (setq p (cadr es))
        (setq ppl (vl-sort pl '(lambda ( a b ) (< (distance p a) (distance p b)))))
        (setq n (vl-position (car ppl) pl))
      )
      (repeat (setq n (rem (1+ n) (length pl)))
        (setq pl (cdr (reverse (cons (car pl) (reverse pl)))))
      )
    )
    (if (null pp)
      (setq pp (car ppl))
      (setq pp (car pl))
    )
    (command "_.ZOOM" "_C" "_non" pp)
    (while (< 0 (getvar 'cmdactive)) (command ""))
    (setq 10px (* (/ (getvar 'viewsize) (cadr (getvar 'screensize))) 10.0))
    (command "_.STRETCH" "_CP" "_non" (mapcar '- pp (list 10px 10px)) "_non" (mapcar '+ pp (list 10px (- 10px))) "_non" (mapcar '+ pp (list 10px 10px)) "_non" (mapcar '+ pp (list (- 10px) 10px)) "" "")
    (while (< 0 (getvar 'cmdactive)) (command "\\"))
  )
  (princ)
)

HTH, M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 11 of 14

marko_ribar
Advisor
Advisor
Accepted solution

Oh, I see now... You want to perform this action from 3D VIEW... Try this, use @ character to skip to next vertex...

 

(defun c:zvv ( / *error* getinfo ucsf es e pl ppl p pp n )

  (vl-load-com)

  (defun *error* ( msg )
    (if ucsf
      (command "_.UCS" "_P")
    )
    (if msg
      (prompt msg)
    )
    (princ)
  )

  (defun getinfo ( es )
    (setq e (car es) pl nil)
    (cond
      ( (eq (cdr (assoc 0 (entget e))) "LWPOLYLINE")
        (setq pl (mapcar '(lambda ( p ) (trans (list (car p) (cadr p) (cdr (assoc 38 (entget e)))) e 0)) (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (eq (car x) 10)) (entget e)))))
        es
      )
      ( (eq (cdr (assoc 0 (entget e))) "POLYLINE")
        (setq v e)
        (while (setq v (entnext v))
          (if (eq (cdr (assoc 0 (entget v))) "VERTEX")
            (setq pl (cons (cdr (assoc 10 (entget v))) pl))
          )
        )
        (setq pl (reverse pl))
        es
      )
      ( (eq (cdr (assoc 0 (entget e))) "SPLINE")
        (setq pl (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (eq (car x) 11)) (entget e))))
        es
      )
      ( (or (eq (cdr (assoc 0 (entget e))) "ARC") (eq (cdr (assoc 0 (entget e))) "ELLIPSE") (eq (cdr (assoc 0 (entget e))) "LINE"))
        (setq pl (cons (vlax-curve-getendpoint e) pl) pl (cons (vlax-curve-getstartpoint e) pl))
        (if (not (equal (car pl) (cadr pl) 1e-8))
          es
          (progn
            (prompt "\nWrong entity pick...")
            (setq es (entsel "\nPick 2d curve with vertices to edit-stretch them..."))
            (setq es (getinfo es))
          )
        )
      )
      ( t
        (prompt "\nWrong entity pick...")
        (setq es (entsel "\nPick 2d curve with vertices to edit-stretch them..."))
        (setq es (getinfo es))
      )
    )
  )

  (if (eq (getvar 'worlducs) 0)
    (progn
      (command "_.UCS" "_W")
      (setq ucsf t)
    )
  )
  (setq es (entsel "\nPick 2d curve with vertices to edit-stretch them..."))
  (setq e (car es))
  (print)
  (prompt "\nZoom&edit vertex... To skip to next vertex - type \"@\" character... ESC to finish...")
  (while (and es (setq es (getinfo es)))
    (if (null p)
      (progn
        (setq p (cadr es))
        (setq ppl (vl-sort pl '(lambda ( a b ) (< (distance p a) (distance p b)))))
        (setq n (vl-position (car ppl) pl))
      )
      (repeat (setq n (rem (1+ n) (length pl)))
        (setq pl (cdr (reverse (cons (car pl) (reverse pl)))))
      )
    )
    (if (null pp)
      (setq pp (car ppl))
      (setq pp (car pl))
    )
    (command "_.ZOOM" "_C" "_non" pp)
    (while (< 0 (getvar 'cmdactive)) (command ""))
    (command "_.STRETCH" "_C" "_non" pp "_non" pp "" "")
    (while (< 0 (getvar 'cmdactive)) (command "\\"))
  )
  (princ)
)

I think that's it... This should be your solution by me...

 

HTH, M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 12 of 14

ebsoares
Collaborator
Collaborator

Marko, this is great work.

 

Thank you very much for the time you put into this.

 

Edgar

0 Likes
Message 13 of 14

ebsoares
Collaborator
Collaborator

Hi, Marko.

 

I just realized this. As I'm editing an element, if we change the view (zoom in, or out, or pan) then the routine will disregard the edit...

0 Likes
Message 14 of 14

ebsoares
Collaborator
Collaborator

Hi, Marko. Never mind, it seems to be working now. Go figure...

 

Thanks again,

 

Edgar

0 Likes