Hi,Patrick_35
I had a try. With your code AutoCAD terminated when opening the drawing in which I copied the layout to.
Then I've changed this:
- I've changed the lines a bit (but not much).
- I've made a paperspace active in the current drawing.
After loading the code everything worked as expected. I'm not sure what the real reason was.
In the destroyed drawing the content of the existing layout (of test.dwg) was moved into a new layout and the original layout was empty.
After using the new code in a restartet AutoCAD session it worked perfectly.
Give it a new try with this code and make sure that the active layout of the current drawing is not the modelspace.
(defun ouvrir_dessin_dbx(dwg / dbx doc lan rel)
(and (setq dwg (findfile dwg))
(progn
(vlax-for doc (vla-get-documents (vlax-get-acad-object))
(and (eq (strcase (vla-get-fullname doc)) (strcase dwg))
(setq dbx doc lan T)
)
)
(and (not dbx)
(setq dbx (vlax-create-object (if (< (setq rel (atoi (getvar "ACADVER"))) 16)
"ObjectDBX.AxDbDocument"
(strcat "ObjectDBX.AxDbDocument." (itoa rel))
)
)
)
(vla-open dbx dwg)
)
)
)
(list dbx lan)
)
(defun c:test ()
(setq oDoc (vla-get-activedocument (vlax-get-acad-object))
dbx (ouvrir_dessin_dbx "d:/test.dwg")
cal (vlax-safearray-fill
(vlax-make-safearray vlax-vbObject (cons 0 0))
(list (vla-get-activelayout oDoc))
)
cod (vla-get-layouts (car dbx))
)
(vla-copyobjects oDoc cal cod)
(vla-saveas (car dbx) "d:/test.dwg")
(vlax-release-object (car dbx))
); test
Fred