/// <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) { if (fileName == null) { throw Error.ArgumentNull("fileName"); } if (!System.IO.File.Exists(fileName)) { throw Error.FileNotFound(fileName); } if (blockName == null) { throw Error.ArgumentNull("blockName"); } if (!Helpers.IsNameValid(blockName)) { throw Error.InvalidName(blockName); } if (xRefBlockContainer.Contains(blockName)) { throw Error.ObjectExists <XRef>(blockName); } return(AttachInternal(fileName, blockName)); }
public void AddRange(IEnumerable <TableStyle> items) { if (items == null) { throw Error.ArgumentNull("items"); } foreach (var item in items) { if (item == null) { throw Error.ArgumentNull("item"); } if (!Helpers.IsNameValid(item.Name)) { throw Error.InvalidName(item.Name); } if (Contains(item.Name)) { throw Error.ObjectExists <TableStyle>(item.Name); } } try { AddRangeInternal(items, items.Select(i => i.Name)); } catch (Exception e) { throw Error.AutoCadException(e); } }
public Group Create(string name, IEnumerable <Entity> entities) { if (name == null) { throw Error.ArgumentNull("name"); } if (!Helpers.IsNameValid(name)) { throw Error.InvalidName(name); } if (Contains(name)) { throw Error.ObjectExists <Group>(name); } try { var group = CreateInternal(name); if (entities.Any()) { group.Append(new ObjectIdCollection(entities.Select(e => e.ObjectId) .ToArray())); } return(group); } catch (Exception e) { throw Error.AutoCadException(e); } }
public PlotSettings Create(string name, bool modelType) { if (name == null) { throw Error.ArgumentNull("name"); } if (!Helpers.IsNameValid(name)) { throw Error.InvalidName(name); } if (Contains(name)) { throw Error.ObjectExists <PlotSettings>(name); } this.modelType = modelType; try { return(CreateInternal(name)); } catch (Exception e) { throw Error.AutoCadException(e); } }
public void AddRange(IEnumerable <T> items) { if (items == null) { throw Error.ArgumentNull("items"); } foreach (var item in items) { if (item == null) { throw Error.ArgumentNull("item"); } if (!Helpers.IsNameValid(item.Name)) { throw Error.InvalidName(item.Name); } if (Contains(item.Name)) { throw Error.ObjectExists <T>(item.Name); } } AddRangeInternal(items, items.Select(i => i.Name)); }
public IEnumerable <T> Create(IEnumerable <string> names) { if (names == null) { throw Error.ArgumentNull("names"); } var invalidName = names.FirstOrDefault(n => !Helpers.IsNameValid(n)); if (invalidName != null) { throw Error.InvalidName(invalidName); } var existingName = names.FirstOrDefault(n => Contains(n)); if (existingName != null) { throw Error.ObjectExists <T>(existingName); } try { return(CreateInternal(names)); } catch (Exception e) { throw Error.AutoCadException(e); } }
/// <summary> /// Creates a new LayerTableRecord and adds the given Entites to it. /// </summary> /// <param name="name">The name of the new LayerTableRecord.</param> /// <param name="entities">The Entities that should be added to the new LayerTableRecord.</param> /// <returns>A new instance of LayerTableRecord.</returns> /// <exception cref="System.ArgumentNullException">Thrown when parameters <i>name</i> or <i>entities</i> is null.</exception> public LayerTableRecord Create(string name, IEnumerable <Entity> entities) { if (name == null) { throw Error.ArgumentNull("name"); } if (!Helpers.IsNameValid(name)) { throw Error.InvalidName(name); } if (Contains(name)) { throw Error.ObjectExists <BlockTableRecord>(name); } if (entities.Any(e => e == null)) { throw Error.ElementNull("entities"); } try { var layer = CreateInternal(name); entities.UpgradeOpen() .ForEach(e => e.LayerId = layer.ObjectId); return(layer); } catch (Exception e) { throw Error.AutoCadException(e); } }
public void Add(T item) { if (item == null) { throw Error.ArgumentNull("item"); } if (!Helpers.IsNameValid(item.Name)) { throw Error.InvalidName(item.Name); } AddRangeInternal(new[] { item }, new[] { item.Name }); }
/// <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) { if (fileName == null) { throw Error.ArgumentNull("fileName"); } if (!System.IO.File.Exists(fileName)) { throw Error.FileNotFound(fileName); } var baseName = System.IO.Path.GetFileNameWithoutExtension(fileName); if (!Helpers.IsNameValid(baseName)) { throw Error.InvalidName(baseName); } return(AttachInternal(fileName, GetBlockName(baseName))); }
public T Create(string name) { if (name == null) { throw Error.ArgumentNull("name"); } if (!Helpers.IsNameValid(name)) { throw Error.InvalidName(name); } try { return(CreateInternal(name)); } catch (Exception e) { throw Error.AutoCadException(e); } }
/// <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) { if (newBlockName == null) { throw Error.ArgumentNull("newBlockName"); } if (!Helpers.IsNameValid(newBlockName)) { throw Error.InvalidName(newBlockName); } if (Contains(newBlockName)) { throw Error.ObjectExists <BlockTableRecord>(newBlockName); } if (fileName == null) { throw Error.ArgumentNull("fileName"); } if (!System.IO.File.Exists(fileName)) { throw Error.FileNotFound(fileName); } try { var blockId = ObjectId.Null; using (var db = AcadDatabase.Open(fileName, DwgOpenMode.ReadOnly)) { blockId = database.Insert(newBlockName, db.Database, true); } return((BlockTableRecord)transaction.GetObject(blockId, OpenMode.ForRead)); } catch (Exception e) { throw Error.AutoCadException(e); } }
/// <summary> /// Creates a new BlockTableRecord and adds the given Entites to it. /// </summary> /// <param name="name">The name of the new BlockTableRecord.</param> /// <param name="entities">The Entities that should be added to the BlockTableRecord.</param> /// <returns>A new instance of BlockTableRecord.</returns> /// <exception cref="System.ArgumentNullException">Thrown when parameters <i>name</i> or <i>entities</i> is null.</exception> public BlockTableRecord Create(string name, IEnumerable <Entity> entities) { if (name == null) { throw Error.ArgumentNull("name"); } if (!Helpers.IsNameValid(name)) { throw Error.InvalidName(name); } if (Contains(name)) { throw Error.ObjectExists <BlockTableRecord>(name); } if (entities.Any(e => e == null)) { throw Error.ElementNull("entities"); } var alreadyInBlock = entities.FirstOrDefault(e => !e.ObjectId.IsNull); if (alreadyInBlock != null) { throw Error.EntityBelongsToBlock(alreadyInBlock.ObjectId); } try { var block = CreateInternal(name); entities.UpgradeOpen() .ForEach(e => block.AppendEntity(e)); return(block); } catch (Exception e) { throw Error.AutoCadException(e); } }
public void Add(TableStyle item) { if (item == null) { throw Error.ArgumentNull("item"); } if (!Helpers.IsNameValid(item.Name)) { throw Error.InvalidName(item.Name); } if (Contains(item.Name)) { throw Error.ObjectExists <TableStyle>(item.Name); } try { AddRangeInternal(new[] { item }, new[] { item.Name }); } catch (Exception e) { throw Error.AutoCadException(e); } }
public TableStyle Create(string name) { if (name == null) { throw Error.ArgumentNull("name"); } if (!Helpers.IsNameValid(name)) { throw Error.InvalidName(name); } if (Contains(name)) { throw Error.ObjectExists <TableStyle>(name); } try { return(CreateInternal(name)); } catch (Exception e) { throw Error.AutoCadException(e); } }