Count for All Referenced Documents

Count for All Referenced Documents

shastu
Advisor Advisor
473 Views
3 Replies
Message 1 of 4

Count for All Referenced Documents

shastu
Advisor
Advisor

Is there a way to get a count for all the Referenced Documents before it goes into the "For Each" loop?

 

For example:

 

Sub FileRefs()

   Dim oAsmDoc As AssemblyDocument
   Set oAsmDoc = ThisApplication.ActiveDocument
   
   Dim oAsmCompDef As AssemblyComponentDefinition
   Set oAsmCompDef = oAsmDoc.ComponentDefinition

   Dim oOcc As ComponentOccurrence
   Dim oRefDoc As Document
    'MsgBox oRefDoc.Count
   
   For Each oRefDoc In oAsmDoc.AllReferencedDocuments
       MsgBox oRefDoc.DisplayName
    Next
      
End Sub

 

I want to know how many times it is going to go through the For Each loop before I enter into it.  See where the 'MsgBox oRefDoc.Count is?  That is where I need to know.  If I have an assembly with three parts the count should be zero.  If I have a structure and I am interested in the Count for the 123.iam how would I do that in the following Structure:

 

Assy.iam

     Part1.ipt

     Part2.ipt

     123.iam

          Part3.ipt

          Part4.ipt

     Part5.ipt

So the count for 123.iam would be 3.  One for the 123.iam, Part3.ipt, and Part4.ipt

 

Hopefully that makes sense.

0 Likes
474 Views
3 Replies
Replies (3)
Message 2 of 4

Owner2229
Advisor
Advisor

Hi, I can't tell right from the top of my head, but it will be one of these:

oAsmDoc.AllReferencedDocuments.Count

Or:

oAsmDoc.AllReferencedDocuments.Items.Count
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 3 of 4

shastu
Advisor
Advisor

Thanks for the response.  The oAsmDoc.AllReferencedDocuments.Count will give me the total.  I was hoping there was a way that I could get a count for each time it goes to the next level.  In the example given, the number for the oAsmDoc.AllReferencedDocuments.Count would be 6, but what I need is a way to check the count for each level so it would be like this:

 

1

1

3

1

 

So based off your suggestion I tried this:

 

oRefDoc.AllReferencedDocuments.Count

 

and that worked.  Thanks for pointing me in the right direction.

0 Likes
Message 4 of 4

Owner2229
Advisor
Advisor

Alright then, here it is:

 

Sub FileRefs()
   Dim oAsmDoc As AssemblyDocument
   Set oAsmDoc = ThisApplication.ActiveDocument
   
   Dim oAsmCompDef As AssemblyComponentDefinition
   Set oAsmCompDef = oAsmDoc.ComponentDefinition
   Dim oOcc As ComponentOccurrence
   Dim oRefDoc As Document
   
   For Each oRefDoc In oAsmDoc.ReferencedDocuments
       Dim oCount As Integer
       oCount = oRefDoc.AllReferencedDocuments.Count + 1
       MsgBox oCount
   Next
      
End Sub
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes