public static ObjectIdCollection GetBlockReferencesWithDesiredPosition(string compartent, string desiredPosition) // Получает все блоки позиций с требуемым номером
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
List<Point3d> listOfBasePoints = new List<Point3d>();
ObjectIdCollection bRefCollection = new ObjectIdCollection();
using ( Transaction tr = doc.TransactionManager.StartTransaction() )
{
BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
if ( bt.Has("GTItemMark") )
{
foreach ( ObjectId btrId in bt ) //bt набор btrRecord то есть по своей сути уже коллекция!
{
BlockTableRecord btr = tr.GetObject(btrId, OpenMode.ForRead) as BlockTableRecord;
if ( btr.Name.Contains("GTItemMark") )
{
ObjectIdCollection bRefIdCollection = btr.GetBlockReferenceIds(false, true); // собрать все Id от BlockReference из BlockTableRecord в коллекцию
foreach ( ObjectId bRefId in bRefIdCollection )
{
BlockReference bRef = tr.GetObject(bRefId, OpenMode.ForWrite) as BlockReference; // получить все BlockReference
AttributeCollection attrIdCollection = bRef.AttributeCollection; // собрать все Id от атрибутов из BlockTableRecord в коллекцию
foreach ( ObjectId idAttRef in attrIdCollection )
{
AttributeReference att = (AttributeReference)tr.GetObject(idAttRef, OpenMode.ForWrite);
if ( (att.Tag == "ContourNumber") && (att.TextString.Substring(0, 2) == compartent) && (int.Parse(att.TextString.Substring(3, 2)) >= int.Parse(desiredPosition)) )
{
int num = int.Parse(att.TextString.Substring(3, 2)) + 1;
if ( num.ToString().Length == 1 )
{
att.TextString = compartent + "-0" + num.ToString();
}
else
{
att.TextString = compartent + "-" + num.ToString();
}
}
}
}
}
}
}
tr.Commit();
}
return bRefCollection;
}