TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: CADaver on October 31, 2007, 10:27:45 AM

Title: Separate layouts to individual dwg files.
Post by: CADaver 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!)
Title: Re: Separate layouts to individual dwg files.
Post by: Slim© on October 31, 2007, 10:38:40 AM
I believe that ToolPac (http://dotsoft.com/toolpac.htm) from DotSoft has that ability.
Title: Re: Separate layouts to individual dwg files.
Post by: deegeecees 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.

Title: Re: Separate layouts to individual dwg files.
Post by: LE 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.
Title: Re: Separate layouts to individual dwg files.
Post by: ronjonp 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)
)
Title: Re: Separate layouts to individual dwg files.
Post by: CAB 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-)
Title: Re: Separate layouts to individual dwg files.
Post by: ronjonp 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.
Title: Re: Separate layouts to individual dwg files.
Post by: T.Willey 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)
)
Title: Re: Separate layouts to individual dwg files.
Post by: CADaver 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?
Title: Re: Separate layouts to individual dwg files.
Post by: ronjonp 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
Title: Re: Separate layouts to individual dwg files.
Post by: T.Willey 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.
Title: Re: Separate layouts to individual dwg files.
Post by: CADaver 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.
Title: Re: Separate layouts to individual dwg files.
Post by: CADaver 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.
Title: Re: Separate layouts to individual dwg files.
Post by: Bob Wahr 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

Title: Re: Separate layouts to individual dwg files.
Post by: ronjonp 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
Title: Re: Separate layouts to individual dwg files.
Post by: Krushert 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:
Title: Re: Separate layouts to individual dwg files.
Post by: alisafei 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.
Title: Re: Separate layouts to individual dwg files.
Post by: T.Willey 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.
Title: Re: Separate layouts to individual dwg files.
Post by: MickD 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.
Title: Re: Separate layouts to individual dwg files.
Post by: alisafei 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.
Title: Re: Separate layouts to individual dwg files.
Post by: T.Willey 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.
Title: Re: Separate layouts to individual dwg files.
Post by: alisafei 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.
Title: Re: Separate layouts to individual dwg files.
Post by: T.Willey 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.
Title: Re: Separate layouts to individual dwg files.
Post by: RolandOrzabal 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.
Title: Re: Separate layouts to individual dwg files.
Post by: T.Willey 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.
Title: Re: Separate layouts to individual dwg files.
Post by: miquan 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
Title: Re: Separate layouts to individual dwg files.
Post by: Lee Mac on October 28, 2013, 07:21:53 AM
See the relevant entry in my Error Message Troubleshooter (http://bit.ly/1doLg4h).
Title: Re: Separate layouts to individual dwg files.
Post by: miquan on October 28, 2013, 09:42:04 AM
Thanks Lee so much for your quick reply.
Title: Re: Separate layouts to individual dwg files.
Post by: Krushert on October 28, 2013, 10:10:27 AM
See the relevant entry in my Error Message Troubleshooter (http://bit.ly/1doLg4h).

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? 
Title: Re: Separate layouts to individual dwg files.
Post by: Lee Mac 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 (http://bit.ly/1doLg4h).

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?)
Title: Re: Separate layouts to individual dwg files.
Post by: CAB on October 28, 2013, 04:45:58 PM
It is in my current list but haven't updated the post in some time.


Title: Re: Separate layouts to individual dwg files.
Post by: Lee Mac 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-)
Title: Re: Separate layouts to individual dwg files.
Post by: miquan 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
Title: Re: Separate layouts to individual dwg files.
Post by: huan_khu 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.
Title: Re: Separate layouts to individual dwg files.
Post by: Bhull1985 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!