Firstly, this 'very messy and inefficient' code sample needs a serious
revision to get rid of all the unnecessary duplication and If...Then
constructs.
One problem I see right away after reading your sample file is that
you're processing 'components' of an assembly, and so not all will have
the same 'attributes' by nature of their individual design. In this
case you need a 'map' enum for your headers so you can assign non-blank
attributes to their respective 'fields' so the data ends up in the
correct columns. This requires a methodology that enums attributes so
you can assign column indexes to values. It also requires your 'same'
attributes be named identically so they can be identified for their
respective position in the data table.
I switched from using ACAD to using SolidWorks back in the 90's and so
its equivalent to model 'attributes' is model 'properties'. I use model
templates that have the same list of properties (via PropertyManager)
for all (sldprt, sldasm) so list number of 'fields' is the same for all
components and assemblies. (Assemblies can contain sub-assemblies) I
don't have to figure things out 'after-the-fact' and so I can't help
you here much beyond approach concept...
1. Loop all components in the model to build a unique list of
'attribute' IDs. (This can be as simple in construct as a delimited
string list!)
2. Loop again to find the index of each component's 'attribute' in the
string list. (This can be as simple as using a counter in a For...Each
constructs!)
3. Assign the value of the components 'attribute' to the counter
position in your 'output array'. The output array should be 2D...
ReDim vaDataOut(<component.count, <attributes.count)
...so all data is processed in memory. Make sure you have a proper
handle on the 'count' values as to their 'base' being zero or 1 so
vaDataOut is correctly dimmed! Note that this array is being dimmed
dynamically and so must be done using the 'ReDim' statement in order to
use variables for the respective 'count' values.
4. Once all data is assign, 'dump' vaDataOut into the worksheet.
However, I strongly suggest implementing a standard set of 'attributes'
for all part/assembly files so you have a consistent 'set' of value
'placeholders' regardless if all are used for every part/assembly file.
--
Garry
Free usenet access at
http://www.eternal-september.org
Classic
VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.
vb.general.discussion