コード例 #1
0
ファイル: AcTransaction.cs プロジェクト: 15831944/Geo7
        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));
        }
コード例 #2
0
ファイル: AcTransaction.cs プロジェクト: 15831944/Geo7
        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));
        }
コード例 #3
0
ファイル: AcAttribute.cs プロジェクト: 15831944/Geo7
 public AcAttributeRef(AcBlockRef owner, AttributeReference entity, AcTransaction trans)
     : base(entity, trans)
 {
     _tag       = entity.Tag;
     _invisible = entity.Invisible;
     Owner      = owner;
 }
コード例 #4
0
        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));
        }
コード例 #5
0
ファイル: AcTransaction.cs プロジェクト: 15831944/Geo7
        /// <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());
        }
コード例 #6
0
ファイル: AcAttribute.cs プロジェクト: 15831944/Geo7
 public AcAttributeDef(AcBlockDef owner, AttributeDefinition entity, AcTransaction trans)
     : base(entity, trans)
 {
     _tag       = entity.Tag;
     _invisible = entity.Invisible;
     this.AttrVisiblePresenter = !_invisible;
     Owner = owner;
 }
コード例 #7
0
ファイル: AcTransaction.cs プロジェクト: 15831944/Geo7
        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);
        }
コード例 #8
0
ファイル: AcTransaction.cs プロジェクト: 15831944/Geo7
 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));
 }
コード例 #9
0
        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));
            }
        }
コード例 #10
0
 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();
 }
コード例 #11
0
 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;
 }
コード例 #12
0
ファイル: AcText.cs プロジェクト: 15831944/Geo7
 public AcText(T entity, AcTransaction trans)
     : base(entity, trans)
 {
     mPosition       = entity.Position;
     mRotation       = entity.Rotation;
     mTextString     = entity.TextString;
     mHorizontalMode = entity.HorizontalMode;
     mVerticalMode   = entity.VerticalMode;
 }
コード例 #13
0
ファイル: AcCurve.cs プロジェクト: 15831944/Geo7
 public AcCurve(T entity, AcTransaction trans)
     : base(entity, trans)
 {
     Area        = entity.Area;
     Closed      = entity.Closed;
     IsPeriodic  = entity.IsPeriodic;
     _startPoint = entity.StartPoint;
     _endPoint   = entity.EndPoint;
 }
コード例 #14
0
ファイル: AcLine.cs プロジェクト: 15831944/Geo7
        public AcLine(T entity, AcTransaction trans)
            : base(entity, trans)
        {
            Angle  = entity.Angle;
            Delta  = entity.Delta;
            Length = entity.Length;

            _normal    = entity.Normal;
            _thickness = entity.Thickness;
        }
コード例 #15
0
ファイル: AcTransaction.cs プロジェクト: 15831944/Geo7
        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);
        }
コード例 #16
0
ファイル: AcTransaction.cs プロジェクト: 15831944/Geo7
        /// <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;
            }
        }
コード例 #17
0
ファイル: AcTransaction.cs プロジェクト: 15831944/Geo7
        public static double GetSavedBlockScale(this AcTransaction trans, string blockName)
        {
            var scale = trans.GetValue(blockName + ".Scale").ToDouble();

            if (scale <= 0)
            {
                scale = 1.0;
            }
            return(scale);
        }
コード例 #18
0
ファイル: AcTransaction.cs プロジェクト: 15831944/Geo7
        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));
        }
コード例 #19
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();
        }
コード例 #20
0
        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);
            }
        }
コード例 #21
0
ファイル: AcPolyline.cs プロジェクト: 15831944/Geo7
        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;
        }
コード例 #22
0
ファイル: AcTransaction.cs プロジェクト: 15831944/Geo7
        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);
        }
コード例 #23
0
ファイル: AcTransaction.cs プロジェクト: 15831944/Geo7
 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);
     }
 }
コード例 #24
0
ファイル: AcTransaction.cs プロジェクト: 15831944/Geo7
        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);
        }
コード例 #25
0
ファイル: AcTransaction.cs プロジェクト: 15831944/Geo7
        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);
            }
        }
コード例 #26
0
        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);
        }
コード例 #27
0
ファイル: AcTransaction.cs プロジェクト: 15831944/Geo7
        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);
        }
コード例 #28
0
ファイル: AcTransaction.cs プロジェクト: 15831944/Geo7
        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);
        }
コード例 #29
0
ファイル: AcTransaction.cs プロジェクト: 15831944/Geo7
        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);
        }
コード例 #30
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);
        }