Message 1 of 28
Counting nested blocks very fast
Not applicable
02-09-2009
02:22 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi at all,
I have a a performance issue when counting nested blocks and hope that someone could help me.
I want to count blocks on Layers H_60* which have the attributes ArticleID and a Multiplier. These blocks can be nested blocks but will not have any further nested blocks. The drawings can be very big but the counting should work in less than a second.
My approach is in the attachment but it is not fast enough. The method gets the objectIds which aefound on Layer "H_60*"
The profiler shows that that line 92 hits more than 300000 times in a drawing with 2200 blocks of the same type.
Do I need to go through the whole blocktablerecord just to find a specific attribute?
Lines 88-92:
{code}
BlockTableRecord blockTableRecord = (BlockTableRecord)currentBlock.BlockTableRecord.GetObject(OpenMode.ForRead,false);
ObjectIdCollection nestedBlockIds = new ObjectIdCollection();
foreach (ObjectId objectId in blockTableRecord)
{
Entity entity = (Entity)transAction.GetObject(objectId, OpenMode.ForRead);
{code}
Is there a faster way of counting nested blocks with the API? EATTEXT and bcount does not seem to work for me.
Is there a faster way than the code above and running through all objectId or tablerecord like this?
{code}
foreach (ObjectId currentSelectedObjectId in objectIds)
{
Entity currentSelectedEntity = (Entity)transAction.GetObject(currentSelectedObjectId, OpenMode.ForRead);
{
BlockReference currentBlock = (BlockReference)currentSelectedEntity;
...
{code}
Thanks in advanced Edited by: hcaddev on Feb 9, 2009 11:53 AM
I have a a performance issue when counting nested blocks and hope that someone could help me.
I want to count blocks on Layers H_60* which have the attributes ArticleID and a Multiplier. These blocks can be nested blocks but will not have any further nested blocks. The drawings can be very big but the counting should work in less than a second.
My approach is in the attachment but it is not fast enough. The method gets the objectIds which aefound on Layer "H_60*"
The profiler shows that that line 92 hits more than 300000 times in a drawing with 2200 blocks of the same type.
Do I need to go through the whole blocktablerecord just to find a specific attribute?
Lines 88-92:
{code}
BlockTableRecord blockTableRecord = (BlockTableRecord)currentBlock.BlockTableRecord.GetObject(OpenMode.ForRead,false);
ObjectIdCollection nestedBlockIds = new ObjectIdCollection();
foreach (ObjectId objectId in blockTableRecord)
{
Entity entity = (Entity)transAction.GetObject(objectId, OpenMode.ForRead);
{code}
Is there a faster way of counting nested blocks with the API? EATTEXT and bcount does not seem to work for me.
Is there a faster way than the code above and running through all objectId or tablerecord like this?
{code}
foreach (ObjectId currentSelectedObjectId in objectIds)
{
Entity currentSelectedEntity = (Entity)transAction.GetObject(currentSelectedObjectId, OpenMode.ForRead);
{
BlockReference currentBlock = (BlockReference)currentSelectedEntity;
...
{code}
Thanks in advanced Edited by: hcaddev on Feb 9, 2009 11:53 AM