Error Layout not initialized

Error Layout not initialized

martin_leiter
Advocate Advocate
443 Views
11 Replies
Message 1 of 12

Error Layout not initialized

martin_leiter
Advocate
Advocate

I have the following problem: When I run the following Lisp and then want to publish it, I get the following error message: Layout not initialized. However, the page settings are correctly assigned for all layouts. However, if I manually delete the layouts that I don't need and then click publish, this error message does not appear and I can publish without any problems. Does anyone know a solution to use the Lisp and not get an error message when publishing?

Code:

 (defun c:Dellay()
(vl-load-com)
(SETVAR "CMDECHO" 0)
(command "_undo" "_begin")
(setvar 'ctab "Model")

;; Initialisiere die Liste der Layout-Namen
(setq plotabs '())

;; Sammle alle Layout-Namen
(vlax-for lay (vla-get-Layouts (vla-get-activedocument (vlax-get-acad-object)))
(setq plotabs (cons (vla-get-name lay) plotabs))
)

;; Lösche die Layouts, die "Layout" im Namen haben
(foreach lay plotabs
(if (and (/= lay "Model")
(wcmatch (strcase lay) "*LAYOUT*"))
(progn
(princ (strcat "\nDeleting layout: " lay)) ;; Debugging-Ausgabe
(command "_.layout" "_d" lay)
)
)
)

(command "_undo" "_end")
(SETVAR "CMDECHO" 1)
(princ)
)

0 Likes
444 Views
11 Replies
Replies (11)
Message 2 of 12

Moshe-A
Mentor
Mentor

@martin_leiter  hi,

 

the problem could be you are iterating with (vlax-for) which also return some objects you do not see on layout tabs (like the paper space it self).

instead you can use (layoutlist) function (see bellow correction but not tested)

 

Moshe

 

 

 

(vl-load-com)

(defun c:Dellay()
 (command "_undo" "_begin")
 (setvar "cmdecho" 0)
 (setvar 'ctab "Model")

 ;; Initialisiere die Liste der Layout-Namen
; (setq plotabs '())

;; Sammle alle Layout-Namen
; (vlax-for lay (vla-get-Layouts (vla-get-activedocument (vlax-get-acad-object)))
;  (setq plotabs (cons (vla-get-name lay) plotabs))
; )

 ;; Lösche die Layouts, die "Layout" im Namen haben
; (foreach lay plotabs
 (foreach lay (layoutlist)
  (if (and (/= lay "Model")
   (wcmatch (strcase lay) "*LAYOUT*"))
   (progn
    (princ (strcat "\nDeleting layout: " lay)) ;; Debugging-Ausgabe
    (command "_.layout" "_d" lay)
   )
  )
 )

 (command "_undo" "_end")
 (setvar "cmdecho"  1)
  
 (princ)
)

 

 

 

0 Likes
Message 3 of 12

martin_leiter
Advocate
Advocate

Hello Moshe,
Unfortunately that doesn't seem to be the case. It still gives the error message when publishing.

0 Likes
Message 4 of 12

Moshe-A
Mentor
Mentor

@martin_leiter ,

 

do some tests:

1. try on another drawing (maybe there some errors on that file that need to be correct by recover/audit)

2. instead of deleting any layout contain *LAYOUT* specify the layout(s) specific name(s).

 

Moshe

 

0 Likes
Message 5 of 12

martin_leiter
Advocate
Advocate

Hello Moshe,
I have already tested this with several layouts. It is always the same.
The code automatically deletes several layouts that contain LAYOUT in the name.
How can I change the code to include all the names that are to be deleted in the list?
(foreach lay (layoutlist)
(if (and (/= lay "Model")
(wcmatch (strcase lay) "*LAYOUT*"))
(progn
(princ (strcat "\nDeleting layout: " lay)) ;; Debugging output
(command "_.layout" "_d" lay)
)
)
)

0 Likes
Message 6 of 12

Moshe-A
Mentor
Mentor

@martin_leiter ,

 

try this and for test, move to a new\clean drawing, modify line #24 with your layouts name

 

Moshe

 

(vl-load-com)

(defun c:Dellay (/ layouts)
 
 (command "_undo" "_begin")
 (setvar "cmdecho" 0)
 (setvar 'ctab "Model")

 ;; Initialisiere die Liste der Layout-Namen
; (setq plotabs '())

;; Sammle alle Layout-Namen
; (vlax-for lay (vla-get-Layouts (vla-get-activedocument (vlax-get-acad-object)))
;  (setq plotabs (cons (vla-get-name lay) plotabs))
; )

 ;; Lösche die Layouts, die "Layout" im Namen haben
; (foreach lay plotabs

 
; (foreach lay (layoutlist)
  
 (setq layouts (vla-get-Layouts (vla-get-activedocument (vlax-get-acad-object))))
 (foreach lay '("layout1" "layout2" "layout2") ; list layout(s) name
    
  (if (and
	(/= lay "Model")
	(not (vl-catch-all-error-p (vl-catch-all-apply 'vla-item (list layouts lay)))) ; is layout exist
      )    
   (progn
    (princ (strcat "\nDeleting layout: " lay)) ;; Debugging-Ausgabe
    (command "_.layout" "_d" lay)
   ); progn
  ); if
 ); foreach

 (vlax-release-object layouts)
  
 (command "_undo" "_end")
 (setvar "cmdecho"  1)
  
 (princ)
)

 

 

 

0 Likes
Message 7 of 12

martin_leiter
Advocate
Advocate

Hello Moshe,
unfortunately still the same error. See picture

martin_leiter_0-1732092980281.png

 

0 Likes
Message 8 of 12

Moshe-A
Mentor
Mentor

@martin_leiter hi,

 

'layout not initialized' has noting to do with your lisp, it also happen manually.

if you create new layout before going to publish pick it to initialize it

 

Moshe

 

 

0 Likes
Message 9 of 12

martin_leiter
Advocate
Advocate

Hello Moshe,
I know that. All layouts are initialized.
The page setup was carried out in the template drawing for all layouts.
It would be easy if you knew which layout it was that was causing the error message. Unfortunately, no layout name is displayed in the error message.

0 Likes
Message 10 of 12

Moshe-A
Mentor
Mentor

@martin_leiter ,

 

well, on my R2023 AutoCAD vanila there is no such issue - sorry 🤔

0 Likes
Message 11 of 12

martin_leiter
Advocate
Advocate

Hello Moshe,
yes I know. This problem only appeared for the first time in acad 2024. The same problem exists in 2025.
Thank you very much for your help anyway!

0 Likes
Message 12 of 12

martin_leiter
Advocate
Advocate

I found this information. Unfortunately, it doesn't help 🙁 me. https://dwf.blogs.com/beyond_the_paper/2006/10/error_layout_no.html 

0 Likes