Lisp works with AutoCAD 2023 but not with 2024

Lisp works with AutoCAD 2023 but not with 2024

sander.van.pelt
Advocate Advocate
547 Views
4 Replies
Message 1 of 5

Lisp works with AutoCAD 2023 but not with 2024

sander.van.pelt
Advocate
Advocate

Hello everybody,

 

I use a lisp to lock and unlock all viewports. If I lock my viewports, they should turn green. When I unlock these, they turn red.

If I now use this lisp in AutoCAD 2023, there is nothing wrong and it works as expected.
When I use it now in AutoCAD 2024, the viewports turn white as soon as I lock them. When I unlock them, they turn red.

But the lisp is loaded and also added to the Startup Suite. If I load this lisp again, the problem is solved but if I open another drawing again (without closing the other drawing where I load the lisp again) I need to load the lisp again.

How is it possible that the lisp works correctly in 2023 but does not work in 2024 and I need to reload it every time.

 

thanks in advance for your comments

 

 

(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)))

(COMMAND "-LAYER" "N" "Viewport" "" "")
(COMMAND "-LAYER" "U" "Viewport" "" "")
(COMMAND "-LAYER" "PLOT" "N" "Viewport" "")
(COMMAND "-LAYER" "ON" "Viewport" "")


    (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
                                                        70
                                                    ) ;_ end of vla-put-color
                                       
                                                    (vla-put-layer
                                                        vp
                                                        "Viewport"
                                                    ) ;_ 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
                                                        70
                                                    ) ;_ end of vla-put-color
                                                    (vla-put-layer
                                                        pl
                                                        "Viewport"
                                                    ) ;_ end of vla-put-layer
                                                    (vla-put-color
                                                        vp
                                                        70
                                                    ) ;_ end of vla-put-color
                                        
                                                    (vla-put-layer
                                                        vp
                                                        "Viewport"
                                                    ) ;_ 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)))

(COMMAND "-LAYER" "N" "Viewport" "" "")
(COMMAND "-LAYER" "U" "Viewport" "" "")
(COMMAND "-LAYER" "PLOT" "N" "Viewport" "")
(COMMAND "-LAYER" "ON" "Viewport" "")

    (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
                                                        "Viewport"
                                                    ) ;_ 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
                                                        "Viewport"
                                                    ) ;_ end of vla-put-layer
                                                    (vla-put-color
                                                        vp
                                                        1
                                                    ) ;_ end of vla-put-color
                                        ; 3 green
                                                    (vla-put-layer
                                                        vp
                                                        "Viewport"
                                                    ) ;_ 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

)

 

 

0 Likes
548 Views
4 Replies
Replies (4)
Message 2 of 5

rgrainer
Collaborator
Collaborator

Try
ACADLSPASDOC set to 1

0 Likes
Message 3 of 5

Kent1Cooper
Consultant
Consultant

ACADLSPASDOC is only applicable if you use a file called acad.lsp [or acadlt.lsp] to load the routine.  I would use acaddoc.lsp to do it, because you don't need to set anything to have it always run with every opening of every drawing [or creation of a new one].

 

The Startup Suite is >described< as being "loaded each time you start the product."  It does not say things in it are loaded every time you open a drawing.  I have sometimes had reason to think they really are, or maybe some things could be, but that may have been only under special circumstances, and a literal reading suggests they are not, so I don't use that.

 

This is from the page >About Auto-Loading and Running AutoLisp Routines< sounding just like the description about the Startup Suite:

 

By default, the acad.lsp or acadlt.lsp file is loaded only once, when the product starts, whereas the acaddoc.lsp or acadltdoc.lsp file is loaded with each individual document (or drawing).

Kent Cooper, AIA
0 Likes
Message 4 of 5

pendean
Community Legend
Community Legend

@sander.van.pelt  Your posted LISP works fine in R2024.1 as it does in R2023.1.4 here in Win10Pro.

You might have an older VPL/VPU lisp loading and doing what you see until such time as you load this posted LISP.

 

Explore this page, and read carefully the words used

http://www.lee-mac.com/autoloading.html

pendean_0-1701982971801.png

 

vs

pendean_1-1701983016157.png

 

0 Likes
Message 5 of 5

Sea-Haven
Mentor
Mentor

I ahve been using the startup suite for years multiple users and as far as I can tell loads for every dwg as you open. I use custom lisps so easier to not edit Acaddoc.lsp etc. My start up lisp has numerous "Autoload" this also allows demand loading of a lisp when you type a custom command name. 

 

0 Likes