TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Patrick_35 on December 22, 2009, 05:48:47 AM

Title: Export Layout
Post by: Patrick_35 on December 22, 2009, 05:48:47 AM
Hi

I want to export a layout in a file

For example
Code: [Select]
  (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)
  )

  (setq dbx (ouvrir_dessin_dbx "c:/test/fichier_test.dwg")
cal (vlax-safearray-fill
      (vlax-make-safearray vlax-vbObject (cons 0 0))
      (list (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
    )
cod (vla-get-layouts (car dbx))
  )

I do not understand why a
Code: [Select]
(vla-copyobjects (vla-get-activedocument (vlax-get-acad-object)) cal cod)does not work the first time and if I redo a
Code: [Select]
(vla-copyobjects (vla-get-activedocument (vlax-get-acad-object)) cal cod)it works but the drawing is Recoverable

@+
Title: Re: Export Layout
Post by: Fred Tomke on December 22, 2009, 06:50:04 AM
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:


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.

Code: [Select]
(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
Title: Re: Export Layout
Post by: Patrick_35 on December 22, 2009, 07:25:33 AM
Thanks for your reply

The simplest is that I give the entire lisp

I'd like to avoid using the vl-catch-all-error-p
Code: [Select]
(if (vl-catch-all-error-p (vl-catch-all-apply 'vla-copyobjects (list doc cal cod)))
  (vla-copyobjects doc cal cod)
)

@+
Title: Re: Export Layout
Post by: CAB on December 22, 2009, 08:57:35 AM
Have you tried this one by Tim?
http://www.theswamp.org/index.php?topic=19721.msg240368#msg240368
Title: Re: Export Layout
Post by: Patrick_35 on December 22, 2009, 09:42:50 AM
Have you tried this one by Tim?
http://www.theswamp.org/index.php?topic=19721.msg240368#msg240368

Thank you very much cab  :-)
I resolve my problem with the lisp of T.Willey

You are kings

@+
Title: Re: Export Layout
Post by: CAB on December 22, 2009, 09:54:47 AM
You're welcome. Tim is a good guy to have around. 8-)