/// <summary> /// Utility method to set block attributes /// </summary> /// <param name="acBlkRef"></param> /// <param name="blkRecId"></param> /// <param name="acTrans"></param> public static void AppendAttributes(this BlockReference acBlkRef, BlockTableRecord acBlkTblRec, Transaction acTrans) { // Verify block table record has attribute definitions associated with it if (acBlkTblRec != null && acBlkTblRec.HasAttributeDefinitions) { foreach (var objId in acBlkTblRec) { var dbObj = acTrans.GetObject(objId, OpenMode.ForRead); if (!(dbObj is AttributeDefinition acAtt)) { continue; } if (acAtt.Constant) { continue; } using (var acAttRef = new AttributeReference()) { acAttRef.SetAttributeFromBlock(acAtt, acBlkRef.BlockTransform); if (!acBlkRef.ContainsAttributeDef(acAtt.Tag, acTrans)) { acAttRef.TextString = acAtt.TextString; acBlkRef.AttributeCollection.AppendAttribute(acAttRef); acTrans.AddNewlyCreatedDBObject(acAttRef, true); } } } } }