/// <summary> /// Provides read only access to the drawing database in the given file. /// </summary> /// <param name="fileName">The name of the drawing database to open.</param> /// <param name="options">Options for opening the database.</param> /// <exception cref="System.ArgumentNullException">Thrown when parameter <i>fileName</i> is null.</exception> /// <exception cref="System.IO.FileNotFoundException">Thrown when the file cannot be found.</exception> /// <exception cref="System.Exception">Thrown when opening the darwing database throws an exception.</exception> /// <returns>The AcadDatabase instance.</returns> public static AcadDatabase OpenReadOnly(string fileName, OpenReadOnlyOptions options) { Require.StringNotEmpty(fileName, nameof(fileName)); Require.FileExists(fileName, nameof(fileName)); return(OpenInternal(fileName, options.Password, options.KeepDatabaseOpen)); }
/// <summary> /// Provides read only access to the drawing database in the given file. /// </summary> /// <param name="fileName">The name of the drawing database to open.</param> /// <exception cref="System.ArgumentNullException">Thrown when parameter <i>fileName</i> is null.</exception> /// <exception cref="System.IO.FileNotFoundException">Thrown when the file cannot be found.</exception> /// <exception cref="System.Exception">Thrown when opening the darwing database throws an exception.</exception> /// <returns>The AcadDatabase instance.</returns> public static AcadDatabase OpenReadOnly(string fileName) { Require.StringNotEmpty(fileName, nameof(fileName)); Require.FileExists(fileName, nameof(fileName)); return(OpenInternal(fileName, null, false)); }
/// <summary> /// Provides access to the drawing database in the given file. /// </summary> /// <param name="fileName">The name of the drawing database to open.</param> /// <param name="openMode">The mode in which the drawing database should be opened.</param> /// <param name="password">The password for the darwing database.</param> /// <param name="keepOpen">True, if the database should be kept open after it has been used. False, if the database should be closed.</param> /// <exception cref="System.ArgumentNullException">Thrown when parameter <i>fileName</i> is null.</exception> /// <exception cref="System.IO.FileNotFoundException">Thrown when the file cannot be found.</exception> /// <exception cref="System.Exception">Thrown when opening the darwing database throws an exception.</exception> /// <returns>The AcadDatabase instance.</returns> public static AcadDatabase Open(string fileName, DwgOpenMode openMode, string password, bool keepOpen) { Require.StringNotEmpty(fileName, nameof(fileName)); Require.FileExists(fileName, nameof(fileName)); return(OpenInternal(fileName, openMode, password, keepOpen)); }
/// <summary> /// Provides read/write access to the drawing database in the given file. /// </summary> /// <param name="fileName">The name of the drawing database to open.</param> /// <param name="options">Options for opening and closing the database.</param> /// <exception cref="System.ArgumentNullException">Thrown when parameter <i>fileName</i> is null.</exception> /// <exception cref="System.IO.FileNotFoundException">Thrown when the file cannot be found.</exception> /// <exception cref="System.Exception">Thrown when opening the darwing database throws an exception.</exception> /// <returns>The AcadDatabase instance.</returns> public static AcadDatabase OpenForEdit(string fileName, OpenForEditOptions options) { Require.StringNotEmpty(fileName, nameof(fileName)); Require.FileExists(fileName, nameof(fileName)); Database database = GetDatabase(fileName, false, options.Password); var outFileName = options.SaveAsFileName ?? fileName; return(new AcadDatabase(database, options.KeepDatabaseOpen, true, outFileName, options.DwgVersion)); }
/// <summary> /// Attaches the XRef at the given file location. /// </summary> /// <param name="fileName">The file name of the XRef.</param> /// <param name="blockName">The XRef's block name.</param> /// <returns>A new instance of XRef.</returns> /// <exception cref="System.ArgumentNullException">Thrown when parameters <i>file name</i> or <i>block name</i> is null.</exception> public XRef Attach(string fileName, string blockName) { Require.ParameterNotNull(fileName, nameof(fileName)); Require.FileExists(fileName, nameof(fileName)); Require.ParameterNotNull(blockName, nameof(blockName)); Require.IsValidSymbolName(blockName, nameof(blockName)); Require.NameDoesNotExists <XRef>(xRefBlockContainer.Contains(blockName), blockName); return(AttachInternal(fileName, blockName)); }
/// <summary> /// Provides read/write access to the drawing database in the given file. /// </summary> /// <param name="fileName">The name of the drawing database to open.</param> /// <exception cref="System.ArgumentNullException">Thrown when parameter <i>fileName</i> is null.</exception> /// <exception cref="System.IO.FileNotFoundException">Thrown when the file cannot be found.</exception> /// <exception cref="System.Exception">Thrown when opening the darwing database throws an exception.</exception> /// <returns>The AcadDatabase instance.</returns> public static AcadDatabase OpenForEdit(string fileName) { Require.StringNotEmpty(fileName, nameof(fileName)); Require.FileExists(fileName, nameof(fileName)); return(OpenForEdit(fileName, new OpenForEditOptions() { SaveAsFileName = fileName, KeepDatabaseOpen = false, DwgVersion = SaveAsDwgVersion.DontChange, })); }
/// <summary> /// Attaches the XRef at the given file location. /// </summary> /// <param name="fileName">The file name of the XRef.</param> /// <returns>A new instance of XRef.</returns> /// <exception cref="System.ArgumentNullException">Thrown when parameter <i>fileName</i> is null.</exception> public XRef Attach(string fileName) { Require.ParameterNotNull(fileName, nameof(fileName)); Require.FileExists(fileName, nameof(fileName)); var baseName = System.IO.Path.GetFileNameWithoutExtension(fileName); Require.IsValidSymbolName(baseName, nameof(fileName)); return(AttachInternal(fileName, GetBlockName(baseName))); }
/// <summary> /// Create a new block and imports all model space entities from the given drawing file to it. /// </summary> /// <param name="newBlockName">The name of the new BlockTableRecord.</param> /// <param name="fileName">The name of the drawing file that should be imported.</param> /// <returns>A new instance of BlockTableRecord.</returns> /// <exception cref="System.ArgumentNullException">Thrown when parameters <i>newBlockName</i> or <i>fileName</i> is null.</exception> public BlockTableRecord Import(string newBlockName, string fileName) { Require.ParameterNotNull(newBlockName, nameof(newBlockName)); Require.NameDoesNotExists <BlockTableRecord>(Contains(newBlockName), newBlockName); Require.ParameterNotNull(fileName, nameof(fileName)); Require.FileExists(fileName, nameof(fileName)); var blockId = ObjectId.Null; using (var db = AcadDatabase.OpenReadOnly(fileName)) { blockId = database.Insert(newBlockName, db.Database, true); } return((BlockTableRecord)transaction.GetObject(blockId, OpenMode.ForRead)); }