multiple layout export to separate CAD files

multiple layout export to separate CAD files

Anonymous
Not applicable
4,699 Views
13 Replies
Message 1 of 14

multiple layout export to separate CAD files

Anonymous
Not applicable

Hi ,

 

I am looking for some help. I am trying to modify this layout export script from ahsattarian3 (see link https://forums.autodesk.com/t5/autocad-forum/export-multiple-layout-tabs-at-one-time-to-another-dwg/...

(prompt "\n Type : LXA ")
(defun c:lxa ()
  (setq layouts (layoutlist))
  (setq layouts (acad_strlsort layouts))
  (setq ad (getvar "dwgprefix"))
  (setq layfol (strcat ad "Layouts"))
  (vl-mkdir layfol)
  (setq f (strcat layfol "\\lxa.scr"))
  (setq ff (open f "w"))
  (write-line "model" ff)
  (foreach layout layouts
    (write-line "layout set" ff)
    (write-line (strcat "\"" layout "\"") ff)
    (setq adname (strcat (chr 34) layfol "\\" layout (chr 34)))
    (write-line "exportlayout" ff)
    (write-line adname ff)
  )
  (write-line "model" ff)
  (close ff)
  (command "script" f)
)

 

 

)

 

Instead of the script saving the the cad file names as their "layout names", I would like to save them as their drawing number (which is a mtext in the paperspace of each layout and in the same coordinates on each sheet/layout) I think I need to do a ssget and window to get the txt string? and I assume it is AD definition that has been used? the coordinates are top right to bottom left in a window. x 775 y 25.34, x 740 y 17.3

 

I cant seem to get it to work at all and im sure a long way off but figured you might know how to do it efficiently. This is what I have below.

 

(defun c:lxa ()
(setq layouts (layoutlist))
(setq layouts (acad_strlsort layouts))
(setq ad (if (ssget "_C"
'(775 25.34 0.0)
'(740 17.3 0.0)
'((0 . "*TEXT"))))
(setq layfol (strcat ad "Layouts"))
(vl-mkdir layfol)
(setq f (strcat layfol "\\lxa.scr"))
(setq ff (open f "w"))
(write-line "model" ff)
(foreach layout layouts
(write-line "layout set" ff)
(write-line layout ff)
(setq adname (strcat (chr 34) layfol "\\" layout (chr 34)))
(write-line "exportlayout" ff)
(write-line adname ff)
)
(write-line "model" ff)
(close ff)
(command "script" f)
)

 

 

 

thankyou!!

0 Likes
Accepted solutions (1)
4,700 Views
13 Replies
Replies (13)
Message 2 of 14

Sea-Haven
Mentor
Mentor

Try this (setq ad (ssget "F" (list '(775 25.34)'(740 17.3)) '((0 . "*TEXT"))))

0 Likes
Message 3 of 14

Anonymous
Not applicable

Keeps returning errors - (the selection set value keeps changing everytime i hit enter)

; error: bad argument type: stringp <Selection set: 5f> 

 

(defun c:lxa ()
(setq layouts (layoutlist))
(setq layouts (acad_strlsort layouts))
(setq ad (ssget "F" (list '(775 25.34)'(740 17.3)) '((0 . "*TEXT"))))
(setq layfol (strcat ad "Layouts"))
(vl-mkdir layfol)
(setq f (strcat layfol "\\lxa.scr"))
(setq ff (open f "w"))
(write-line "model" ff)
(foreach layout layouts
(write-line "layout set" ff)
(write-line (strcat "\"" layout "\"") ff)
(setq adname (strcat (chr 34) layfol "\\" layout (chr 34)))
(write-line "exportlayout" ff)
(write-line adname ff)
)
(write-line "model" ff)
(close ff)
(command "script" f)
)

0 Likes
Message 4 of 14

Sea-Haven
Mentor
Mentor

I think I misinterpreted what your doing your reading a text value somewhere in a layout and using that as part of the export name.

 

So the sequence should be 

get all the layouts

loop through the layouts

look for the text and make the new dwg name

export the layout to a new dwg

end of loop.

 

So your "ad" should be within the foreach loop. There is no need to write a script just export each layout using (command............. .

More use (setvar 'ctab layout) to change to new layouts and then you need to do a pspace to make sure your in paper space. 

 

Rather than me rewrite your code hopefully it makes sense what I am saying you have all the code just need to re-arrange it. Happy to help have a go 1st.

 

When doing something like this think about how you would do it manually I often write down on a piece of paper a shorthand did this then code. 

0 Likes
Message 5 of 14

Anonymous
Not applicable

Yes correct - current script exports to cad and saves the file name as the layout name, where as i want it to save as a string of text in each layout (the drawing number for each layout)

i'll have a go and see what happens - appreciate it

0 Likes
Message 6 of 14

ronjonp
Mentor
Mentor

Maybe try using this as a base. It's more straight forward than writing a script to export tabs to separate drawings.

(defun c:layoutstodwgs (/ ct doc exprt fda lays msg pre)
  ;; https://www.theswamp.org/index.php?topic=19721.msg240359#msg240359
  (vl-load-com)
  (setq	fda   (getvar 'filedia)
	pre   (getstring "\n Enter filename prefix: ")
	exprt (getvar 'expert)
	ct    (getvar 'ctab)
	doc   (vla-get-activedocument (vlax-get-acad-object))
	lays  (vla-get-layouts doc)
	msg   ""
  )
  (setvar 'filedia 0)
  (setvar 'expert 5)
  (setvar 'tilemode 1)
  (command "_ucs" "_w")
  (foreach l (layoutlist)
    (setvar 'ctab l)
    (if	(> (sslength (ssget "_x" (list (cons 410 (getvar 'ctab))))) 1)
      (progn (vla-endundomark doc)
	     (vla-startundomark doc)
	     (vlax-for x lays
	       (and (/= (vla-get-name x) (getvar 'ctab)) (vl-catch-all-apply 'vla-delete (list x)))
	     )
	     (command "_-.wblock" (strcat (getvar 'dwgprefix) pre l) "*")
	     (setq msg (strcat (getvar 'dwgprefix) pre l ".dwg created.\n" msg))
	     (vla-endundomark doc)
	     (command "_u")
      )
      (setq msg (strcat "Tab " l " has nothing on it and skipped.\n" msg))
    )
  )
  (setvar 'filedia fda)
  (setvar 'expert exprt)
  (setvar 'ctab ct)
  (princ msg)
)

 

0 Likes
Message 7 of 14

Sea-Haven
Mentor
Mentor

So to clarify you want layout names to be changed. Ok you get the text value then so

(foreach layout layouts
get name do your thing
(vla-put-name layout newname)

 

0 Likes
Message 8 of 14

Anonymous
Not applicable

Nope - cad file stays the same. no layouts change. Just the exported cad file name to change. (to suit the mtext string that is in the layout)

0 Likes
Message 9 of 14

ronjonp
Mentor
Mentor
Accepted solution

Maybe something as simple as this?

(defun c:foo (/ ad)
  (setvar 'filedia 0)
  (foreach l (layoutlist)
    (setvar 'ctab l)
    (command "_.exportlayout"
	     (strcat (getvar 'dwgprefix)
		     ;; Assumes that your text is visible for the fence selection
		     ;; Your sample drawing has nothing to select at the coordinates listed below
		     (if (setq ad (ssget "_F" (list '(775 25.34) '(740 17.3)) '((0 . "*TEXT"))))
		       (cdr (assoc 1 (entget (ssname ad 0))))
		       l
		     )
		     ".dwg"
	     )
	     ""
    )
  )
  (setvar 'filedia 1)
)

 

0 Likes
Message 10 of 14

maratovich
Advisor
Advisor

lay.png

---------------------------------------------------------------------
Software development
Automatic creation layouts and viewport. Batch printing drawings from model.
www.kdmsoft.net
0 Likes
Message 11 of 14

ronjonp
Mentor
Mentor

@maratovich  Will your program grab text from a certain location on each tab and and use that as the name?

0 Likes
Message 12 of 14

maratovich
Advisor
Advisor

Yes.

Please attach an example of your file.

---------------------------------------------------------------------
Software development
Automatic creation layouts and viewport. Batch printing drawings from model.
www.kdmsoft.net
Message 13 of 14

Anonymous
Not applicable

perfect thankyou so much!!!

0 Likes
Message 14 of 14

Amriya_Exe
Advocate
Advocate
Working nice for my purpose.
0 Likes