CAD Forum - Database of tips, tricks and utilities for AutoCAD, Inventor and other Autodesk products [www.cadforum.cz]
CZ | EN | DE
Login or
registration
  Visitors: 914
RSS channel - CAD tips RSS tips
RSS discussions

Discussion Discussion forum

 

HelpCAD discussion

 
CAD Forum - Homepage CAD discussion forum - ask any CAD-related questions here, share your CAD knowledge on AutoCAD, Inventor, Revit and other Autodesk software with your peers from all over the world. To start a new topic, choose an appropriate forum.

Please abide by the rules of this forum.

How to post questions: register or login, go to the specific forum and click the NEW TOPIC button.
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Topic ClosedLock/ unlock viewports

 Post Reply Post Reply
Author
Sandervp View Drop Down
Groupie
Groupie


Joined: 02.Jun.2014
Location: Netherlands
Using: Autocad 2015 and older
Status: Offline
Points: 30
Direct Link To This Post Topic: Lock/ unlock viewports
    Posted: 20.Oct.2014 at 08:54
I have got a lisp file that will defun 2 commands.
 
One command shall lock all of my viewports and also changes the color of all those locked viewports into green.
The other command shall unlock all of the viewports and the color changes into red.
 
Sometimes I do have something strange:
 
I do have some viewports. They are all unlocked (color red). When I create a new viewport, the viewport is unlocked and his color is "by layer".
 
The following action is to lock all the viewports.
The color of all the viewports is changed into the color green except 1.
 
The color of the last drawed viewport also changed. But not into the color green but in red. The color of unlocked viewports.
Do I look to the properties of the red colored viewport, the display is locked.
 
If I unlock all of the viewports with the created command, the color of all te green colored viewport shall change into red. But the red colored locked viewport jumpes into the green color.
 
How is this possible?
 
This is my lisp file;
 
(vl-load-com)
(defun dxf (n ed) (cdr (assoc n ed)))
(defun c:vpl (/ AD COUNT ENT I PL SS TABNAME VP VPNO)
    (setq ad (vla-get-activedocument (vlax-get-acad-object)))
 
    (vlax-for lay (vla-get-layouts ad)
        (if (/= (setq TabName (strcase (vla-get-name lay))) "MODEL") ;_ end of /=
            (progn
                (if (setq ss (ssget
                                 "X"
                                 (list (cons 0 "viewport")
                                 ) ;_ end of list
                             ) ;_ end of ssget
                    ) ;_ end of setq
                    (progn
                        (setq count (sslength ss))
                        (setq i 0)
                        (if (> count 0)
                            (progn
                                (while (< i count)
                                    (setq
                                        ent (ssname ss
                                                    i
                                            ) ;_ end of ssname
                                    ) ;_ end of setq
                                    (setq vpNo
                                             (dxf
                                                 69
                                                 (entget
                                                     ent
                                                 ) ;_ end of entget
                                             ) ;_ end of dxf
                                    ) ;_ end of setq
                                    (if (> vpNo 1)
                                        (progn
                                            (setq vp (vlax-ename->vla-object
                                                         ent
                                                     ) ;_ end of vlax-ename->vla-object
                                            ) ;_ end of setq
                                            (if (= (vla-get-clipped
                                                       vp
                                                   ) ;_ end of vla-get-clipped
                                                   :vlax-false
                                                ) ;_ end of =
                                                (progn
                                                    (vla-put-color
                                                        vp
                                                        3
                                                    ) ;_ end of vla-put-color
                                      
                                                    (vla-put-layer
                                                        vp
                                                        "defpoints"
                                                    ) ;_ end of vla-put-layer
                                                ) ;_ end of progn
                                                (progn
                                                    (setq
                                                        pl (entget
                                                               (dxf
                                                                   340
                                                                   (entget
                                                                       ent
                                                                   ) ;_ end of entget
                                                               ) ;_ end of dxf
                                                           ) ;_ end of entget
                                                    ) ;_ end of setq
                                                    ;get clip entity
                                                    (setq pl (vlax-ename->vla-object
                                                                 (dxf -1
                                                                      pl
                                                                 ) ;_ end of dxf
                                                             ) ;_ end of vlax-ename->vla-object
                                                    ) ;_ end of setq
                                                    (vla-put-color
                                                        pl
                                                        1
                                                    ) ;_ end of vla-put-color
                                                    (vla-put-layer
                                                        pl
                                                        "defpoints"
                                                    ) ;_ end of vla-put-layer
                                                    (vla-put-color
                                                        vp
                                                        1
                                                    ) ;_ end of vla-put-color
                                       
                                                    (vla-put-layer
                                                        vp
                                                        "defpoints"
                                                    ) ;_ end of vla-put-layer
                                                ) ;_ end of progn
                                            ) ;_ end of if
                                            (vla-put-displaylocked
                                                vp
                                                :vlax-true
                                            ) ;_ end of vla-put-displaylocked
                                            (vla-update vp)
                                        ) ;_ end of progn
                                    ) ;_ end of if
                                    (setq i (1+ i))
                                ) ;_ end of while
                            ) ;_ end of progn
                        ) ;_ end of if
                    ) ;_ end of progn
                ) ;_ end of if
            ) ;_ end of progn
        ) ;_ end of if
    ) ;_ end of vlax-for
) ;_ end of defun
(defun c:vpu (/ AD COUNT ENT I PL SS TABNAME VP VPNO)
    (setq ad (vla-get-activedocument (vlax-get-acad-object)))
 
    (vlax-for lay (vla-get-layouts ad)
        (if (/= (setq TabName (strcase (vla-get-name lay))) "MODEL") ;_ end of /=
            (progn
                (if (setq ss (ssget
                                 "X"
                                 (list (cons 0 "viewport")
                                 ) ;_ end of list
                             ) ;_ end of ssget
                    ) ;_ end of setq
                    (progn
                        (setq count (sslength ss))
                        (setq i 0)
                        (if (> count 0)
                            (progn
                                (while (< i count)
                                    (setq
                                        ent (ssname ss
                                                    i
                                            ) ;_ end of ssname
                                    ) ;_ end of setq
                                    (setq vpNo
                                             (dxf
                                                 69
                                                 (entget
                                                     ent
                                                 ) ;_ end of entget
                                             ) ;_ end of dxf
                                    ) ;_ end of setq
                                    (if (> vpNo 1)
                                        (progn
                                            (setq vp (vlax-ename->vla-object
                                                         ent
                                                     ) ;_ end of vlax-ename->vla-object
                                            ) ;_ end of setq
                                            (if (= (vla-get-clipped
                                                       vp
                                                   ) ;_ end of vla-get-clipped
                                                   :vlax-false
                                                ) ;_ end of =
                                                (progn
                                                    (vla-put-color
                                                        vp
                                                        1
                                                    ) ;_ end of vla-put-color
                                        ; 3 green
                                                    (vla-put-layer
                                                        vp
                                                        "defpoints"
                                                    ) ;_ end of vla-put-layer
                                                ) ;_ end of progn
                                                (progn
                                                    (setq
                                                        pl (entget
                                                               (dxf
                                                                   340
                                                                   (entget
                                                                       ent
                                                                   ) ;_ end of entget
                                                               ) ;_ end of dxf
                                                           ) ;_ end of entget
                                                    ) ;_ end of setq
                                                    ;get clip entity
                                                    (setq pl (vlax-ename->vla-object
                                                                 (dxf -1
                                                                      pl
                                                                 ) ;_ end of dxf
                                                             ) ;_ end of vlax-ename->vla-object
                                                    ) ;_ end of setq
                                                    (vla-put-color
                                                        pl
                                                        3
                                                    ) ;_ end of vla-put-color
                                                    (vla-put-layer
                                                        pl
                                                        "defpoints"
                                                    ) ;_ end of vla-put-layer
                                                    (vla-put-color
                                                        vp
                                                        3
                                                    ) ;_ end of vla-put-color
                                        ; 3 green
                                                    (vla-put-layer
                                                        vp
                                                        "defpoints"
                                                    ) ;_ end of vla-put-layer
                                                ) ;_ end of progn
                                            ) ;_ end of if
                                            (vla-put-displaylocked
                                                vp
                                                :vlax-false
                                            ) ;_ end of vla-put-displaylocked
                                            (vla-update vp)
                                        ) ;_ end of progn
                                    ) ;_ end of if
                                    (setq i (1+ i))
                                ) ;_ end of while
                            ) ;_ end of progn
                        ) ;_ end of if
                    ) ;_ end of progn
                ) ;_ end of if
            ) ;_ end of progn
        ) ;_ end of if
    ) ;_ end of vlax-for
)
 
 
 
 
 
 
 
 
Is it also possible, when you (un)lock a viewport in the properties palette, the color changes also?
 
I want to see in a second which viewport is locked or not
Back to Top
Sandervp View Drop Down
Groupie
Groupie


Joined: 02.Jun.2014
Location: Netherlands
Using: Autocad 2015 and older
Status: Offline
Points: 30
Direct Link To This Post Posted: 28.Oct.2014 at 09:57
I have found the problem.
 
Several times, 3 times in every defun, you'll see:  "(vla-put-color  vp  1)" or  "(vla-put-color  vp  3)" in this lisp.
 
In the defuns "VPU" and "VPL" you'll find them both.
 
I've changed the "(vla-put-color  vp  1)" into "(vla-put-color  vp  3)" in the defun "VPL". And in the defun "VPU", I've changed the "(vla-put-color  vp  3)" into "(vla-put-color  vp  1)".
 
Everything is oke now.
 
If anybody needs the right lisp file;
 
(vl-load-com)
(defun dxf (n ed) (cdr (assoc n ed)))
(defun c:vpl (/ AD COUNT ENT I PL SS TABNAME VP VPNO)
    (setq ad (vla-get-activedocument (vlax-get-acad-object)))
 
    (vlax-for lay (vla-get-layouts ad)
        (if (/= (setq TabName (strcase (vla-get-name lay))) "MODEL") ;_ end of /=
            (progn
                (if (setq ss (ssget
                                 "X"
                                 (list (cons 0 "viewport")
                                 ) ;_ end of list
                             ) ;_ end of ssget
                    ) ;_ end of setq
                    (progn
                        (setq count (sslength ss))
                        (setq i 0)
                        (if (> count 0)
                            (progn
                                (while (< i count)
                                    (setq
                                        ent (ssname ss
                                                    i
                                            ) ;_ end of ssname
                                    ) ;_ end of setq
                                    (setq vpNo
                                             (dxf
                                                 69
                                                 (entget
                                                     ent
                                                 ) ;_ end of entget
                                             ) ;_ end of dxf
                                    ) ;_ end of setq
                                    (if (> vpNo 1)
                                        (progn
                                            (setq vp (vlax-ename->vla-object
                                                         ent
                                                     ) ;_ end of vlax-ename->vla-object
                                            ) ;_ end of setq
                                            (if (= (vla-get-clipped
                                                       vp
                                                   ) ;_ end of vla-get-clipped
                                                   :vlax-false
                                                ) ;_ end of =
                                                (progn
                                                    (vla-put-color
                                                        vp
                                                        3
                                                    ) ;_ end of vla-put-color
                                      
                                                    (vla-put-layer
                                                        vp
                                                        "defpoints"
                                                    ) ;_ end of vla-put-layer
                                                ) ;_ end of progn
                                                (progn
                                                    (setq
                                                        pl (entget
                                                               (dxf
                                                                   340
                                                                   (entget
                                                                       ent
                                                                   ) ;_ end of entget
                                                               ) ;_ end of dxf
                                                           ) ;_ end of entget
                                                    ) ;_ end of setq
                                                    ;get clip entity
                                                    (setq pl (vlax-ename->vla-object
                                                                 (dxf -1
                                                                      pl
                                                                 ) ;_ end of dxf
                                                             ) ;_ end of vlax-ename->vla-object
                                                    ) ;_ end of setq
                                                    (vla-put-color
                                                        pl
                                                        3
                                                    ) ;_ end of vla-put-color
                                                    (vla-put-layer
                                                        pl
                                                        "defpoints"
                                                    ) ;_ end of vla-put-layer
                                                    (vla-put-color
                                                        vp
                                                        3
                                                    ) ;_ end of vla-put-color
                                       
                                                    (vla-put-layer
                                                        vp
                                                        "defpoints"
                                                    ) ;_ end of vla-put-layer
                                                ) ;_ end of progn
                                            ) ;_ end of if
                                            (vla-put-displaylocked
                                                vp
                                                :vlax-true
                                            ) ;_ end of vla-put-displaylocked
                                            (vla-update vp)
                                        ) ;_ end of progn
                                    ) ;_ end of if
                                    (setq i (1+ i))
                                ) ;_ end of while
                            ) ;_ end of progn
                        ) ;_ end of if
                    ) ;_ end of progn
                ) ;_ end of if
            ) ;_ end of progn
        ) ;_ end of if
    ) ;_ end of vlax-for
) ;_ end of defun
(defun c:vpu (/ AD COUNT ENT I PL SS TABNAME VP VPNO)
    (setq ad (vla-get-activedocument (vlax-get-acad-object)))
 
    (vlax-for lay (vla-get-layouts ad)
        (if (/= (setq TabName (strcase (vla-get-name lay))) "MODEL") ;_ end of /=
            (progn
                (if (setq ss (ssget
                                 "X"
                                 (list (cons 0 "viewport")
                                 ) ;_ end of list
                             ) ;_ end of ssget
                    ) ;_ end of setq
                    (progn
                        (setq count (sslength ss))
                        (setq i 0)
                        (if (> count 0)
                            (progn
                                (while (< i count)
                                    (setq
                                        ent (ssname ss
                                                    i
                                            ) ;_ end of ssname
                                    ) ;_ end of setq
                                    (setq vpNo
                                             (dxf
                                                 69
                                                 (entget
                                                     ent
                                                 ) ;_ end of entget
                                             ) ;_ end of dxf
                                    ) ;_ end of setq
                                    (if (> vpNo 1)
                                        (progn
                                            (setq vp (vlax-ename->vla-object
                                                         ent
                                                     ) ;_ end of vlax-ename->vla-object
                                            ) ;_ end of setq
                                            (if (= (vla-get-clipped
                                                       vp
                                                   ) ;_ end of vla-get-clipped
                                                   :vlax-false
                                                ) ;_ end of =
                                                (progn
                                                    (vla-put-color
                                                        vp
                                                        1
                                                    ) ;_ end of vla-put-color
                                        ; 3 green
                                                    (vla-put-layer
                                                        vp
                                                        "defpoints"
                                                    ) ;_ end of vla-put-layer
                                                ) ;_ end of progn
                                                (progn
                                                    (setq
                                                        pl (entget
                                                               (dxf
                                                                   340
                                                                   (entget
                                                                       ent
                                                                   ) ;_ end of entget
                                                               ) ;_ end of dxf
                                                           ) ;_ end of entget
                                                    ) ;_ end of setq
                                                    ;get clip entity
                                                    (setq pl (vlax-ename->vla-object
                                                                 (dxf -1
                                                                      pl
                                                                 ) ;_ end of dxf
                                                             ) ;_ end of vlax-ename->vla-object
                                                    ) ;_ end of setq
                                                    (vla-put-color
                                                        pl
                                                        1
                                                    ) ;_ end of vla-put-color
                                                    (vla-put-layer
                                                        pl
                                                        "defpoints"
                                                    ) ;_ end of vla-put-layer
                                                    (vla-put-color
                                                        vp
                                                        1
                                                    ) ;_ end of vla-put-color
                                        ; 3 green
                                                    (vla-put-layer
                                                        vp
                                                        "defpoints"
                                                    ) ;_ end of vla-put-layer
                                                ) ;_ end of progn
                                            ) ;_ end of if
                                            (vla-put-displaylocked
                                                vp
                                                :vlax-false
                                            ) ;_ end of vla-put-displaylocked
                                            (vla-update vp)
                                        ) ;_ end of progn
                                    ) ;_ end of if
                                    (setq i (1+ i))
                                ) ;_ end of while
                            ) ;_ end of progn
                        ) ;_ end of if
                    ) ;_ end of progn
                ) ;_ end of if
            ) ;_ end of progn
        ) ;_ end of if
    ) ;_ end of vlax-for
)
 
 
Back to Top

Related CAD tips:


 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down



This page was generated in 0,391 seconds.