Autocad Exportlayout Failed to Generate a New Drawing
It appears that Autodesk's discussion group server is mangling code (removing angle braces ), so I'm posting this here in case anyone needs the actual code.
-
/// ExportLayouts.cs (c) 2013 Tony Tanzillo
-
///
-
/// AutoCAD.NET API sample that automates
-
/// the EXPORTLAYOUT command to export all
-
/// layouts in the current document.
-
///
-
/// Two versions of the command are included.
-
/// The second version (EXPORTLAYOUTS2) requires
-
/// a reference to AcExportLayout.dll.
-
using System ;
-
using System.Collections ;
-
using System.Collections.Generic ;
-
using System.IO ;
-
using System.Linq ;
-
using System.Reflection ;
-
using System.Linq.Expressions ;
-
using Autodesk.AutoCAD.ApplicationServices ;
-
using Autodesk.AutoCAD.DatabaseServices ;
-
using Autodesk.AutoCAD.EditorInput ;
-
using Autodesk.AutoCAD.Runtime ;
-
/// Needed with EXPORTLAYOUTS2 command only, and
-
/// requires a reference to AcExportLayout.dll:
-
using AcExportLayout = Autodesk. AutoCAD . ExportLayout ;
-
namespace ExportLayoutsExample
-
{
-
public static class ExportLayoutsCommands
-
{
-
/// <summary>
-
/// Automates the EXPORTLAYOUT command to export
-
/// all paper space layouts to .DWG files.
-
///
-
/// In this example, we export each layout to
-
/// a drawing file in the same location as the
-
/// current drawing, wherein each file has the
-
/// name "<dwgname>_<layoutname>.dwg".
-
///
-
/// This is not a functionally-complete example:
-
///
-
/// No checking is done to see if any of the
-
/// files already exist, and existing files
-
/// are overwritten without warning or error.
-
///
-
/// No checking is done to detect if an existing
-
/// file exists and is in-use by another user, or
-
/// cannot be overwritten for any other reason.
-
///
-
/// No checking is done to ensure that the user
-
/// has sufficient rights to write files in the
-
/// target location.
-
///
-
/// You can and should deal with any or all of
-
/// the above as per your own requirements.
-
///
-
/// </summary>
-
[CommandMethod( "EXPORTLAYOUTS" ) ]
-
public static void ExportLayoutsCommand( )
-
{
-
var doc = Application. DocumentManager . MdiActiveDocument ;
-
var db = doc. Database ;
-
var editor = doc. Editor ;
-
try
-
{
-
if ( ( short ) Application. GetSystemVariable ( "DWGTITLED" ) == 0 )
-
{
-
editor. WriteMessage (
-
"\nCommand cannot be used on an unnamed drawing"
-
) ;
-
return ;
-
}
-
string format =
-
Path. Combine (
-
Path. GetDirectoryName ( doc. Name ),
-
Path. GetFileNameWithoutExtension ( doc. Name ) )
-
+ "_{0}.dwg" ;
-
string [ ] names = null ;
-
using ( Transaction tr = doc. TransactionManager . StartTransaction ( ) )
-
{
-
// Get the localized name of the model tab:
-
BlockTableRecord btr = (BlockTableRecord)
-
SymbolUtilityServices. GetBlockModelSpaceId ( db )
-
. GetObject ( OpenMode. ForRead ) ;
-
Layout layout = (Layout)
-
btr. LayoutId . GetObject ( OpenMode. ForRead ) ;
-
string model = layout. LayoutName ;
-
// Open the Layout dictionary:
-
IDictionary layouts = (IDictionary)
-
db. LayoutDictionaryId . GetObject ( OpenMode. ForRead ) ;
-
// Get the names and ids of all paper space layouts into a list:
-
names = layouts. Keys . Cast < string > ( )
-
. Where ( name => name != model ) . ToArray ( ) ;
-
tr. Commit ( ) ;
-
}
-
int cmdecho = 0 ;
-
#if DEBUG
-
cmdecho = 1 ;
-
0 Response to "Autocad Exportlayout Failed to Generate a New Drawing"
إرسال تعليق