MDT VBA and collections

MDT VBA and collections

Anonymous
Not applicable
406 Views
7 Replies
Message 1 of 8

MDT VBA and collections

Anonymous
Not applicable
In MDT5's VBA I have a collection of objects, say mcad definitions. If I
want to
access one specific item in the collection I currently have to perform a For
Loop until it matches the name of the definition in question. See below.

-------
'Create collection of all definitions in drawing.
Set oMCADComps = CreateArrayOfComponents(oAssMgr.RootDefinition)

'Loop until I find the definition in question.
For j = 0 To oMCADComps.Count - 1
If oMCADComps(j).Definition.Name = "My Special Part" Then
'Found match
Set oPart=oMCADComps(j).Definition.Body
... Do the rest of my thing here (about 30 lines) ...
End If
Next j
-----
Why can't I do the following?
Set oPart=oMCADComps("My Special Part").Definition.Body

In theory it should work, no? Unfortunately it doesn't and I have to
perform the For Loop for at least 10 parts which means cycling through the
oMCADComps (with about 100+ parts) for each part which is taking a LOOOOOONG
time.

Any ideas? TIA
--
Seth Cohen
Group Leader-Design Department
Mystaire Division
Misonix, Inc.
0 Likes
407 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable
If I remember correctly, this is a flaw in the Definitions collection. I
believe you can NOT directly access a definition by it's name, only by
index. (How useful !!). Luckily for me I have not had to refer to a
component definition this way ...so far. There may be an alternative to
iterating the collection and comparing names, however I don't see it right
now.


Regards,
Jacob Dinardi


"Seth Cohen" wrote in message
news:21F8FC13E0684909C5F5131793729C96@in.WebX.maYIadrTaRb...
> In MDT5's VBA I have a collection of objects, say mcad definitions. If I
> want to
> access one specific item in the collection I currently have to perform a
For
> Loop until it matches the name of the definition in question. See below.
>
> -------
> 'Create collection of all definitions in drawing.
> Set oMCADComps = CreateArrayOfComponents(oAssMgr.RootDefinition)
>
> 'Loop until I find the definition in question.
> For j = 0 To oMCADComps.Count - 1
> If oMCADComps(j).Definition.Name = "My Special Part" Then
> 'Found match
> Set oPart=oMCADComps(j).Definition.Body
> ... Do the rest of my thing here (about 30 lines) ...
> End If
> Next j
> -----
> Why can't I do the following?
> Set oPart=oMCADComps("My Special Part").Definition.Body
>
> In theory it should work, no? Unfortunately it doesn't and I have to
> perform the For Loop for at least 10 parts which means cycling through the
> oMCADComps (with about 100+ parts) for each part which is taking a
LOOOOOONG
> time.
>
> Any ideas? TIA
> --
> Seth Cohen
> Group Leader-Design Department
> Mystaire Division
> Misonix, Inc.
>
>
0 Likes
Message 3 of 8

Anonymous
Not applicable
Jacob,

If you don't mind, please check out the mcad.mdt5.support ng. I posted the
same question there and I think I may have found a sneaky way around this
frustrating mess.

I basically create another array with just the names, find the name in
question in the array, get the index then use the index back in the
collection. Problem is, how do I get the index from the array without going
through the same mess of For loops? I posted some stuff I tried this
morning but I'm still not 100% there.

If you can help that would be great.

Thanks
--
--
Seth Cohen
Group Leader-Design Department
Mystaire Division
Misonix, Inc.
"Jacob Dinardi" wrote in message
news:D891D24023EA80E24AAE9A6E6CAA8AC4@in.WebX.maYIadrTaRb...
> If I remember correctly, this is a flaw in the Definitions collection. I
> believe you can NOT directly access a definition by it's name, only by
> index. (How useful !!). Luckily for me I have not had to refer to a
> component definition this way ...so far. There may be an alternative to
> iterating the collection and comparing names, however I don't see it right
> now.
>
>
> Regards,
> Jacob Dinardi
>
>
> "Seth Cohen" wrote in message
> news:21F8FC13E0684909C5F5131793729C96@in.WebX.maYIadrTaRb...
> > In MDT5's VBA I have a collection of objects, say mcad definitions. If
I
> > want to
> > access one specific item in the collection I currently have to perform a
> For
> > Loop until it matches the name of the definition in question. See
below.
> >
> > -------
> > 'Create collection of all definitions in drawing.
> > Set oMCADComps = CreateArrayOfComponents(oAssMgr.RootDefinition)
> >
> > 'Loop until I find the definition in question.
> > For j = 0 To oMCADComps.Count - 1
> > If oMCADComps(j).Definition.Name = "My Special Part" Then
> > 'Found match
> > Set oPart=oMCADComps(j).Definition.Body
> > ... Do the rest of my thing here (about 30 lines) ...
> > End If
> > Next j
> > -----
> > Why can't I do the following?
> > Set oPart=oMCADComps("My Special Part").Definition.Body
> >
> > In theory it should work, no? Unfortunately it doesn't and I have to
> > perform the For Loop for at least 10 parts which means cycling through
the
> > oMCADComps (with about 100+ parts) for each part which is taking a
> LOOOOOONG
> > time.
> >
> > Any ideas? TIA
> > --
> > Seth Cohen
> > Group Leader-Design Department
> > Mystaire Division
> > Misonix, Inc.
> >
> >
>
>
0 Likes
Message 4 of 8

Anonymous
Not applicable
One thought I have is this:

You could take a one-time hit and create your own collection of component
definitions, when you add the objects to it specify their name as the key.
You should be able to reference this collection instead, using the standard
myCollection("MyItemKey") syntax.

Caveat:

If you create more component definitions you need to update your collection
with the new object. Ugly? Yes. Will it work? I think so!


Jacob


"Seth Cohen" wrote in message
news:C7202801DC5C4E14C8657F693FACA664@in.WebX.maYIadrTaRb...
> Jacob,
>
> If you don't mind, please check out the mcad.mdt5.support ng. I posted
the
> same question there and I think I may have found a sneaky way around this
> frustrating mess.
>
> I basically create another array with just the names, find the name in
> question in the array, get the index then use the index back in the
> collection. Problem is, how do I get the index from the array without
going
> through the same mess of For loops? I posted some stuff I tried this
> morning but I'm still not 100% there.
>
> If you can help that would be great.
>
> Thanks
> --
> --
> Seth Cohen
> Group Leader-Design Department
> Mystaire Division
> Misonix, Inc.
> "Jacob Dinardi" wrote in message
> news:D891D24023EA80E24AAE9A6E6CAA8AC4@in.WebX.maYIadrTaRb...
> > If I remember correctly, this is a flaw in the Definitions collection. I
> > believe you can NOT directly access a definition by it's name, only by
> > index. (How useful !!). Luckily for me I have not had to refer to a
> > component definition this way ...so far. There may be an alternative to
> > iterating the collection and comparing names, however I don't see it
right
> > now.
> >
> >
> > Regards,
> > Jacob Dinardi
> >
> >
> > "Seth Cohen" wrote in message
> > news:21F8FC13E0684909C5F5131793729C96@in.WebX.maYIadrTaRb...
> > > In MDT5's VBA I have a collection of objects, say mcad definitions.
If
> I
> > > want to
> > > access one specific item in the collection I currently have to perform
a
> > For
> > > Loop until it matches the name of the definition in question. See
> below.
> > >
> > > -------
> > > 'Create collection of all definitions in drawing.
> > > Set oMCADComps = CreateArrayOfComponents(oAssMgr.RootDefinition)
> > >
> > > 'Loop until I find the definition in question.
> > > For j = 0 To oMCADComps.Count - 1
> > > If oMCADComps(j).Definition.Name = "My Special Part" Then
> > > 'Found match
> > > Set oPart=oMCADComps(j).Definition.Body
> > > ... Do the rest of my thing here (about 30 lines) ...
> > > End If
> > > Next j
> > > -----
> > > Why can't I do the following?
> > > Set oPart=oMCADComps("My Special Part").Definition.Body
> > >
> > > In theory it should work, no? Unfortunately it doesn't and I have to
> > > perform the For Loop for at least 10 parts which means cycling through
> the
> > > oMCADComps (with about 100+ parts) for each part which is taking a
> > LOOOOOONG
> > > time.
> > >
> > > Any ideas? TIA
> > > --
> > > Seth Cohen
> > > Group Leader-Design Department
> > > Mystaire Division
> > > Misonix, Inc.
> > >
> > >
> >
> >
>
>
0 Likes
Message 5 of 8

Anonymous
Not applicable
Jacob,

I already tried to make a variant array just of the defs names. Couldn't
get it to work.
Just tried to a collection of comp defs. Same problem as with any
collection.

There's no way to get the index from a variant if I plug in the name I want
in the array?

I posted 2 sections of code that are a mm away from solving this problem (in
the mcad.mdt5.support ng)

Maybe I'll post another message to this ng about dealing with arrays.
--
--
Seth Cohen
Group Leader-Design Department
Mystaire Division
Misonix, Inc.
"Jacob Dinardi" wrote in message
news:7F857F707BA7DA8A6F72A30BC3B893BF@in.WebX.maYIadrTaRb...
> One thought I have is this:
>
> You could take a one-time hit and create your own collection of component
> definitions, when you add the objects to it specify their name as the key.
> You should be able to reference this collection instead, using the
standard
> myCollection("MyItemKey") syntax.
>
> Caveat:
>
> If you create more component definitions you need to update your
collection
> with the new object. Ugly? Yes. Will it work? I think so!
>
>
> Jacob
>
>
> "Seth Cohen" wrote in message
> news:C7202801DC5C4E14C8657F693FACA664@in.WebX.maYIadrTaRb...
> > Jacob,
> >
> > If you don't mind, please check out the mcad.mdt5.support ng. I posted
> the
> > same question there and I think I may have found a sneaky way around
this
> > frustrating mess.
> >
> > I basically create another array with just the names, find the name in
> > question in the array, get the index then use the index back in the
> > collection. Problem is, how do I get the index from the array without
> going
> > through the same mess of For loops? I posted some stuff I tried this
> > morning but I'm still not 100% there.
> >
> > If you can help that would be great.
> >
> > Thanks
> > --
> > --
> > Seth Cohen
> > Group Leader-Design Department
> > Mystaire Division
> > Misonix, Inc.
> > "Jacob Dinardi" wrote in message
> > news:D891D24023EA80E24AAE9A6E6CAA8AC4@in.WebX.maYIadrTaRb...
> > > If I remember correctly, this is a flaw in the Definitions collection.
I
> > > believe you can NOT directly access a definition by it's name, only by
> > > index. (How useful !!). Luckily for me I have not had to refer to a
> > > component definition this way ...so far. There may be an alternative
to
> > > iterating the collection and comparing names, however I don't see it
> right
> > > now.
> > >
> > >
> > > Regards,
> > > Jacob Dinardi
> > >
> > >
> > > "Seth Cohen" wrote in message
> > > news:21F8FC13E0684909C5F5131793729C96@in.WebX.maYIadrTaRb...
> > > > In MDT5's VBA I have a collection of objects, say mcad definitions.
> If
> > I
> > > > want to
> > > > access one specific item in the collection I currently have to
perform
> a
> > > For
> > > > Loop until it matches the name of the definition in question. See
> > below.
> > > >
> > > > -------
> > > > 'Create collection of all definitions in drawing.
> > > > Set oMCADComps = CreateArrayOfComponents(oAssMgr.RootDefinition)
> > > >
> > > > 'Loop until I find the definition in question.
> > > > For j = 0 To oMCADComps.Count - 1
> > > > If oMCADComps(j).Definition.Name = "My Special Part"
Then
> > > > 'Found match
> > > > Set oPart=oMCADComps(j).Definition.Body
> > > > ... Do the rest of my thing here (about 30 lines)
...
> > > > End If
> > > > Next j
> > > > -----
> > > > Why can't I do the following?
> > > > Set oPart=oMCADComps("My Special Part").Definition.Body
> > > >
> > > > In theory it should work, no? Unfortunately it doesn't and I have
to
> > > > perform the For Loop for at least 10 parts which means cycling
through
> > the
> > > > oMCADComps (with about 100+ parts) for each part which is taking a
> > > LOOOOOONG
> > > > time.
> > > >
> > > > Any ideas? TIA
> > > > --
> > > > Seth Cohen
> > > > Group Leader-Design Department
> > > > Mystaire Division
> > > > Misonix, Inc.
> > > >
> > > >
> > >
> > >
> >
> >
>
>
0 Likes
Message 6 of 8

Anonymous
Not applicable
Seth, I was referring to something like this...

Sub MakeDefsCollection()
Dim oMCAD As McadApplication
Dim oCompDef As McadComponentDefinition
Dim oCompDefs As McadComponentDefinitions
Dim colMyDefs As New Collection

Set oMCAD = Application.GetInterfaceObject("MCAD.Application")

Set oCompDefs = oMCAD.ActiveDocument.AssemblyMgr.Definitions

For Each oCompDef In oCompDefs
colMyDefs.Add oCompDef, oCompDef.Name
Next

colMyDefs("cylinder").Delete

Set colMyDefs = Nothing ' see notes
End Sub



I ran this in a drawing with (2) parts, one called "cylinder" and one called
"cube", it successfully deleted the cylinder definition. Obviously you still
have to use a for...each to initially get the objects into your collection,
however if you need to access it more than once, it will save from running
the loop every time. In this case don't destroy the collection until you aer
done with it.

Like I said though, you need to manually keep it up-to-date, but I think
that would be the case with your solution as well.


Jacob


"Seth Cohen" wrote in message
news:BB4D15ED1C5913BF17A9282DB6963187@in.WebX.maYIadrTaRb...
> Jacob,
>
> I already tried to make a variant array just of the defs names. Couldn't
> get it to work.
> Just tried to a collection of comp defs. Same problem as with any
> collection.
>
> There's no way to get the index from a variant if I plug in the name I
want
> in the array?
>
> I posted 2 sections of code that are a mm away from solving this problem
(in
> the mcad.mdt5.support ng)
>
> Maybe I'll post another message to this ng about dealing with arrays.
> --
> --
> Seth Cohen
> Group Leader-Design Department
> Mystaire Division
> Misonix, Inc.
> "Jacob Dinardi" wrote in message
> news:7F857F707BA7DA8A6F72A30BC3B893BF@in.WebX.maYIadrTaRb...
> > One thought I have is this:
> >
> > You could take a one-time hit and create your own collection of
component
> > definitions, when you add the objects to it specify their name as the
key.
> > You should be able to reference this collection instead, using the
> standard
> > myCollection("MyItemKey") syntax.
> >
> > Caveat:
> >
> > If you create more component definitions you need to update your
> collection
> > with the new object. Ugly? Yes. Will it work? I think so!
> >
> >
> > Jacob
> >
> >
> > "Seth Cohen" wrote in message
> > news:C7202801DC5C4E14C8657F693FACA664@in.WebX.maYIadrTaRb...
> > > Jacob,
> > >
> > > If you don't mind, please check out the mcad.mdt5.support ng. I
posted
> > the
> > > same question there and I think I may have found a sneaky way around
> this
> > > frustrating mess.
> > >
> > > I basically create another array with just the names, find the name in
> > > question in the array, get the index then use the index back in the
> > > collection. Problem is, how do I get the index from the array without
> > going
> > > through the same mess of For loops? I posted some stuff I tried this
> > > morning but I'm still not 100% there.
> > >
> > > If you can help that would be great.
> > >
> > > Thanks
> > > --
> > > --
> > > Seth Cohen
> > > Group Leader-Design Department
> > > Mystaire Division
> > > Misonix, Inc.
> > > "Jacob Dinardi" wrote in
message
> > > news:D891D24023EA80E24AAE9A6E6CAA8AC4@in.WebX.maYIadrTaRb...
> > > > If I remember correctly, this is a flaw in the Definitions
collection.
> I
> > > > believe you can NOT directly access a definition by it's name, only
by
> > > > index. (How useful !!). Luckily for me I have not had to refer to a
> > > > component definition this way ...so far. There may be an alternative
> to
> > > > iterating the collection and comparing names, however I don't see it
> > right
> > > > now.
> > > >
> > > >
> > > > Regards,
> > > > Jacob Dinardi
> > > >
> > > >
> > > > "Seth Cohen" wrote in message
> > > > news:21F8FC13E0684909C5F5131793729C96@in.WebX.maYIadrTaRb...
> > > > > In MDT5's VBA I have a collection of objects, say mcad
definitions.
> > If
> > > I
> > > > > want to
> > > > > access one specific item in the collection I currently have to
> perform
> > a
> > > > For
> > > > > Loop until it matches the name of the definition in question. See
> > > below.
> > > > >
> > > > > -------
> > > > > 'Create collection of all definitions in drawing.
> > > > > Set oMCADComps = CreateArrayOfComponents(oAssMgr.RootDefinition)
> > > > >
> > > > > 'Loop until I find the definition in question.
> > > > > For j = 0 To oMCADComps.Count - 1
> > > > > If oMCADComps(j).Definition.Name = "My Special Part"
> Then
> > > > > 'Found match
> > > > > Set oPart=oMCADComps(j).Definition.Body
> > > > > ... Do the rest of my thing here (about 30 lines)
> ...
> > > > > End If
> > > > > Next j
> > > > > -----
> > > > > Why can't I do the following?
> > > > > Set oPart=oMCADComps("My Special Part").Definition.Body
> > > > >
> > > > > In theory it should work, no? Unfortunately it doesn't and I have
> to
> > > > > perform the For Loop for at least 10 parts which means cycling
> through
> > > the
> > > > > oMCADComps (with about 100+ parts) for each part which is taking a
> > > > LOOOOOONG
> > > > > time.
> > > > >
> > > > > Any ideas? TIA
> > > > > --
> > > > > Seth Cohen
> > > > > Group Leader-Design Department
> > > > > Mystaire Division
> > > > > Misonix, Inc.
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>
0 Likes
Message 7 of 8

Anonymous
Not applicable
"Seth Cohen" wrote in message
news:BB4D15ED1C5913BF17A9282DB6963187@in.WebX.maYIadrTaRb...
> Jacob,
>
> I already tried to make a variant array just of the defs names. Couldn't
> get it to work.
> Just tried to a collection of comp defs. Same problem as with any
> collection.
>
> There's no way to get the index from a variant if I plug in the name I
want
> in the array?
>
> I posted 2 sections of code that are a mm away from solving this problem
(in
> the mcad.mdt5.support ng)
>
> Maybe I'll post another message to this ng about dealing with arrays.
> --
> --
> Seth Cohen
> Group Leader-Design Department
> Mystaire Division
> Misonix, Inc.
> "Jacob Dinardi" wrote in message
> news:7F857F707BA7DA8A6F72A30BC3B893BF@in.WebX.maYIadrTaRb...
> > One thought I have is this:
> >
> > You could take a one-time hit and create your own collection of
component
> > definitions, when you add the objects to it specify their name as the
key.
> > You should be able to reference this collection instead, using the
> standard
> > myCollection("MyItemKey") syntax.
> >
> > Caveat:
> >
> > If you create more component definitions you need to update your
> collection
> > with the new object. Ugly? Yes. Will it work? I think so!
> >
> >
> > Jacob
> >
> >
> > "Seth Cohen" wrote in message
> > news:C7202801DC5C4E14C8657F693FACA664@in.WebX.maYIadrTaRb...
> > > Jacob,
> > >
> > > If you don't mind, please check out the mcad.mdt5.support ng. I
posted
> > the
> > > same question there and I think I may have found a sneaky way around
> this
> > > frustrating mess.
> > >
> > > I basically create another array with just the names, find the name in
> > > question in the array, get the index then use the index back in the
> > > collection. Problem is, how do I get the index from the array without
> > going
> > > through the same mess of For loops? I posted some stuff I tried this
> > > morning but I'm still not 100% there.
> > >
> > > If you can help that would be great.
> > >
> > > Thanks
> > > --
> > > --
> > > Seth Cohen
> > > Group Leader-Design Department
> > > Mystaire Division
> > > Misonix, Inc.
> > > "Jacob Dinardi" wrote in
message
> > > news:D891D24023EA80E24AAE9A6E6CAA8AC4@in.WebX.maYIadrTaRb...
> > > > If I remember correctly, this is a flaw in the Definitions
collection.
> I
> > > > believe you can NOT directly access a definition by it's name, only
by
> > > > index. (How useful !!). Luckily for me I have not had to refer to a
> > > > component definition this way ...so far. There may be an alternative
> to
> > > > iterating the collection and comparing names, however I don't see it
> > right
> > > > now.
> > > >
> > > >
> > > > Regards,
> > > > Jacob Dinardi
> > > >
> > > >
> > > > "Seth Cohen" wrote in message
> > > > news:21F8FC13E0684909C5F5131793729C96@in.WebX.maYIadrTaRb...
> > > > > In MDT5's VBA I have a collection of objects, say mcad
definitions.
> > If
> > > I
> > > > > want to
> > > > > access one specific item in the collection I currently have to
> perform
> > a
> > > > For
> > > > > Loop until it matches the name of the definition in question. See
> > > below.
> > > > >
> > > > > -------
> > > > > 'Create collection of all definitions in drawing.
> > > > > Set oMCADComps = CreateArrayOfComponents(oAssMgr.RootDefinition)
> > > > >
> > > > > 'Loop until I find the definition in question.
> > > > > For j = 0 To oMCADComps.Count - 1
> > > > > If oMCADComps(j).Definition.Name = "My Special Part"
> Then
> > > > > 'Found match
> > > > > Set oPart=oMCADComps(j).Definition.Body
> > > > > ... Do the rest of my thing here (about 30 lines)
> ...
> > > > > End If
> > > > > Next j
> > > > > -----
> > > > > Why can't I do the following?
> > > > > Set oPart=oMCADComps("My Special Part").Definition.Body
> > > > >
> > > > > In theory it should work, no? Unfortunately it doesn't and I have
> to
> > > > > perform the For Loop for at least 10 parts which means cycling
> through
> > > the
> > > > > oMCADComps (with about 100+ parts) for each part which is taking a
> > > > LOOOOOONG
> > > > > time.
> > > > >
> > > > > Any ideas? TIA
> > > > > --
> > > > > Seth Cohen
> > > > > Group Leader-Design Department
> > > > > Mystaire Division
> > > > > Misonix, Inc.
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>
0 Likes
Message 8 of 8

Anonymous
Not applicable
YOU ARRRRRE THE MAN!!!

It worked like a charm, and a zillion times faster.

I didn't realize that there was a collection in VBA that was different from
MDT collection. Learn something new everyday.

Thanks again!
--
--
Seth Cohen
Group Leader-Design Department
Mystaire Division
Misonix, Inc.
"Jacob Dinardi" wrote in message
news:DA1D3CB333105787B8B13DD308B36B12@in.WebX.maYIadrTaRb...
> Seth, I was referring to something like this...
>
> Sub MakeDefsCollection()
> Dim oMCAD As McadApplication
> Dim oCompDef As McadComponentDefinition
> Dim oCompDefs As McadComponentDefinitions
> Dim colMyDefs As New Collection
>
> Set oMCAD = Application.GetInterfaceObject("MCAD.Application")
>
> Set oCompDefs = oMCAD.ActiveDocument.AssemblyMgr.Definitions
>
> For Each oCompDef In oCompDefs
> colMyDefs.Add oCompDef, oCompDef.Name
> Next
>
> colMyDefs("cylinder").Delete
>
> Set colMyDefs = Nothing ' see notes
> End Sub
>
>
>
> I ran this in a drawing with (2) parts, one called "cylinder" and one
called
> "cube", it successfully deleted the cylinder definition. Obviously you
still
> have to use a for...each to initially get the objects into your
collection,
> however if you need to access it more than once, it will save from running
> the loop every time. In this case don't destroy the collection until you
aer
> done with it.
>
> Like I said though, you need to manually keep it up-to-date, but I think
> that would be the case with your solution as well.
>
>
> Jacob
>
>
> "Seth Cohen" wrote in message
> news:BB4D15ED1C5913BF17A9282DB6963187@in.WebX.maYIadrTaRb...
> > Jacob,
> >
> > I already tried to make a variant array just of the defs names.
Couldn't
> > get it to work.
> > Just tried to a collection of comp defs. Same problem as with any
> > collection.
> >
> > There's no way to get the index from a variant if I plug in the name I
> want
> > in the array?
> >
> > I posted 2 sections of code that are a mm away from solving this problem
> (in
> > the mcad.mdt5.support ng)
> >
> > Maybe I'll post another message to this ng about dealing with arrays.
> > --
> > --
> > Seth Cohen
> > Group Leader-Design Department
> > Mystaire Division
> > Misonix, Inc.
> > "Jacob Dinardi" wrote in message
> > news:7F857F707BA7DA8A6F72A30BC3B893BF@in.WebX.maYIadrTaRb...
> > > One thought I have is this:
> > >
> > > You could take a one-time hit and create your own collection of
> component
> > > definitions, when you add the objects to it specify their name as the
> key.
> > > You should be able to reference this collection instead, using the
> > standard
> > > myCollection("MyItemKey") syntax.
> > >
> > > Caveat:
> > >
> > > If you create more component definitions you need to update your
> > collection
> > > with the new object. Ugly? Yes. Will it work? I think so!
> > >
> > >
> > > Jacob
> > >
> > >
> > > "Seth Cohen" wrote in message
> > > news:C7202801DC5C4E14C8657F693FACA664@in.WebX.maYIadrTaRb...
> > > > Jacob,
> > > >
> > > > If you don't mind, please check out the mcad.mdt5.support ng. I
> posted
> > > the
> > > > same question there and I think I may have found a sneaky way around
> > this
> > > > frustrating mess.
> > > >
> > > > I basically create another array with just the names, find the name
in
> > > > question in the array, get the index then use the index back in the
> > > > collection. Problem is, how do I get the index from the array
without
> > > going
> > > > through the same mess of For loops? I posted some stuff I tried
this
> > > > morning but I'm still not 100% there.
> > > >
> > > > If you can help that would be great.
> > > >
> > > > Thanks
> > > > --
> > > > --
> > > > Seth Cohen
> > > > Group Leader-Design Department
> > > > Mystaire Division
> > > > Misonix, Inc.
> > > > "Jacob Dinardi" wrote in
> message
> > > > news:D891D24023EA80E24AAE9A6E6CAA8AC4@in.WebX.maYIadrTaRb...
> > > > > If I remember correctly, this is a flaw in the Definitions
> collection.
> > I
> > > > > believe you can NOT directly access a definition by it's name,
only
> by
> > > > > index. (How useful !!). Luckily for me I have not had to refer to
a
> > > > > component definition this way ...so far. There may be an
alternative
> > to
> > > > > iterating the collection and comparing names, however I don't see
it
> > > right
> > > > > now.
> > > > >
> > > > >
> > > > > Regards,
> > > > > Jacob Dinardi
> > > > >
> > > > >
> > > > > "Seth Cohen" wrote in message
> > > > > news:21F8FC13E0684909C5F5131793729C96@in.WebX.maYIadrTaRb...
> > > > > > In MDT5's VBA I have a collection of objects, say mcad
> definitions.
> > > If
> > > > I
> > > > > > want to
> > > > > > access one specific item in the collection I currently have to
> > perform
> > > a
> > > > > For
> > > > > > Loop until it matches the name of the definition in question.
See
> > > > below.
> > > > > >
> > > > > > -------
> > > > > > 'Create collection of all definitions in drawing.
> > > > > > Set oMCADComps = CreateArrayOfComponents(oAssMgr.RootDefinition)
> > > > > >
> > > > > > 'Loop until I find the definition in question.
> > > > > > For j = 0 To oMCADComps.Count - 1
> > > > > > If oMCADComps(j).Definition.Name = "My Special Part"
> > Then
> > > > > > 'Found match
> > > > > > Set oPart=oMCADComps(j).Definition.Body
> > > > > > ... Do the rest of my thing here (about 30
lines)
> > ...
> > > > > > End If
> > > > > > Next j
> > > > > > -----
> > > > > > Why can't I do the following?
> > > > > > Set oPart=oMCADComps("My Special Part").Definition.Body
> > > > > >
> > > > > > In theory it should work, no? Unfortunately it doesn't and I
have
> > to
> > > > > > perform the For Loop for at least 10 parts which means cycling
> > through
> > > > the
> > > > > > oMCADComps (with about 100+ parts) for each part which is taking
a
> > > > > LOOOOOONG
> > > > > > time.
> > > > > >
> > > > > > Any ideas? TIA
> > > > > > --
> > > > > > Seth Cohen
> > > > > > Group Leader-Design Department
> > > > > > Mystaire Division
> > > > > > Misonix, Inc.
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>
0 Likes