Author Topic: Separate layouts to individual dwg files.  (Read 27004 times)

0 Members and 1 Guest are viewing this topic.

CADaver

  • Guest
Separate layouts to individual dwg files.
« on: October 31, 2007, 10:27:45 AM »
A client asked, I told him I'd check.   I searched here but no luck.  Is there a tool out there somewhere that will take a multi-layout tabbed file and make individual files with one layout tab each??

(Might as well explode dimensions while you're at it, sheesh!)

Slim©

  • Needs a day job
  • Posts: 6566
  • The Dude Abides...
Re: Separate layouts to individual dwg files.
« Reply #1 on: October 31, 2007, 10:38:40 AM »
I believe that ToolPac from DotSoft has that ability.
I drink beer and I know things....

deegeecees

  • Guest
Re: Separate layouts to individual dwg files.
« Reply #2 on: October 31, 2007, 10:41:50 AM »
Sounds easy enough. Pseudo code:

Get # of layouts to list
Create a copy of dwg file for each layout (length of list)
Delete all but 1 of the layouts for each dwg, iterating through the list

I think Alan can be of more help on this.


LE

  • Guest
Re: Separate layouts to individual dwg files.
« Reply #3 on: October 31, 2007, 10:42:23 AM »
Randy;

Have a look in the lisp section of www.jtbworld.com

Here is a direct link:
http://www.jtbworld.com/lisp/layoutstodwgs.htm

There is one lisp there, that it does that.
« Last Edit: October 31, 2007, 10:49:24 AM by LE »

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Separate layouts to individual dwg files.
« Reply #4 on: October 31, 2007, 11:29:43 AM »
Here is my rewrite of Jimmy's routine. I've had better luck with this finishing the job plus it ignores tabs with nothing on them.

Code: [Select]
(defun c:layoutstodwgs (/ ct doc exprt fda lays msg pre)
  (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)
)
« Last Edit: January 14, 2014, 08:52:24 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Separate layouts to individual dwg files.
« Reply #5 on: October 31, 2007, 11:58:47 AM »
I tried one or two of these routines in the past and the problem was that they exported the objects
that were in paper space but left behind the objects visible in the viewports. So that was not good
for my use. I never pursed it as my need for such a routine was a one time thing.
Maybe Ron's routine will do that?  8-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Separate layouts to individual dwg files.
« Reply #6 on: October 31, 2007, 12:03:16 PM »
I tried one or two of these routines in the past and the problem was that they exported the objects
that were in paper space but left behind the objects visible in the viewports. So that was not good
for my use. I never pursed it as my need for such a routine was a one time thing.
Maybe Ron's routine will do that?  8-)

From my tests it grabbed all that is needed.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Separate layouts to individual dwg files.
« Reply #7 on: October 31, 2007, 12:09:11 PM »
Here is my entry.  With some slight modifications it could be used with ObjectDBX.
Code: [Select]
(defun c:Tabs->Drawings (/ ActDoc MsObjList PsObjList dbxApp oVer FirstPass)

(setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(vlax-for obj (vla-get-ModelSpace ActDoc)
(setq MsObjList (cons obj MsObjList))
)
(vlax-for lo (vla-get-Layouts ActDoc)
(if (/= (vla-get-Name lo) "Model")
(progn
(setq FirstPass T)
(vlax-for obj (vla-get-Block lo)
(if (not FirstPass)
(setq PsObjList (cons obj PsObjList))
(setq FirstPass nil)
)
)
(setq dbxApp
(if (< (atoi (setq oVer (substr (getvar "acadver") 1 2))) 16)
(vla-GetInterfaceObject (vlax-get-acad-object) "ObjectDBX.AxDbDocument")
(vla-GetInterfaceObject (vlax-get-acad-object) (strcat "ObjectDBX.AxDbDocument." oVer))
)
)
(vlax-invoke ActDoc 'CopyObjects MsObjList (vla-get-ModelSpace dbxApp))
(vlax-invoke ActDoc 'CopyObjects PsObjList (vla-get-PaperSpace dbxApp))
(vla-SaveAs dbxApp (strcat (vla-get-Path ActDoc) "\\" (vla-get-Name lo)))
(vlax-release-object dbxApp)
(setq dbxApp nil)
(setq PsObjList nil)
)
)
)
(princ)
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CADaver

  • Guest
Re: Separate layouts to individual dwg files.
« Reply #8 on: November 01, 2007, 09:29:17 AM »
Thanks guys appreciate the help.  I'll pass the info off to the client if thats okay with everyone who offered help?

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Separate layouts to individual dwg files.
« Reply #9 on: November 01, 2007, 09:51:39 AM »
Thanks guys appreciate the help.  I'll pass the info off to the client if thats okay with everyone who offered help?

Not a problem here....except the logic behind it. :-D

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Separate layouts to individual dwg files.
« Reply #10 on: November 01, 2007, 11:02:31 AM »
Thanks guys appreciate the help.  I'll pass the info off to the client if thats okay with everyone who offered help?
I have no problem.  Mine will overwrite though without warning, FYI.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CADaver

  • Guest
Re: Separate layouts to individual dwg files.
« Reply #11 on: November 01, 2007, 11:04:09 AM »
Thanks guys appreciate the help.  I'll pass the info off to the client if thats okay with everyone who offered help?

Not a problem here....except the logic behind it. :-D
I think I'll add code to explode all the dimensions while we're at it.

CADaver

  • Guest
Re: Separate layouts to individual dwg files.
« Reply #12 on: November 01, 2007, 11:05:08 AM »
Thanks guys appreciate the help.  I'll pass the info off to the client if thats okay with everyone who offered help?
I have no problem.  Mine will overwrite though without warning, FYI.
Even better.  I haven't tested any of them, and I will indicate such to the client.  Thanks for the help.

Bob Wahr

  • Guest
Re: Separate layouts to individual dwg files.
« Reply #13 on: November 01, 2007, 11:13:51 AM »
Some other functionality you might want to consider

explode all blocks
for each thingy in the DWuG
get layer of thingy
apply color setting of layer to thingy
apply linetype setting of layer to thingy
change layer to 0


ronjonp

  • Needs a day job
  • Posts: 7529
Re: Separate layouts to individual dwg files.
« Reply #14 on: November 01, 2007, 11:49:27 AM »
We could also move all XREF's to arbitrary base points and change all the scale factors to random numbers.  :-D

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Separate layouts to individual dwg files.
« Reply #15 on: November 01, 2007, 01:01:50 PM »
You guys are just mean. 
Why don't you just explode the Mtext to Dtext while you are at it? Or just explode the Leaders?
Not that I would do a thing like that.  :roll: :roll:
« Last Edit: November 01, 2007, 01:03:07 PM by Krushert »
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

alisafei

  • Guest
Re: Separate layouts to individual dwg files.
« Reply #16 on: January 28, 2009, 06:30:40 PM »
not working for me.
there are nothing changes with original one, just made many layouts separate drawings.
but all the drawings are same, nothing changed at all.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Separate layouts to individual dwg files.
« Reply #17 on: January 28, 2009, 07:09:44 PM »
not working for me.
there are nothing changes with original one, just made many layouts separate drawings.
but all the drawings are same, nothing changed at all.

That is the purpose of the code.  To create separate drawings for each layout.  Do nothing to the original drawing.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

MickD

  • King Gator
  • Posts: 3636
  • (x-in)->[process]->(y-out) ... simples!
Re: Separate layouts to individual dwg files.
« Reply #18 on: January 28, 2009, 08:38:41 PM »
In regards to why you might want to do this I'll offer up an example.
Here our client uses a document management system that HAS to store each drg created as a seperate document so we generally just create seperate drgs as required. It has litereally hundreds of thousands of doc's stored that we need to search on a regular basis, usually by drg number or title.
This tool may be worth a look for us too, thanks.
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

alisafei

  • Guest
Re: Separate layouts to individual dwg files.
« Reply #19 on: January 29, 2009, 07:31:57 AM »
not working for me.
there are nothing changes with original one, just made many layouts separate drawings.
but all the drawings are same, nothing changed at all.

That is the purpose of the code.  To create separate drawings for each layout.  Do nothing to the original drawing.

yes, i know its purpose.
i think it need this type of code because the original file is big one and contains a lot of layouts, so it is time resuming.
i thought the code will make as many drawing as layouts, and the drawing only contains part of drawing (which is shown in layout itself) and put it modelspace.

i am not sure i explained it clear. so let me write a example..
i have an alignment with 10km in  model space with contour drawing, which contains 20 layouts, each one is 500m of alignment.
after using the code, the layout1 drawing only contains 0-500m alignment portion of drawing (not the whole 10km contour drawing), if i do so, i think the layout is useless now, do just those drawing in model space, no more layout needed, and the file size is reduced greately.

bcz, when i use the existing code, the original file size is 2mb, it contains 5 layouts. after saving the 5 layouts separately, each layout file size it still about 1.8mb and it is 1.8*5 = 9mb ..so it will be a problem if your file size is very big.

anyway, thanks for your code.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Separate layouts to individual dwg files.
« Reply #20 on: January 29, 2009, 11:05:26 AM »
One way to make the code help make smaller files, is to have the original file be an xref ( if not already ) of the new sheet files.  That way the new sheet files only have the minimum within them.  This wouldn't be hard to do, I don't think.

To do what you want is kind of hard, not impossible, but hard.  You would have to get the viewport of each layout, and translate that into modelspace.  Then erase all that is outside of it, and then trim all that crosses it, all without user interaction.  There are codes that do those things here, but not all in one code.  You might have to do it yourself, and then others can/will help when you need it; unless someone wants to take on the challenge.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

alisafei

  • Guest
Re: Separate layouts to individual dwg files.
« Reply #21 on: January 29, 2009, 12:17:28 PM »
One way to make the code help make smaller files, is to have the original file be an xref ( if not already ) of the new sheet files.  That way the new sheet files only have the minimum within them.  This wouldn't be hard to do, I don't think.

To do what you want is kind of hard, not impossible, but hard.  You would have to get the viewport of each layout, and translate that into modelspace.  Then erase all that is outside of it, and then trim all that crosses it, all without user interaction.  There are codes that do those things here, but not all in one code.  You might have to do it yourself, and then others can/will help when you need it; unless someone wants to take on the challenge.
yes, i agree with your view.make the original one X-ref then save as layouts, this way the drawing will be smaller size.

the things which i wanted is a little bit diffucult, if it is time taking, just leave it ..
i think it is good for people working with big file always, like me, highway drawings a quite big and sometime diffucult to handle everything in one drawing.
thanks.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Separate layouts to individual dwg files.
« Reply #22 on: January 29, 2009, 12:28:15 PM »
I did one that would copy the xclip.  Maybe it could be changed to set the xclip boundary per the viewport of each new sheet.  I don't know if that will save for occupy space though.  The xref idea might not be too hard to code, and I think it would be a better way to go, that way all the information can still related to each other in a logical way.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

RolandOrzabal

  • Newt
  • Posts: 86
  • "memories fade but the scars still linger"
Re: Separate layouts to individual dwg files.
« Reply #23 on: May 08, 2013, 12:36:41 AM »
Here is my entry.  With some slight modifications it could be used with ObjectDBX.
Code: [Select]
(defun c:Tabs->Drawings (/ ActDoc MsObjList PsObjList dbxApp oVer FirstPass)

(setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(vlax-for obj (vla-get-ModelSpace ActDoc)
(setq MsObjList (cons obj MsObjList))
)
(vlax-for lo (vla-get-Layouts ActDoc)
(if (/= (vla-get-Name lo) "Model")
(progn
(setq FirstPass T)
(vlax-for obj (vla-get-Block lo)
(if (not FirstPass)
(setq PsObjList (cons obj PsObjList))
(setq FirstPass nil)
)
)
(setq dbxApp
(if (< (atoi (setq oVer (substr (getvar "acadver") 1 2))) 16)
(vla-GetInterfaceObject (vlax-get-acad-object) "ObjectDBX.AxDbDocument")
(vla-GetInterfaceObject (vlax-get-acad-object) (strcat "ObjectDBX.AxDbDocument." oVer))
)
)
(vlax-invoke ActDoc 'CopyObjects MsObjList (vla-get-ModelSpace dbxApp))
(vlax-invoke ActDoc 'CopyObjects PsObjList (vla-get-PaperSpace dbxApp))
(vla-SaveAs dbxApp (strcat (vla-get-Path ActDoc) "\\" (vla-get-Name lo)))
(vlax-release-object dbxApp)
(setq dbxApp nil)
(setq PsObjList nil)
)
)
)
(princ)
)

Thanks for this..

however, i noticed that the LTSCALE settings were changed when exported.
« Last Edit: May 08, 2013, 12:51:59 AM by NOD684 »
"memories fade but the scars still linger"

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Separate layouts to individual dwg files.
« Reply #24 on: May 08, 2013, 06:51:12 PM »
You're welcome.

If the LTSCALE is a big then, then I can look into when I get some time, but I do not work in AutoCAD  that much anymore, so I'm not sure when I would have time to look into this.  Let me know though, or maybe someone else knows of a quick fix for it, because off the top of my head I don't know of one.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

miquan

  • Guest
Re: Separate layouts to individual dwg files.
« Reply #25 on: October 28, 2013, 01:34:30 AM »
Dear ronjonp,

I try to using your lisp.
But I get this error" ; error: no function definition: VLAX-GET-ACAD-OBJECT"

Please help me solve this matter.
Thanks,
Miquan

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Separate layouts to individual dwg files.
« Reply #26 on: October 28, 2013, 07:21:53 AM »
See the relevant entry in my Error Message Troubleshooter.

miquan

  • Guest
Re: Separate layouts to individual dwg files.
« Reply #27 on: October 28, 2013, 09:42:04 AM »
Thanks Lee so much for your quick reply.

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Separate layouts to individual dwg files.
« Reply #28 on: October 28, 2013, 10:10:27 AM »
See the relevant entry in my Error Message Troubleshooter.

That list IS AWESOME!!!

Thanks LEE.  :lol: :lol: :lol:

Have to remember that the next time I have something to code.

Did that get linked to Problems and Solutions Links (don't reinvent the wheel ...) Thread? 
If not Could it? 
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Separate layouts to individual dwg files.
« Reply #29 on: October 28, 2013, 10:42:41 AM »
Thanks Lee so much for your quick reply.

You're most welcome miquan -
I figured the link would be more helpful in the long term than simply providing the straight answer  :-)

See the relevant entry in my Error Message Troubleshooter.

That list IS AWESOME!!!

Thanks LEE.  :lol: :lol: :lol:

Have to remember that the next time I have something to code.

Thank you Krushert! - I'm glad you like it  8-)

Quite a lot of information can be gleaned from those short error messages returned by the interpreter, so the troubleshooter helps to point you in the right direction.

Did that get linked to Problems and Solutions Links (don't reinvent the wheel ...) Thread? 
If not Could it?

I don't think it is, but I'm sure CAB could add it to his list, or I could post a link separately in that thread.
(not sure how best to keep the thread organised?)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Separate layouts to individual dwg files.
« Reply #30 on: October 28, 2013, 04:45:58 PM »
It is in my current list but haven't updated the post in some time.


« Last Edit: October 28, 2013, 10:19:58 PM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Separate layouts to individual dwg files.
« Reply #31 on: October 28, 2013, 08:05:58 PM »
It in my current list but haven't updated the post in some time.

Cheers Alan  8-)

miquan

  • Guest
Re: Separate layouts to individual dwg files.
« Reply #32 on: January 14, 2014, 12:58:15 AM »
Dear Lee,

Could you possibly help me to keep only objects within layout frame after separating?

Or Normally I have a block or xref for title frame, you could help me to keep object only in this frame.

Thanks in advance,
Miquan

huan_khu

  • Guest
Re: Separate layouts to individual dwg files.
« Reply #33 on: January 14, 2014, 03:55:29 AM »
Dear Lee,

Could you possibly help me to keep only objects within layout frame after separating?

Or Normally I have a block or xref for title frame, you could help me to keep object only in this frame.

Thanks in advance,
Miquan

I have the same problem with him.

The second issue is on my layout tab, I have many drawings (about 10). Can I separate them as the single drawings? Thank you.

Bhull1985

  • Guest
Re: Separate layouts to individual dwg files.
« Reply #34 on: January 14, 2014, 08:41:16 AM »
Hey Lee, just perusing through the forums and noticed this thread, and the links to your error handler.
Just wanted to offer some suggestions as to making your already incredibly useful error handler, even more useful.
To keep the streamlined aspect of your webpage you could utilize the "spoiler" code, where you have to click on the word "spoiler" in order to reveal the text hidden.
But, within those you could give typical examples of what would cause the error code, and the fix to the typical example.
Sometimes when an inexperienced lisper sees an error spat back at them, and even having checked your webpage to find the description of the error and what's causing it, it can still be difficult to find out which line in specific is causing the error. A spoiler such as this may be really useful to fledglings such as myself and others, though I fear you're probably too busy for such a thing at this moment, I wanted to at least run it by you.
Have a good day!