.NET

Reply
*GPaolo
Message 1 of 3 (120 Views)

Read all entity in Block definition

120 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 (120 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 (120 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]
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!