У того блока, у которого больше Handle, тот и вставлен последним.
Если Handle числовое значение, то почему не идет сравнение? Я словил exception.
[CommandMethod("ListBlockReferences")]
public static void SetCurrentPageNumber( )
{
//--------------------------------------------------------------------Mandatory variables
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
Editor ed = acDoc.Editor;
Transaction acTrans = acCurDb.TransactionManager.StartTransaction( );
//--------------------------------------------------------------------Mandatory variables
int curPageNumber = 0;
List<Handle> listOfHandles = new List<Handle>( );
ObjectIdCollection attIdWithPage = new ObjectIdCollection( );
using (acTrans)
{
BlockTable bt = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead, false, true) as BlockTable;
foreach (ObjectId btrId in bt)
{
BlockTableRecord btr = acTrans.GetObject(btrId, OpenMode.ForRead, false, true) as BlockTableRecord;
if (btr.Name.StartsWith("Regular"))
{
ObjectIdCollection brIdCollection = btr.GetBlockReferenceIds(false, true);
curPageNumber = curPageNumber + brIdCollection.Count;
foreach (ObjectId brId in brIdCollection)
{
BlockReference br = acTrans.GetObject(brId, OpenMode.ForRead) as BlockReference;
listOfHandles.Add(br.Handle);
var brHandle = listOfHandles.Max( );
if (br.Handle == brHandle)
{
AttributeCollection brAttCollection = br.AttributeCollection;
foreach (ObjectId attId in brAttCollection)
{
AttributeReference attribute = acTrans.GetObject(attId, OpenMode.ForRead) as AttributeReference;
if (attribute.Tag == "Page")
{
attIdWithPage.Add(attId);
}
}
}
}
}
}
foreach (ObjectId idAtt in attIdWithPage)
{
AttributeReference att = acTrans.GetObject(idAtt, OpenMode.ForWrite) as AttributeReference;
att.TextString = curPageNumber.ToString( );
}
acTrans.Commit( );
}
Application.DocumentManager.MdiActiveDocument.Editor.Regen( );
}
line 80 в моем коде это27 здесь. По тексту ошибки выходит, что handle не реализует интерфейс
Но ошибки кода нет, компиляция без проблем.
************** Exception Text **************
System.ArgumentException: At least one object must implement IComparable.
at System.Collections.Comparer.Compare(Object a, Object b)
at System.Collections.Generic.ObjectComparer`1.Compare(T x, T y)
at System.Linq.Enumerable.Max[TSource](IEnumerable`1 source)
at GOST_Titles.PageEnumerator.AttributeHandler.SetCurrentPageNumber() in E:\Visual Studio\Projects\Recirculation\ITAT_Autocad\GOST Titles\PageEnumerator.cs:line 80
at Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorker(MethodInfo mi, Object commandObject, Boolean bLispFunction)
at Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorkerWithExceptionFilter(MethodInfo mi, Object commandObject, Boolean bLispFunction)
at Autodesk.AutoCAD.Runtime.CommandClass.CommandThunk.Invoke()