How to simulate a Key beeing pressed in a LISP Routine?

How to simulate a Key beeing pressed in a LISP Routine?

alx86
Enthusiast Enthusiast
1,396 Views
4 Replies
Message 1 of 5

How to simulate a Key beeing pressed in a LISP Routine?

alx86
Enthusiast
Enthusiast

Hi,

 

I'm trying to create a very basic LISP routine that will:

 

-change to next Layout Tab

-Lock all viewport

-Zoom/Extent

 

the only part I don't know how to do, is to simulate ctrl+pagedown being pressed to change tab

 

My LISP look like this so far:

 

(defun C:NE (/)
  (ctrl+pagedown) <---- How should I write this part?
  (command "_.PSPACE" "mview" "l" "on" "all" "")
  (command "ZOOM" "E")
)

 

Thanks for any help 🙂

0 Likes
Accepted solutions (1)
1,397 Views
4 Replies
Replies (4)
Message 2 of 5

M_Hensley
Advisor
Advisor

To change layouts in lisp you need to know the layout name. To switch to layout1 would be (setvar "ctab" "layout1")

(layoutlist) will return a list of layouts so you can do so comparative tests.

0 Likes
Message 3 of 5

hmsilva
Mentor
Mentor

@Anonymous wrote:

Hi,

 

I'm trying to create a very basic LISP routine that will:

 

-change to next Layout Tab

-Lock all viewport

-Zoom/Extent

 ...


Hi abonneau,

 

The 'layoutlist' function will return a list with all layouts in alphabetical order, not in tab order.

To change to the next layout, we'll have to get the actual tab order, to change to the 'next' layout.

To get the tab order, using AUTOLISP, we would have to look in ACAD_LAYOUT dictionary...

Using Visual LISP, it is easier, and the 'layout order' is a property from the Layout object in Layouts collection.

 

(vl-load-com)
(defun c:ne (/ acdoc aclyt app fstlyt lyts newlyt order)
  (setq app   (vlax-get-acad-object)
        acdoc (vla-get-activedocument app)
        aclyt (vla-get-activelayout acdoc)
        lyts  (vla-get-layouts acdoc)
        order (vla-get-taborder aclyt)
  )
  (if (and (/= order 0) (> (getvar 'CVPORT) 1))
    (command "_.pspace")
  )
  (vlax-for lyt lyts
    (if (= (vla-get-taborder lyt) (1+ order))
      (setq newlyt lyt)
    )
    (if (= (vla-get-taborder lyt) 1)
      (setq fstlyt lyt)
    )
  )
  (if newlyt
    (vla-put-activelayout acdoc newlyt)
    (vla-put-activelayout acdoc fstlyt)
  )
  (vlax-for blk (vla-get-block (vla-get-activelayout acdoc))
    (if (= (vla-get-objectname blk) "AcDbViewport")
      (vlax-put blk 'displaylocked -1)
    )
  )
  (vla-ZoomExtents app)
  (princ)
)

 

 

Hope this helps,
Henrique

 

EESignature

Message 4 of 5

alx86
Enthusiast
Enthusiast
Accepted solution

Thanks a lot hmsilva 🙂

 

Your routine work very well. The only thing is if the next layout is currently in an active viewport, it will zoom/extent inside the viewport instead of locking it, then zoom/extent to the layout. Beeing very beginner with lisp I barely understead them when I read them, but I've try replacing this part:

 

 (vlax-for blk (vla-get-block (vla-get-activelayout acdoc))
    (if (= (vla-get-objectname blk) "AcDbViewport")
      (vlax-put blk 'displaylocked -1)
    )
  )

 

for this line:

 

(command "_.PSPACE" "mview" "l" "on" "all" "")

 

____________________________________________________

 

 

And now it work perfectly 🙂 So the final version look like this:

 

  (vl-load-com)
(defun c:ne (/ acdoc aclyt app fstlyt lyts newlyt order)
  (setq app   (vlax-get-acad-object)
        acdoc (vla-get-activedocument app)
        aclyt (vla-get-activelayout acdoc)
        lyts  (vla-get-layouts acdoc)
        order (vla-get-taborder aclyt)
  )
  (if (and (/= order 0) (> (getvar 'CVPORT) 1))
    (command "_.pspace")
  )
  (vlax-for lyt lyts
    (if (= (vla-get-taborder lyt) (1+ order))
      (setq newlyt lyt)
    )
    (if (= (vla-get-taborder lyt) 1)
      (setq fstlyt lyt)
    )
  )
  (if newlyt
    (vla-put-activelayout acdoc newlyt)
    (vla-put-activelayout acdoc fstlyt)
  )
    (command "_.PSPACE" "mview" "l" "on" "all" "")
  (vla-ZoomExtents app)
  (princ)
)

 

0 Likes
Message 5 of 5

hmsilva
Mentor
Mentor

You're welcome, abonneau!

Glad you have it sorted!

 

Henrique

EESignature

0 Likes