viewport selection and cycling

Discussion in 'AutoCAD' started by Buzz123, Jun 15, 2004.

  1. Buzz123

    Buzz123 Guest

    I'd like to have a toolbar button that can select a viewport in paperspace to expose its' properties in the properties window, and to aid selection I'd like it to cycle through the available viewports on subsequent button presses.

    The cycling part of it is similar to using Crtl-R, except that Mspace is not active.

    Is there an easy way to do this in lisp? Any help you could give me would be appreciated.
     
    Buzz123, Jun 15, 2004
    #1
  2. Buzz123

    Jeff Mishler Guest

    Something like this?

    (defun c:cycle-vp (/ doc ans vplist ss i)
    (vl-load-com)
    (and (setq doc (vla-get-activedocument (vlax-get-acad-object)))
    (= (getvar "tilemode") 0)
    (setq ans "N")
    (vlax-for x (vla-get-block (vla-get-activelayout doc))
    (if (= (vla-get-objectname x) "AcDbViewport")
    (setq vplist (cons x vplist))
    )
    )
    (setq vplist (cdr (reverse vplist)))
    (setq ss (ssadd))
    (setq i 0)
    (while (= (strcase ans) "N")
    (ssadd (vlax-vla-object->ename (nth i vplist)) ss)
    (sssetfirst nil ss)
    (setq temp (getstring "\nEnter or space for next, any other key to
    exit....."))
    (if (not (= temp ""))
    (setq ans "X")
    (progn
    (sssetfirst nil nil)
    (ssdel (vlax-vla-object->ename (nth i vplist)) ss)
    (setq i (1+ i))
    (if (= i (length vplist))(setq i 0))
    )
    )
    )
    )
    (princ)
    )

    Jeff

    to expose its' properties in the properties window, and to aid selection I'd
    like it to cycle through the available viewports on subsequent button
    presses.
    be appreciated.
     
    Jeff Mishler, Jun 15, 2004
    #2
  3. Buzz123

    Buzz123 Guest

    Jeff

    Thanks. Your code looks great. I had hoped to get something that would return to the command line after each button push (and leave the viewport selected).

    Is that possible?

    Thanks again

    Michael
     
    Buzz123, Jun 15, 2004
    #3
  4. Buzz123

    Jeff Mishler Guest

    Well, how about this?

    (defun c:cycle-vp (/ doc ss)
    (vl-load-com)
    (and (setq doc (vla-get-activedocument (vlax-get-acad-object)))
    (= (getvar "tilemode") 0)
    (= (getvar "cvport") 1)
    (or *jmm-tab*
    (setq *jmm-tab* (getvar "ctab"))
    )
    (or (= *jmm-tab* (getvar "ctab"))
    (progn
    (setq *jmm-vplist* nil)
    (setq *jmm-i* nil)
    (setq *jmm-tab* (getvar "ctab"))
    )
    )
    (or *jmm-vplist*
    (and (vlax-for x (vla-get-block (vla-get-activelayout doc))
    (if (= (vla-get-objectname x) "AcDbViewport")
    (setq *jmm-vplist* (cons x *jmm-vplist*))
    )
    )
    (setq *jmm-vplist* (cdr (reverse *jmm-vplist*)))
    )
    )
    (setq ss (ssadd))
    (or *jmm-i*
    (setq *jmm-i* 0)
    )
    (sssetfirst nil nil)
    (ssadd (vlax-vla-object->ename (nth *jmm-i* *jmm-vplist*)) ss)
    (sssetfirst nil ss)
    (setq *jmm-i* (1+ *jmm-i*))
    (if (= *jmm-i* (length *jmm-vplist*))(setq *jmm-i* 0))
    )
    (princ)
    )

    You're welcome,
    Jeff

    return to the command line after each button push (and leave the viewport
    selected).
     
    Jeff Mishler, Jun 15, 2004
    #4
  5. Buzz123

    Buzz123 Guest

    Jeff

    What I was hoping for was on the first run through the code it would select the first viewport and on subsequent runs it would cycle through other viewports contained on the paperspace layout. And each time it would return you to the command line with the viewport still selected.

    The most recent code you've posted slects the first viewport, but won't "cycle" to other veiwports. Also if the first viewport is deleted then an error (bad argument type: lentityp nil) is returned.

    Thanks anyway

    Michael
     
    Buzz123, Jun 16, 2004
    #5
  6. Buzz123

    Jeff Mishler Guest

    See comments in-line.....Mine in caps, not to "shout" but for ease of seeing
    them.
    select the first viewport and on subsequent runs it would cycle through
    other viewports contained on the paperspace layout. THIS IS HOW IT
    WORKS.....AT LEAST IT DOES HERE. And each time it would return you to the
    command line with the viewport still selected. AGAIN, THIS IS HOW I MADE IT
    WORK. IF YOU HAVE THE PROPERTIES DIALOG OPEN, IT WILL REFLECT THE CURRENTLY
    SELECTED VP
    "cycle" to other veiwports. AGAIN, THIS CODE DOES CYCLE THRU ALL VPORTS.
    Also if the first viewport is deleted then an error (bad argument type:
    lentityp nil) is returned. I HAVE MADE SOME REVISIONS AND THIS IS NOW
    ADDRESSED.
    IF it is NOT working the way you have described and I know it works here,
    I'm wondering if maybe you didn't load the first one and not the second one.
    The revised one I have prompts for the first Vport, it then will cycle from
    that one.

    Jeff
     
    Jeff Mishler, Jun 16, 2004
    #6
  7. Buzz123

    Buzz123 Guest

    Jeff

    Thanks for all your help. I did a little more testing last night and I've found that the odd behaviour occurs if you create additional viewports after running the lisp code. i.e. select a paperspace layout with only one viewport and run the code, create additional viewports and run the code - it will only ever select the 1st one. You can reset the behaviour by switching to another paperspace layout and running the code again. It also still has trouble when viewports are deleted, but you can reset this behaviour as described above.

    Thanks for all your help. The code's in a form that is very usable for my purposes. I'm in awe of anyone who can do lisp, and you've been very speedy with your replies. Much appreciated.

    Regards

    Michael
     
    Buzz123, Jun 16, 2004
    #7
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.