.NET

Reply
*GPaolo
Message 1 of 3 (118 Views)

Read all entity in Block definition

118 Views, 2 Replies
04-29-2006 02:37 AM
Is already too much time that i search the way to iterate in Block
definition to read the objectid of any entity contained.

Someone can explain me the correct way to make it?


I want use the dotnet managed library not Com ,because with com i know the
system.
Many thank's in Advance
GPaolo
Distinguished Contributor
Alexander Rivilis
Posts: 303
Registered: ‎09-26-2004
Message 2 of 3 (118 Views)

Re: Read all entity in Block definition

04-29-2006 02:10 PM in reply to: *GPaolo
As variant:
[code]
static public ObjectIdCollection GetAllObjectIdsInBlockDef(ObjectId idBlockDef)
{
ObjectIdCollection ids = new ObjectIdCollection();
Database db = idBlockDef.Database;
Transaction trans = db.TransactionManager.StartTransaction();
try
{
BlockTableRecord btr = (BlockTableRecord)(trans.GetObject(idBlockDef, OpenMode.ForRead));
foreach (ObjectId id in btr) ids.Add(id);
trans.Commit();
}
finally
{
trans.Dispose();
}
return ids;
}
[/code]

Only for testing:

[code]
[CommandMethod("GetAllIdsInCurrentSpace")]
static public void GetAllIdsInCurrentSpace()
{
Autodesk.AutoCAD.EditorInput.Editor ed =
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
Database db = HostApplicationServices.WorkingDatabase;
ObjectIdCollection ids = GetAllObjectIdsInBlockDef(db.CurrentSpaceId);
ed.WriteMessage("\nNumber of entities in current space: {0}",ids.Count);
}
[/code]
*GPaolo
Message 3 of 3 (118 Views)

Re: Read all entity in Block definition

05-02-2006 01:35 AM in reply to: *GPaolo
ok.Many thanks

ha scritto nel messaggio
news:5158998@discussion.autodesk.com...
As variant:
[code]
static public ObjectIdCollection GetAllObjectIdsInBlockDef(ObjectId
idBlockDef)
{
ObjectIdCollection ids = new ObjectIdCollection();
Database db = idBlockDef.Database;
Transaction trans = db.TransactionManager.StartTransaction();
try
{
BlockTableRecord btr = (BlockTableRecord)(trans.GetObject(idBlockDef,
OpenMode.ForRead));
foreach (ObjectId id in btr) ids.Add(id);
trans.Commit();
}
finally
{
trans.Dispose();
}
return ids;
}
[/code]

Only for testing:

[code]
[CommandMethod("GetAllIdsInCurrentSpace")]
static public void GetAllIdsInCurrentSpace()
{
Autodesk.AutoCAD.EditorInput.Editor ed =

Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDo
cument.Editor;
Database db = HostApplicationServices.WorkingDatabase;
ObjectIdCollection ids = GetAllObjectIdsInBlockDef(db.CurrentSpaceId);
ed.WriteMessage("\nNumber of entities in current space: {0}",ids.Count);
}
[/code]
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.