.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Read all entity in Block definition

2 REPLIES 2
Reply
Message 1 of 3
Anonymous
256 Views, 2 Replies

Read all entity in Block definition

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
2 REPLIES 2
Message 2 of 3
Anonymous
in reply to: Anonymous

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]
Message 3 of 3
Anonymous
in reply to: Anonymous

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]

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost