public static DBDictionary GetGeo7Dict(this AcTransaction trans, string dictName) { DBDictionary NOD = trans.GetNOD(); DBDictionary g7Dict = trans.GetSubDictionary(NOD, "Geo7.Dictionary"); return(trans.GetSubDictionary(g7Dict, dictName)); }
private static Xrecord GetValueRecord(this AcTransaction trans, string valName) { valName = Ac.GetValidName(valName); var valDict = trans.GetGeo7Dict("Values"); if (valDict.Contains(valName)) { var valId = valDict.GetAt(valName); return(trans.GetObject <Xrecord>(valId)); } else { var typedVal = new TypedValue((int)DxfCode.Text, ""); using (var resBuff = new ResultBuffer(typedVal)) { var xRec = new Xrecord(); xRec.Data = resBuff; valDict.SetAt(valName, xRec); trans.AddNewlyCreatedDBObject(xRec, true); return(xRec); } } //ResultBuffer resbuf = new ResultBuffer( new TypedValue((int)DxfCode.Text, "HELLO"), // new TypedValue((int)DxfCode.Int16, 256), // new TypedValue((int)DxfCode.Real, 25.4)); }
public AcAttributeRef(AcBlockRef owner, AttributeReference entity, AcTransaction trans) : base(entity, trans) { _tag = entity.Tag; _invisible = entity.Invisible; Owner = owner; }
public AcBlockRef AddBlockRef(Point3d pos, AcTransaction trans) { //Create the block reference... var blockRef = new BlockReference(pos, this.ObjectId); blockRef.SetDatabaseDefaults(); // Default/Active layer, color, ... trans.AddEntity(blockRef); // Do it before blockRef.AttributeCollection.AppendAttribute(attRef); var attrRefs = new List <AttributeReference>(); foreach (var attrDef in this.Attributes) { // this BlockDef could be initialized throught other (closed) Transaction, the same with this.Attributes var attDefObj = attrDef.GetAcObject(trans); // trans.GetObject<AttributeDefinition>(attrDef.ObjectId); // attrDef.AcObject; var attRef = new AttributeReference(); attRef.SetAttributeFromBlock(attDefObj, blockRef.BlockTransform); attRef.SetDatabaseDefaults(); if (!attDefObj.Constant) { attRef.TextString = attDefObj.TextString; } blockRef.AttributeCollection.AppendAttribute(attRef); trans.AddNewlyCreatedDBObject(attRef, true); attrRefs.Add(attRef); } return(new AcBlockRef(blockRef, trans, attrRefs)); }
/// <summary> /// Gets value from 'Geo7.Dictionary.Values' dictionary. If there is no value for 'name' empty string ("") is returned. /// </summary> public static string GetValue(this AcTransaction trans, string valName) { Xrecord xRec = trans.GetValueRecord(valName); var val = xRec.Data.AsArray()[0]; return(val.Value.ToString()); }
public AcAttributeDef(AcBlockDef owner, AttributeDefinition entity, AcTransaction trans) : base(entity, trans) { _tag = entity.Tag; _invisible = entity.Invisible; this.AttrVisiblePresenter = !_invisible; Owner = owner; }
public static ObjectId AddEntity(this AcTransaction trans, Entity ent) { var entId = trans.ModelSpace.AppendEntity(ent); // Add the reference to ModelSpace trans.AddNewlyCreatedDBObject(ent, true); // Let the transaction know about it return(entId); }
public static LayerTableRecord GetLayer(this AcTransaction trans, ObjectId id) { if (id.ObjectClass.Name != "AcDbLayerTableRecord") { throw new InvalidCastException("Object " + id.ObjectClass.Name + " is not a layer"); } return(trans.GetObject <LayerTableRecord>(id)); }
public IEnumerable <AcBlockRef> GetBlocks(AcTransaction trans) { var blockRefIds = this.GetAcObject(trans).GetBlockReferenceIds(true, true); foreach (ObjectId id in blockRefIds) { yield return(new AcBlockRef(id, trans)); } }
public AcBlockRef(BlockReference entity, AcTransaction trans, IEnumerable <AttributeReference> attributes) : this(entity, trans) { foreach (var attr in attributes) { attrDict.Add(new AcAttributeRef(this, attr, trans)); } InitAttributes(); }
public AcBlockRef(BlockReference entity, AcTransaction trans) : base(entity, trans) { this.Name = entity.Name; this.BlockDef = trans.GetBlockDef(this.Name); this.HasAttributes = this.BlockDef.HasAttributes; _position = entity.Position; _scale = entity.ScaleFactors.X; }
public AcText(T entity, AcTransaction trans) : base(entity, trans) { mPosition = entity.Position; mRotation = entity.Rotation; mTextString = entity.TextString; mHorizontalMode = entity.HorizontalMode; mVerticalMode = entity.VerticalMode; }
public AcCurve(T entity, AcTransaction trans) : base(entity, trans) { Area = entity.Area; Closed = entity.Closed; IsPeriodic = entity.IsPeriodic; _startPoint = entity.StartPoint; _endPoint = entity.EndPoint; }
public AcLine(T entity, AcTransaction trans) : base(entity, trans) { Angle = entity.Angle; Delta = entity.Delta; Length = entity.Length; _normal = entity.Normal; _thickness = entity.Thickness; }
public static DBText AddText(this AcTransaction trans, Point3d pos, string text) { DBText txt = new DBText(); txt.Position = pos; txt.TextString = text; trans.AddEntity(txt); return(txt); }
/// <summary> /// Sets value in 'Geo7.Dictionary.Values' dictionary. /// </summary> public static void SetValue(this AcTransaction trans, string valName, string value) { var typedVal = new TypedValue((int)DxfCode.Text, value); using (var resBuff = new ResultBuffer(typedVal)) { var xRec = trans.GetValueRecord(valName); xRec.Data = resBuff; } }
public static double GetSavedBlockScale(this AcTransaction trans, string blockName) { var scale = trans.GetValue(blockName + ".Scale").ToDouble(); if (scale <= 0) { scale = 1.0; } return(scale); }
public static LayerTableRecord GetLayer(this AcTransaction trans, string name) { if (!trans.LayerTable.Has(name)) { throw new KeyNotFoundException("Layer '" + name + "' does not exists"); } var layerId = trans.LayerTable[name]; return(trans.GetObject <LayerTableRecord>(layerId)); }
public AcBlockRef(ObjectId id, AcTransaction trans) : this(trans.GetObject <BlockReference>(id), trans) { var entity = this.AcObject; foreach (ObjectId attrId in entity.AttributeCollection) { var attr = trans.GetObject <AttributeReference>(attrId); attrDict.Add(new AcAttributeRef(this, attr, trans)); } InitAttributes(); }
public AcBlockRef FirstBlock(AcTransaction trans) { var blockRefIds = this.GetAcObject(trans).GetBlockReferenceIds(true, true); if (blockRefIds.Count > 0) { return(new AcBlockRef(blockRefIds[0], trans)); } else { return(null); } }
public AcPolyline(T entity, AcTransaction trans) : base(entity, trans) { IsOnlyLines = entity.IsOnlyLines; Length = entity.Length; NumberOfVertices = entity.NumberOfVertices; _constantWidth = entity.ConstantWidth; _elevation = entity.Elevation; _normal = entity.Normal; _plinegen = entity.Plinegen; _thickness = entity.Thickness; }
public static BlockTableRecord GetBlockTableRecord(this AcTransaction trans, string blockName) { var blockTable = trans.BlockTable; if (!blockTable.Has(blockName)) { throw new KeyNotFoundException(blockTable.GetType().Name + " does not contain element '" + blockName + "'"); } var blockId = blockTable[blockName]; var res = trans.GetObject <BlockTableRecord>(blockId); return(res); }
public static DBDictionary GetSubDictionary(this AcTransaction trans, DBDictionary parentDict, string subDictKey) { if (parentDict.Contains(subDictKey)) { var subDictId = parentDict.GetAt(subDictKey); return(trans.GetObject <DBDictionary>(subDictId)); } else { var newDict = new DBDictionary(); var res = parentDict.SetAt(subDictKey, newDict); trans.AddNewlyCreatedDBObject(newDict, true); return(newDict); } }
public static IEnumerable <T> GetAllEntities <T>(this AcTransaction trans, string ObjectClassName) where T : Entity { List <T> res = new List <T>(); var modelSpace = trans.ModelSpace; foreach (var entId in modelSpace) { if (entId.ObjectClass.Name.ToLower() == ObjectClassName.ToLower()) // AcDbMText,AcDbText,AcDbPolyline { var ent = trans.GetObject <T>(entId); res.Add(ent); } } return(res); }
public static ObjectId CreateLayer(this AcTransaction trans, string name) { if (trans.LayerTable.Has(name)) { return(trans.LayerTable[name]); } using (var ltr = new LayerTableRecord()) { ltr.Name = name; //ltr.Color = Color.FromColorIndex(ColorMethod.ByAci, 2); var res = trans.LayerTable.Add(ltr); trans.AddNewlyCreatedDBObject(ltr, true); return(res); } }
public AcBlockDef(BlockTableRecord obj, AcTransaction trans) : base(obj, trans) { this.Name = obj.Name; this.HasAttributes = obj.HasAttributeDefinitions; this.IsAnonymous = obj.IsAnonymous; this.IsLayout = obj.IsLayout; var blockRefIds = obj.GetBlockReferenceIds(true, true); this.BlockCount = blockRefIds.Count; this.HasReferences = blockRefIds.Count > 0; InitAttributeInfos(trans); }
public static bool IsReadOnly(this AcTransaction trans, Entity ent) { if (!ent.IsWriteEnabled) { return(false); } var layer = trans.GetLayer(ent.LayerId); if (layer.IsFrozen) { return(true); } return(false); }
public static bool IsDisplayed(this AcTransaction trans, Entity ent) { if (!ent.Visible) { return(false); } var layer = trans.GetLayer(ent.LayerId); if (layer.IsHidden || layer.IsFrozen || layer.IsOff) { return(false); } return(true); }
public static IEnumerable <T> GetAllEntities <T>(this AcTransaction trans) where T : Entity { List <T> res = new List <T>(); var modelSpace = trans.ModelSpace; foreach (var entId in modelSpace) { var ent = trans.GetObject <DBObject>(entId); if (ent is T) { res.Add(ent as T); } else { ent.Dispose(); } } return(res); }
private void InitAttributeInfos(AcTransaction trans) { string firstAttr = null; foreach (ObjectId id in this.AcObject) { var blockSubEntity = trans.GetObject <DBObject>(id); var blockAttrDef = blockSubEntity as AttributeDefinition; if ((blockAttrDef != null) && !string.IsNullOrEmpty(blockAttrDef.Tag)) { if (attrDict.Find(blockAttrDef.Tag) != null) { AppServices.Log.Add(this.GetType().Name + "." + nameof(InitAttributeInfos) + "() Warning: "); AppServices.Log.Add(" Block " + this.Name + "." + blockAttrDef.Tag + " attribute already exists"); //Ac.WriteLn("Geo7 warning: Block " + this.Name + "." + blockAttrDef.Tag + " attribute already exists"); } else { var attr = new AcAttributeDef(this, blockAttrDef, trans); attrDict.Add(attr); if (firstAttr == null) { firstAttr = attr.Tag; } } } else { blockSubEntity.Dispose(); } } this.IdAttribute = attrDict.FindFirstKey(Ac.IdAttributeTags); if (this.IdAttribute == null) { this.IdAttribute = firstAttr; } this.HeightAttribute = attrDict.FindFirstKey(Ac.HeightAttributeTags); this.CodeAttribute = attrDict.FindFirstKey(Ac.CodeAttributeTags); }