Hi Bill.
Sorry, that code was bugged.
You might have noticed one of my rants about using IEnumerator directly in
code, which is not advised except in unusual situations, and if you do use
it, you have to check to see if it implements IDisposable and if it does,
call it's Dispose() method.
Here is a revised version that works. It uses foreach() to get the first
item in the collection which eliminates the need to deal with IEnumerator
directly.
{code}
public static ObjectId GetNewest( DBDictionary dictionary )
{
ICollection ids = ((IDictionary) dictionary).Values;
ObjectId last = ObjectId.Null;
foreach( ObjectId temp in ids )
{
last = temp;
break;
}
if( ! last.IsNull )
{
long current = last.Handle.Value;
foreach( ObjectId id in ids )
{
long value = id.Handle.Value;
if( value > current )
{
current = value;
last = id;
}
}
}
return last;
}
{code}
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010
http://www.acadxtabs.com
Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");
wrote in message news:6274283@discussion.autodesk.com...
Thanks Tony.
Didn't know that about sort.
It's fortunate that this all boils down to the highest handle value.
Should come in handy for most all objects created in the drawing.
I'm having one problem with: ObjectId last = ids[0];
it tells me that I cannot use indexing on an ICollection.
I'll see if I can figure out how to get a single item from the collection or
use something different.
Edit:
This seemed a straight forward way to get a single item from the
ICollection:
>DBDictionary groups =
(DBDictionary)tr.GetObject(db.GroupDictionaryId, OpenMode.ForRead);
>ICollection ids = ((IDictionary)groups).Values;
>IEnumerator enumerator = ids.GetEnumerator();
>ObjectId last = ObjectId.Null;
>
> if (enumerator.MoveNext())
>{
>last = (ObjectId)enumerator.Current;
>long current = last.Handle.Value;
>
> foreach (ObjectId id in ids)
>{
>long value = id.Handle.Value;
>if (value > current)
> {
>current = value;
>last = id;
>}
>}
>}
>if (!last.IsNull)
>{
>Group grp = (Group)tr.GetObject(last,
OpenMode.ForRead, false, true);
>return grp.Name;
>}
Bill
Edited by: BillZndl on Oct 20, 2009 8:40 AM