-pan Lisp not doing anything

-pan Lisp not doing anything

jarredmonday
Collaborator Collaborator
306 Views
4 Replies
Message 1 of 5

-pan Lisp not doing anything

jarredmonday
Collaborator
Collaborator

In all transparency, I used Chatgpt to write most of this code. I've tried variation of this base of my search results and I am stuck.

 

I have multiple sheets that are identical and the viewport need to be panned over a specific amount to maintain consistency. While inside the viewport I use the -Pan command the for left & right is 1200inchs (or units) and up & down will be 1440 inchs (or units). I would like help where the command prompt asks which direction and the view inside the view port pans in the specific distance.

 

If anyone is up to adding the process of selecting a viewport, making the viewport active and unlocking if lock, then using the  -pan command. 🙂

(defun c:mvp ()
  (initget 1 "Up Down Left Right")
  (setq direction (getkword "\nWhich direction? [Up/Down/Left/Right]: "))
  (cond
    ((equal (strcase direction) "UP")
     (command (list _.-PAN (trans '(0 1440 0) 0 1))))
    ((equal (strcase direction) "DOWN")
     (command (list _.-PAN (trans '(0 -1440 0) 0 1))))
    ((equal (strcase direction) "LEFT")
     (command (list _.-PAN (trans '(-1200 0 0) 0 1))))
    ((equal (strcase direction) "RIGHT")
     (command (list _.-PAN (trans '(1200 0 0) 0 1))))
  )
  (princ)
)

 

 

Please mark Accept as Solution if your question is answered. Kudos gladly accepted. ⇘
0 Likes
307 Views
4 Replies
Replies (4)
Message 2 of 5

jarredmonday
Collaborator
Collaborator

Actually, I found this code at this link. This works very well. I will try to modify add my choices and return...

 

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pan-all-viewports-in-selected-layout... 

 

(defun c:wr6 ( / *error* *adoc* s vp ce vs cenew )

  (vl-load-com)

  (defun *error* ( m )
    (vla-endundomark *adoc*)
    (if m
      (prompt m)
    )
    (princ)
  )

  (setq *adoc* (vla-get-activedocument (vlax-get-acad-object)))
  (if (= 8 (logand 8 (getvar 'undoctl)))
    (vla-endundomark *adoc*)
  )
  (vla-startundomark *adoc*)
  (while
    (or
      (prompt "\nPick VIEWPORT entity to activate...")
      (not (setq s (ssget "_+.:E:S:L" '((0 . "VIEWPORT") (-4 . "<not") (410 . "Model") (-4 . "not>")))))
    )
    (prompt "\nMissed or picked wrong entity type...")
  )
  (setq vp (ssname s 0))
  (vla-display (vlax-ename->vla-object vp) :vlax-true)
  (vla-put-mspace *adoc* :vlax-true)
  (vla-put-activepviewport *adoc* (vlax-ename->vla-object vp))
  (setq ce (getvar 'viewctr))
  (setq vs (getvar 'viewsize))
  (setq cenew (mapcar '+ ce '(1200.0 0.0 0.0)))
  (vl-cmdf "_.zoom" "_c" "_non" cenew vs)
  (vla-put-mspace *adoc* :vlax-false)
  (*error* nil)
)

 

 

Please mark Accept as Solution if your question is answered. Kudos gladly accepted. ⇘
0 Likes
Message 3 of 5

paullimapa
Mentor
Mentor

Definitely don't rely on Chatgpt because the codes written are all wrong.

Assuming your vport is not locked, try these modifications:

(defun c:mvp ()
  (initget 1 "Up Down Left Right")
  (setq direction (getkword "\nWhich direction? [Up/Down/Left/Right]: "))
  (cond
    ((equal (strcase direction) "UP")
     (command "_.-PAN" (getvar"viewctr") "@0,-1440")
    )
    ((equal (strcase direction) "DOWN")
     (command "_.-PAN" (getvar"viewctr") "@0,1440")
    )
    ((equal (strcase direction) "LEFT")
     (command "_.-PAN" (getvar"viewctr") "@1200,0")
    )
    ((equal (strcase direction) "RIGHT")
     (command "_.-PAN" (getvar"viewctr") "@-1200,0")
    )
  ) 
  (princ)
)

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 4 of 5

Sea-Haven
Mentor
Mentor

I would not go down pan method rather use either a block or a rectang and then make the layouts to suit, this is follow a pline making layouts, at correct scale and sheet size. A grid version would be easy. You can move/ rotate or delete the rectangs then make layouts.

SeaHaven_0-1689137201790.png

 

Just did 28 layouts from this if nothing inside then skip.

SeaHaven_1-1689137241849.png

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-create-automatic-layouts/td-p...

 

 

0 Likes
Message 5 of 5

Kent1Cooper
Consultant
Consultant

Other things ChatGPT doesn't understand yet:

 

How the (initget)/(getkword) system works.  One of its features is that if you type in the right character(s) in response to (getkword), in any case or case combination, it returns the spelling and case combination as in the (initget) argument.  So you can type in U or u or Up or up or UP or uP, and in all cases what will be returned will be "Up."  So the (strcase) operations are unnecessary.

 

That inside an AutoLisp (command) function, the hyphen prefix is not needed on command names.

 

That a simple (=) function works with text strings as well as numbers -- (equal) will do it, but has other capabilities not needed here [e.g. a fuzz factor in numerical comparisons].

 

That the PAN command can be simplified, by giving it a displacement and just Enter to use that as one, rather than as a point.

 

So, a further simplified version:

 

(defun c:mvp ()
  (initget 1 "Up Down Left Right")
  (setq direction (getkword "\nWhich direction? [Up/Down/Left/Right]: "))
  (cond
    ((= direction "Up")
     (command "_.pan" "0,-1440" "")
    )
    ((= direction "Down")
     (command "_.pan" "0,1440" "")
    )
    ((= direction "Left")
     (command "_.pan" "1200,0" "")
    )
    ((= direction "Right")
     (command "_.pan" "-1200,0" "")
    )
  ) 
  (princ)
)

 

Kent Cooper, AIA
0 Likes