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

Sort and count block references

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
kinakira2013
589 Views, 4 Replies

Sort and count block references

Hi,

 

I have an ObjectIdCollection (of block references). I don't know how to sort and count block references via ObjectIdCollection.

Anyone can help me?

 

Thanks!

-Kin-

4 REPLIES 4
Message 2 of 5
_gile
in reply to: kinakira2013

Hi,

You should ellaborate what you mean with: "sort and count block references"



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 5
kinakira2013
in reply to: _gile


@_gile wrote:

Hi,

You should ellaborate what you mean with: "sort and count block references"


Hi _gile,

I mean that:

- Sort ascending follow the name of blocks (alpha, beta)

- Count: is the number of each type of block

I want to display a list name (sorted) and quantity of each block.

Example:

A1 : 10

A5 : 2

B3 : 2

C12 : 7

Message 4 of 5
Anonymous
in reply to: kinakira2013

It looks like magic. You run the command, select everything and hit enter. Watch! There is a list of all blocks, sorted by name, including quantity. So what is this magic word? think.
The BCOUNT team is part of Express Tools, so if you are using AutoCAD LT you will not have any fun because the Express tools are not.

Message 5 of 5
_gile
in reply to: kinakira2013

  1. Create a new instance of Dictionary<string, int> where the key (string) will be the block name and the value (int) the number of blocks.
  2. Iterate through the ObjectId collection and, for each ObjectId:
    1. Open the block reference for read.
    2. Check if the dictionary contains a key equal to the block name:
      1. If the key is found, increment the value.
      2. Else create a new key with the block name and a value equal to 1.

This can also be done in a more declarative way using Linq queries (GroupBy, Count, ...).



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report