Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Export Layout to Model LISP

19 REPLIES 19
Reply
Message 1 of 20
WillHBK
8179 Views, 19 Replies

Export Layout to Model LISP

I've searched and searched and cannot find a solution to my problem.

 

I am currently working on a project for a client that includes 6 seperate dwgs each with about 13 layouts in them.  The client wants 78 different dwgs (one for each layout).  However, they want the layout to be transposed into model space rather than paper space.  The layouts have multiple viewports in them so "chspace" is not a practical solution.

 

I know you can right-click on the layout tab and choose "Export Layout to Model...", but I am looking for a way to automate this approach.

 

There are others posts with LISPs that export each layout to a seperate dwg.  However, these LISPs only move each layout into a seperate dwg.  I'm looking to move the layout (title block and all) into a seperate dwg AND into model space.

 

If someone could provide a LISP that could do this, that would be amazing.  I've never done programming in AutoCAD but could learn if I had to.  So my second option would be if someone could layout a programming approach without the coding and I'll take it from there.

 

Thanks!

Tags (3)
19 REPLIES 19
Message 2 of 20
hmsilva
in reply to: WillHBK

Welcome to the Autodesk Community, WillHBK

 

A quick and dirty one...
Give it a try.

(defun c:test ( / BASE LST OLD_DIA)
  (setq	old_dia	(getvar 'FILEDIA)
	base	(strcat (getvar 'DWGPREFIX) (vl-filename-base (getvar 'DWGNAME)))
  )
  (setvar 'FILEDIA 0)
  (setq lst (layoutlist))
  (foreach l lst
    (command "_.ctab"
	     l
	     "exportlayout"
	     (strcat base "-" l)
    )
  )
  (setvar 'FILEDIA old_dia)
  (princ)
)

HTH

Henrique

EESignature

Message 3 of 20
Lineabove
in reply to: WillHBK

EXCELLENT !

 

This is a routine that I never really thought I would use... BUT after trying it.... AWESOME !!!

 

 

Mel

 

Message 4 of 20
hmsilva
in reply to: Lineabove


@Anonymous wrote:

EXCELLENT !

 

This is a routine that I never really thought I would use... BUT after trying it.... AWESOME !!!

 

 

Mel

 


Mel, I'm glad it's useful to you!

 

Henrique

EESignature

Message 5 of 20
WillHBK
in reply to: WillHBK

Thanks for the warm welcome.  I've always found what I've needed on the forums and never actually had to post but I figured it was time to create a profile and join the community.

 

The LISP works well.  Thanks for the help.  It'll definitely save me lots of time.  The only problem is that I get an "unhandled exception" error notice for each sheet when I export.

 

The error reads:

 

"Unhandled exception has occurred in a component in your application.  If you click Continue, the application will ignore this error and attempt to continue.  The given key was not present in the dictionary."

 

Details include:

 

"Application does not support just-in-time (JIT)
debugging. See the end of this message for details.

************** Exception Text **************
System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   at Autodesk.AutoCAD.ExportLayout.CustomObjectConverter.ResetLineTypeId()
   at Autodesk.AutoCAD.ExportLayout.CustomObjectConverter.Convert(Database database)
   at Autodesk.AutoCAD.ExportLayout.Engine.ExportLayout(ObjectId srcLayoutId)
   at Autodesk.AutoCAD.ExportLayoutUI.Commands.ExportLayout()

at Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorker(MethodInfo mi, Object commandObject, Boolean bLispFunction)
   at Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorkerWithExceptionFilter(MethodInfo mi, Object commandObject, Boolean bLispFunction)
   at Autodesk.AutoCAD.Runtime.PerDocumentCommandClass.Invoke(MethodInfo mi, Boolean bLispFunction)
   at Autodesk.AutoCAD.Runtime.CommandClass.CommandThunk.Invoke()


************** Loaded Assemblies **************

 

A bunch of other stuff, then:

 

 

----------------------------------------

************** JIT Debugging **************
Application does not support Windows Forms just-in-time (JIT)
debugging. Contact the application author for more
information.

 

 

Is this a common error for this type of export?  Is there a simple solution?  I've downloaded the service pack already, so it's not that.

 

Thanks for all the help.

 

Will

Message 6 of 20
hmsilva
in reply to: WillHBK

You're welcome, Will

 

Is this a common error for this type of export?

 

I never had it.

If you use the right-click on the layout tab to export, do you receive the same error?

 

Henrique

EESignature

Message 7 of 20
WillHBK
in reply to: hmsilva

I get the same error when right-clicking.  Could it be the number of layouts in my file?  When I run the LISP on a file with only one layout, it works fine and I don't get an error message.  I ran it on a file with two layouts and got the error.

 

Any ideas?

 

Will

Message 8 of 20
hmsilva
in reply to: WillHBK


@WillHBK wrote:

I get the same error when right-clicking.  Could it be the number of layouts in my file?  When I run the LISP on a file with only one layout, it works fine and I don't get an error message.  I ran it on a file with two layouts and got the error.

 

Any ideas?

 

Will


Will,

 

I tested the code with 15 layouts without error.

Sorry, but I have no idea why it happens...

 

Henrique

EESignature

Message 9 of 20
Lineabove
in reply to: hmsilva

I have tried the code with a drawing with about 15 layouts and I do not receive an error.

 

I am unable to assist.

 

Message 10 of 20
niksus
in reply to: WillHBK

I'd just like to say thank you to 

Message 11 of 20
hmsilva
in reply to: niksus


@niksus wrote:

I'd just like to say thank you to 


You're welcome, niksus
Glad it works for you.

 

Thank you for sharing with us your solution for the "Unhandled exception" problem.

 

Henrique

EESignature

Message 12 of 20
fordfamily
in reply to: hmsilva

your .lsp just saved me hours of work. THANK YOU!!!

Message 13 of 20
hmsilva
in reply to: fordfamily

You're welcome, forfamily
Glad I could help

Henrique

EESignature

Message 14 of 20
danglar
in reply to: hmsilva

I have a problem with this lisp then I trying to invoke it on dwg with xrefs. Do you have any solution for this problem?

Message 15 of 20
hmsilva
in reply to: danglar


@apelbaum2014 wrote:

I have a problem with this lisp then I trying to invoke it on dwg with xrefs. Do you have any solution for this problem?


Can you be more specific?

What is the problem?

 

Henrique

EESignature

Message 16 of 20
jagalabilawa
in reply to: WillHBK

Hi.. Thank you for the LISP.. This is one of the best LISP for autocad..

however, is it possible to make it more complete, such as having a Save As Dialog before it starts exporting?

i use 2013 and my client uses 2007, it end up i have to open it again one by one to save as the drawing to 2007 before i can send it...

 

another thing...

I found a way to minimize the "unhandled exception" everytime we export the layout..

It is because the drawing contain Xclip-ed reference or blocks... 

so at the end you may want to Bind the xref, explode the xclips... and redraw the boundary as shown in the layouts..

 

thanks..

 

jagalabilawa 

Message 17 of 20
rvtquestions
in reply to: jagalabilawa

@hmsilva 

@jagalabilawa

@WillHBK

 

Anyone else have an issue when exporting to existing files? It seems to crash and fail when files already exist. I am trying to incorporate the iffindfile function and save if existing, but I am facing some issues. Any help on getting this script to overwrite existing files when exporting? Thanks. 

Message 18 of 20
sacprasanna
in reply to: hmsilva

Thank You very much sir , It works 

 

 

 

Chamara Prasanna
AutoCAD Civil 3D 2015 SP 1
Sri Lanka
Message 19 of 20
namhoang1235
in reply to: hmsilva

it work like a charm, thank you ❤️

Message 20 of 20
roland.r71
in reply to: rvtquestions

I'm a bit late, but here's the solution to that:

 

(defun c:test ( / BASE LST OLD_DIA l layrexp)
  (setq old_dia (getvar 'FILEDIA)
    base (strcat (getvar 'DWGPREFIX) (vl-filename-base (getvar 'DWGNAME)))
  )
  (setvar 'FILEDIA 0)
  (setq lst (layoutlist))
  (foreach l lst

    (setq layrexp (strcat base "-" l))

    (Setvar 'ctab l)
   
(if (findfile (layrexp))

     (command "_exportlayout" layrexp "_y") ; if it exists, answer 'yes' to overwrite
     (command "_exportlayout" layrexp)
    )

  )
  (setvar 'FILEDIA old_dia)
  (princ)
)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost