You can't remove anything from a SelectionSet (but you can prevent
objects from being added using the Editor's SelectionAdded event).
The sample below pulls the objectids of all distinct DBPoint objects
from a SelectionSet, where no two or more points referenced by the
ids in the resulting ObjectIdCollection should be coincident.
{code}
public class Example
{
public static ObjectIdCollection GetDistinctPointIds( SelectionSet ss )
{
Database db = ss[0].ObjectId.Database;
RXClass pointClass = RXObject.GetClass( typeof( DBPoint ) );
using( Transaction tr = db.TransactionManager.StartTransaction() )
{
try
{
return new ObjectIdCollection(
ss.GetObjectIds().Cast
()
.Where( id => id.ObjectClass.IsDerivedFrom( pointClass ) )
.Select( id => id.GetObject( OpenMode.ForRead ) as
DBPoint )
.Distinct( new DBPointEqualityComparer() )
.Select( p => p.ObjectId )
.ToArray() );
}
finally
{
tr.Commit();
}
}
}
/// same as above, but using Linq expressions:
public static ObjectIdCollection GetDistinctPointIds2( SelectionSet ss )
{
Database db = ss[0].ObjectId.Database;
RXClass pointClass = RXObject.GetClass( typeof( DBPoint ) );
using( Transaction tr = db.TransactionManager.StartTransaction() )
{
try
{
var points = from id in ss.GetObjectIds().Cast()
where id.ObjectClass.IsDerivedFrom(
pointClass )
select id.GetObject( OpenMode.ForRead ) as
DBPoint;
points = points.Distinct( new DBPointEqualityComparer() );
var ids = from dbPoint in points
select dbPoint.ObjectId;
return new ObjectIdCollection( ids.ToArray() );
}
finally
{
tr.Commit();
}
}
}
class DBPointEqualityComparer : IEqualityComparer
{
public bool Equals( DBPoint x, DBPoint y )
{
return x.Position == y.Position;
}
public int GetHashCode( DBPoint obj )
{
return obj != null ? obj.Position.GetHashCode() : 0;
}
}
}
{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");
"Paul Richardson" wrote in message
news:6254792@discussion.autodesk.com...
If your set of points is a set of ObjectIds then you'll need to open them to
do your testing. This filtered 262144 points and returned the 16 non
duplicates in 1.37 seconds. Arbitrary test but still quick.
{code}
static ObjectIdCollection RemoveDuplicatePoints
(IEnumerable o,Transaction t)
{
List temp = new List();
ObjectIdCollection ids =
new ObjectIdCollection();
foreach (ObjectId id in o)
{
//note I'm assuming all point ids.
DBPoint p = (DBPoint)t.GetObject
(id, OpenMode.ForRead);
if (temp.Contains
(p.Position)) continue;
temp.Add(p.Position);
ids.Add(id);
}
return ids;
}
{code}
wrote in message news:6254391@discussion.autodesk.com...
Hello,
Is posibly to do this automaticaly without iterating set of points?
Best regards,
Danijel Ivankovic