Esempio n. 1
0
        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();
        }
Esempio n. 2
0
        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));
        }
Esempio n. 3
0
 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));
 }
Esempio n. 4
0
        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));
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
 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);
     }
 }
Esempio n. 8
0
        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);
        }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
        public static void ChangeColor(this AcTransaction trans, ObjectId entId, int color)
        {
            Entity ent = trans.GetObject <Entity>(entId);

            ent.ColorIndex = color;
        }
Esempio n. 11
0
 public static DBDictionary GetNOD(this AcTransaction trans)
 {
     return(trans.GetObject <DBDictionary>(Ac.Db.NamedObjectsDictionaryId));
 }
Esempio n. 12
0
 public static DrawOrderTable GetDrawOrderTable(this AcTransaction trans, BlockTableRecord blockRec)
 {
     return(trans.GetObject <DrawOrderTable>(blockRec.DrawOrderTableId));
 }
Esempio n. 13
0
 public static T GetObject <T>(this AcTransaction trans, ObjectId id) where T : DBObject
 {
     return((T)trans.GetObject(id));
 }