Esempio n. 1
0
        /// <summary>
        /// Requires a transaction (not an OpenCloseTransaction) to be active when called:
        /// Returns an enumeration of all AttributeDefinitions whose Constant property is
        /// true, and all AttributeReferences attached to the block reference.
        /// </summary>
        public static IEnumerable <DBText> GetAttributes([NotNull] this BlockReference blockRef)
        {
            var tr  = blockRef.GetTransaction();
            var btr = (BlockTableRecord)blockRef.BlockTableRecord.GetObject(OpenMode.ForRead);

            if (blockRef.AttributeCollection != null)
            {
                foreach (ObjectId id in blockRef.AttributeCollection)
                {
                    if (id.IsValidEx())
                    {
                        continue;
                    }
                    yield return((AttributeReference)tr.GetObject(id, OpenMode.ForRead));
                }
            }

            if (btr.HasAttributeDefinitions)
            {
                foreach (var id in btr)
                {
                    if (!id.IsValidEx())
                    {
                        continue;
                    }
                    var attDef = tr.GetObject(id, OpenMode.ForRead) as AttributeDefinition;
                    if (attDef == null)
                    {
                        continue;
                    }
                    if (attDef.Constant)
                    {
                        yield return(attDef);
                    }
                }
            }
        }