Autocad Exportlayout Failed to Generate a New Drawing

It appears that Autodesk's discussion group server is mangling code (removing angle braces :roll:), so I'm posting this here in case anyone needs the actual code.

  1. /// ExportLayouts.cs  (c) 2013  Tony Tanzillo

  2. ///

  3. /// AutoCAD.NET API sample that automates

  4. /// the EXPORTLAYOUT command to export all

  5. /// layouts in the current document.

  6. ///

  7. /// Two versions of the command are included.

  8. /// The second version (EXPORTLAYOUTS2) requires

  9. /// a reference to AcExportLayout.dll.

  10. using System ;

  11. using System.Collections ;

  12. using System.Collections.Generic ;

  13. using System.IO ;

  14. using System.Linq ;

  15. using System.Reflection ;

  16. using System.Linq.Expressions ;

  17. using Autodesk.AutoCAD.ApplicationServices ;

  18. using Autodesk.AutoCAD.DatabaseServices ;

  19. using Autodesk.AutoCAD.EditorInput ;

  20. using Autodesk.AutoCAD.Runtime ;

  21. /// Needed with EXPORTLAYOUTS2 command only, and

  22. /// requires a reference to AcExportLayout.dll:

  23. using AcExportLayout = Autodesk. AutoCAD . ExportLayout ;

  24. namespace ExportLayoutsExample

  25. {

  26. public static class ExportLayoutsCommands

  27. {

  28. /// <summary>

  29. /// Automates the EXPORTLAYOUT command to export

  30. /// all paper space layouts to .DWG files.

  31. ///

  32. /// In this example, we export each layout to

  33. /// a drawing file in the same location as the

  34. /// current drawing, wherein each file has the

  35. /// name "<dwgname>_<layoutname>.dwg".

  36. ///

  37. /// This is not a functionally-complete example:

  38. ///

  39. /// No checking is done to see if any of the

  40. /// files already exist, and existing files

  41. /// are overwritten without warning or error.

  42. ///

  43. /// No checking is done to detect if an existing

  44. /// file exists and is in-use by another user, or

  45. /// cannot be overwritten for any other reason.

  46. ///

  47. /// No checking is done to ensure that the user

  48. /// has sufficient rights to write files in the

  49. /// target location.

  50. ///

  51. /// You can and should deal with any or all of

  52. /// the above as per your own requirements.

  53. ///

  54. /// </summary>

  55. [CommandMethod( "EXPORTLAYOUTS" ) ]

  56. public static void ExportLayoutsCommand( )

  57. {

  58. var doc = Application. DocumentManager . MdiActiveDocument ;

  59. var db = doc. Database ;

  60. var editor = doc. Editor ;

  61. try

  62. {

  63. if ( ( short ) Application. GetSystemVariable ( "DWGTITLED" ) == 0 )

  64. {

  65.                editor. WriteMessage (

  66. "\nCommand cannot be used on an unnamed drawing"

  67. ) ;

  68. return ;

  69. }

  70. string format =

  71.                Path. Combine (

  72.                   Path. GetDirectoryName ( doc. Name ),

  73.                   Path. GetFileNameWithoutExtension ( doc. Name ) )

  74. + "_{0}.dwg" ;

  75. string [ ] names = null ;

  76. using ( Transaction tr = doc. TransactionManager . StartTransaction ( ) )

  77. {

  78. // Get the localized name of the model tab:

  79.                BlockTableRecord btr = (BlockTableRecord)

  80.                   SymbolUtilityServices. GetBlockModelSpaceId ( db )

  81. . GetObject ( OpenMode. ForRead ) ;

  82.                Layout layout = (Layout)

  83.                   btr. LayoutId . GetObject ( OpenMode. ForRead ) ;

  84. string model = layout. LayoutName ;

  85. // Open the Layout dictionary:

  86.                IDictionary layouts = (IDictionary)

  87.                   db. LayoutDictionaryId . GetObject ( OpenMode. ForRead ) ;

  88. // Get the names and ids of all paper space layouts into a list:

  89.                names = layouts. Keys . Cast < string > ( )

  90. . Where ( name => name != model ) . ToArray ( ) ;

  91.                tr. Commit ( ) ;

  92. }

  93. int cmdecho = 0 ;

  94. #if DEBUG

  95.             cmdecho = 1 ;

0 Response to "Autocad Exportlayout Failed to Generate a New Drawing"

إرسال تعليق

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel