-1

In an AutoCAD VBA routine i have made, the program searches for dynamic blocks with a certain name and extracts some dynamic properties - width and height.

What i have so far is a list of all the blocks and their properties but they are not sorted - if a block has the same width and height as another, it simply lists them individually. The block info is in the form of a multi-dimensional array, such as:

PANEL(j, 0) = Panel_ref

PANEL(j, 1) = width

PANEL(j, 2) = height

(j is just a counter within cycling through each block in the selection set.)

What I would to do is be able to sort all these blocks into groups (not autocad groups) of the same size, so if there a few blocks that are 595x455 (width x height) for example, these should be grouped so that there are X number of them (say Panel_ref #1) and not individually tabled. I hope i'm being clear enough.

So bascially, it would look like:

Ref | Width | Height | Quantity

1 | 600 | 800 | 3

2 | 700 | 900 | 1

3 | 650 | 1000 | 2

instead of......

Ref | Width | Height

1 | 600 | 800

2 | 600 | 800

3 | 600 | 800

4 | 700 | 900

5 | 650 | 1000

6 | 650 | 1000

...as it is now. (sorry, i can't format this post any better)

What is the best way to sort this data? I've seen array sorting code online but only for non multi-dim arrays.

I guess i would need to cycle through the array, find the different "sizes" (width and height), store them somewhere and compare the each block to these? I was thinking of converting the width and height to a String ("800 x 600") as comparing these that way but i'm sure it can be done in their number (Double) format.

If need be, i can post some code but thought it might be easier without for now.

Thanks,

Paul.

  • Does AutoCAD VBA require a multidimensional array? If it supports user-defined types, that would make things easier. – Weston E Jan 09 '19 at 20:21
  • Oh yeah, of course. I forgot all about types. That will be neater code too. Thanks. I still need to get my head around how to group any same-size blocks though. – hardwiredstudios Jan 09 '19 at 23:33
  • Will AutoCAD VBA let you instantiate an Excel Application object? If so, you could build a temporary worksheet and let Excel VBA do the sorting. – Weston E Jan 10 '19 at 13:58
  • Yeah it will and i was thinking of doing this but i thought excel couldn't sort things like this - i thought excel sorts the columns but the rows get screwed up as they're not exclusively tied? That's probably not the case but i don't know enough about it. Access would be good but means the user must have access installed. – hardwiredstudios Jan 10 '19 at 14:11

1 Answers1

0

Excel VBA lets you specify multiple sort keys (Sort.SortFields.Add) and also a sort range of any size (Sort.SetRange Range("A1:H200")).

sample sort code

Weston E
  • 133
  • 1
  • 9
  • Thanks for that code, that's awesome. Once i'm back on that program i'll give it a go and see if i can get it sorted. thanks for all your help – hardwiredstudios Jan 12 '19 at 19:26