Graphscr (Lisp flips back and forth)

Graphscr (Lisp flips back and forth)

Lineabove
Collaborator Collaborator
585 Views
5 Replies
Message 1 of 6

Graphscr (Lisp flips back and forth)

Lineabove
Collaborator
Collaborator

Below is a lisp which saves the current drawing Layer state of Model Space, Paper Space Layouts and Paper Space Layout Viewports.

 

During use it will flip back and forth between the Text window and the Graphics screen.

 

Would a lisp master please take a look and offer a suggestion as how I may prevent the flipping back and forth please.

 

 

;; Prepared by standing on the shoulders of others...
;; Many thanks to Henrique (hmsilva) for the bulk of this code
;; Many thanks to unknown author for the balance of this code
 
 
 

(defun c:LSVPorts (/ _ctab layst nt i ss vp)
 

  (setq _ctab (getvar 'CTAB))
  (foreach x (layoutlist)
    (setvar 'CTAB x)
    (if (and (= 0 (getvar "tilemode")) (>= (getvar "cvport") 2))
      (command "_.pspace")
    )
    (command "_.zoom" "_E")
 

    ;;PAPERSPACE LAYOUT TAB LAYERSTATES
    (IF (layerstate-has (getvar "CTAB"))
      (layerstate-delete (getvar "CTAB"))
    )
    (COMMAND "-LAYER" "A" "S" (getvar "CTAB") "" "" "")
    (graphscr)
    (princ)
 
 
 
    (if (setq ss (ssget "_X"
   (list '(0 . "VIEWPORT")
         '(-4 . "!=")
         '(69 . 1)
         (cons 410 x)
   )
   )
 )
      (repeat (setq i (sslength ss))
 (setq hnd (ssname ss (setq i (1- i)))
       ent (entget hnd)
       vp  (cdr (assoc 69 ent))
 )
 (if (> vp 1)
   (progn
     (if
       (not
  (and (= 0 (getvar "tilemode")) (>= (getvar "cvport") 2))
       )
        (command "_.mspace")
     )
     (setvar 'CVPORT vp)
     (setq layst (strcat x " VP " (itoa vp)))
 

     ;;PAPERSPACE LAYOUT TAB VIEWPORT LAYERSTATES
     (IF (layerstate-has layst)
       (layerstate-delete layst)
     )
     (COMMAND "-LAYER" "A" "S" layst "" "" "")
     (graphscr)
     (princ)
 
 
 
   )
 )
      )
    )
    (command "_.pspace")
  )
 
  (Command "Model")
  (Command "ZOOM" "E")
 
  ;; MODEL SPACE LAYERSTATE
  (IF (layerstate-has (getvar "CTAB"))
    (layerstate-delete (getvar "CTAB"))
  )
  (COMMAND "-LAYER" "A" "S" (getvar "CTAB") "" "" "")
  (graphscr)
  (princ)
 
  (setvar 'CTAB _ctab)
  (princ)
)
0 Likes
Accepted solutions (1)
586 Views
5 Replies
Replies (5)
Message 2 of 6

Lineabove
Collaborator
Collaborator

I may have resolved the issue of flipping back and forth between the textscreen and the graphscr.

 

As I am learning lisp one line at a time... would a Lisp Master please take a look at in case I made some fatal mistake.

 

I revised the line:

(COMMAND "-LAYER" "A" "S" (getvar "CTAB") "" "" "")

to read:

(layerstate-save (getvar "CTAB") 128 nil)

 

And I revised the line:

(COMMAND "-LAYER" "A" "S" layst "" "" "")

to read:

(layerstate-save layst 128 (ssname (ssget "X" '((0 . "VIEWPORT")(68 . 1))) 0))

 

 

 

 

 

 

;; Prepared by standing on the shoulders of others...
;; Many thanks to Henrique (hmsilva) for the bulk of this code
;; Many thanks to unknown author for the balance of this code
 
 
 

(defun c:LSVPorts (/ _ctab layst nt i ss vp)
 
  (setq _ctab (getvar 'CTAB))
  (foreach x (layoutlist)
    (setvar 'CTAB x)
    (if (and (= 0 (getvar "tilemode")) (>= (getvar "cvport") 2))
      (command "_.pspace")
    )
    (command "_.zoom" "_E")

    ;;PAPERSPACE LAYOUT TAB LAYERSTATES
    (IF (layerstate-has (getvar "CTAB"))
      (layerstate-delete (getvar "CTAB"))
    )
    (layerstate-save (getvar "CTAB") 128 nil)
    (princ)
 
    (if (setq ss (ssget "_X"
   (list '(0 . "VIEWPORT")
         '(-4 . "!=")
         '(69 . 1)
         (cons 410 x)
   )
   )
 )
      (repeat (setq i (sslength ss))
 (setq hnd (ssname ss (setq i (1- i)))
       ent (entget hnd)
       vp  (cdr (assoc 69 ent))
 )
 (if (> vp 1)
   (progn
     (if
       (not
  (and (= 0 (getvar "tilemode")) (>= (getvar "cvport") 2))
       )
        (command "_.mspace")
     )
     (setvar 'CVPORT vp)
     (setq layst (strcat x " VP " (itoa vp)))

     ;;PAPERSPACE LAYOUT TAB VIEWPORT LAYERSTATES
     (IF (layerstate-has layst)
       (layerstate-delete layst)
     )
       (layerstate-save layst 128 (ssname (ssget "X" '((0 . "VIEWPORT")(68 . 1))) 0))
     (princ)
 
 
0 Likes
Message 3 of 6

Lineabove
Collaborator
Collaborator

I'm trying this one more time...

 

Did not paste the entire lisp in my last post so this time I have attached the lisp file.

 

0 Likes
Message 4 of 6

hmsilva
Mentor
Mentor
Accepted solution

@Anonymous wrote:

I'm trying this one more time...

 

Did not paste the entire lisp in my last post so this time I have attached the lisp file.

 


Hi Lineabove,

 

'During use it will flip back and forth between the Text window and the Graphics screen.'

 

the code should not mess with Text / Graphic screan, the code sets currente each layout Tab, saves the layer states, activates each Viewport, saves the layer states, set the Modet Tab current, saves the layer states and set current the original Tab.

 

Attached, your code, slightly modified.

 Untested... I don´t have AutoCAD in this old laptop...

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 5 of 6

Lineabove
Collaborator
Collaborator

Thank you Henrique.

 

I respect your expertise with lisp.

(I keep learning from your posts.)

 

 

0 Likes
Message 6 of 6

hmsilva
Mentor
Mentor

@Anonymous wrote:

Thank you Henrique.

 

I respect your expertise with lisp.

(I keep learning from your posts.)


You're welcome, Lineabove
Glad I could help

Henrique

EESignature

0 Likes