ReferencedFileDescriptors

ReferencedFileDescriptors

Anonymous
Not applicable
1,097 Views
7 Replies
Message 1 of 8

ReferencedFileDescriptors

Anonymous
Not applicable
Hey All,

I'm trying to get a list of all files associated with an IDW or and IAM.

Basically what I want to do is select a drawing file and get a list of all files that are in that reference and stuff the results into a list.

The code I have only works a little bit.
If my drawing references an assembly and that assembly has two components the result I get is the assembly idw, the assembly iam and one of the two parts in the assembly. And then it exits out of the sub.

I'm not sure I'm even going about this the correct way.

I want it to work like Design Assistant where you can pick the top level of an IDW and get all teh children.

Lots of thanks in advance for any assistance you can provide.

AllenG


Private Sub FileRef(FileName As String)

Dim oApprentice As ApprenticeServerComponent
Dim oDoc As ApprenticeServerDocument
Dim ReferencedFileDescriptor As ApprenticeServerComponent
Dim oRefFileDesc As ReferencedFileDescriptor
Set oApprentice = New ApprenticeServerComponent
Set oDoc = oApprentice.Open(FileName)
Set oRefFileDesc = oDoc.ReferencedFileDescriptors(1)

MsgBox oDoc.ReferencedFiles.Count

For Each oRefFileDesc In oDoc.ReferencedFileDescriptors

Form1.lstAvailableFiles.AddItem oRefFileDesc.FullFileName

Call FileRef(oRefFileDesc.FullFileName)


Next oRefFileDesc


Set oRefFileDesc = Nothing
Set oApprentice = Nothing
Set oDoc = Nothing


End Sub
0 Likes
1,098 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable
One easy option is to use ApprenticeServerDocument.AllReferencedDocuments.
This returns a flat list of all documents (direct and nested) that are
referenced. However, the limitation is that if any of the referenced
documents are missing, the property doesn't return any information regarding
that. This is where the file descriptors come in. If you don't care about
missing references, use the AllReferencedDocuments property. Else, you will
need to iteratively recurse thru the descriptors at every level.

Sanjay-


wrote in message news:5206611@discussion.autodesk.com...
Hey All,

I'm trying to get a list of all files associated with an IDW or and IAM.

Basically what I want to do is select a drawing file and get a list of all
files that are in that reference and stuff the results into a list.

The code I have only works a little bit.
If my drawing references an assembly and that assembly has two components
the result I get is the assembly idw, the assembly iam and one of the two
parts in the assembly. And then it exits out of the sub.

I'm not sure I'm even going about this the correct way.

I want it to work like Design Assistant where you can pick the top level of
an IDW and get all teh children.

Lots of thanks in advance for any assistance you can provide.

AllenG


Private Sub FileRef(FileName As String)

Dim oApprentice As ApprenticeServerComponent
Dim oDoc As ApprenticeServerDocument
Dim ReferencedFileDescriptor As ApprenticeServerComponent
Dim oRefFileDesc As ReferencedFileDescriptor
Set oApprentice = New ApprenticeServerComponent
Set oDoc = oApprentice.Open(FileName)
Set oRefFileDesc = oDoc.ReferencedFileDescriptors(1)

MsgBox oDoc.ReferencedFiles.Count

For Each oRefFileDesc In oDoc.ReferencedFileDescriptors

Form1.lstAvailableFiles.AddItem oRefFileDesc.FullFileName

Call FileRef(oRefFileDesc.FullFileName)


Next oRefFileDesc


Set oRefFileDesc = Nothing
Set oApprentice = Nothing
Set oDoc = Nothing


End Sub
0 Likes
Message 3 of 8

Anonymous
Not applicable
Thank You Sanjay,

Could you please provide a code sample to do this? I ran across a similar mention of this from Brian Ekins, But I didn't understand how to accomplish this. In this case, I'm not concerned about the missing references.

Thank You,

AllenG
0 Likes
Message 4 of 8

Anonymous
Not applicable
I've modified your code, but haven't done any testing on this:

Private Sub FileRef(FileName As String)

Dim oApprentice As ApprenticeServerComponent
Set oApprentice = New ApprenticeServerComponent

Dim oDoc As ApprenticeServerDocument
Set oDoc = oApprentice.Open(FileName)

MsgBox oDoc.AllReferencedDocuments.Count

Dim oRefDoc As ApprenticeServerDocument
For Each oRefDoc In oDoc.AllReferencedDocuments

Form1.lstAvailableFiles.AddItem oRefDoc.FullFileName

Next

Set oDoc = Nothing
Set oApprentice = Nothing

End Sub

Sanjay-

wrote in message news:5206879@discussion.autodesk.com...
Thank You Sanjay,

Could you please provide a code sample to do this? I ran across a similar
mention of this from Brian Ekins, But I didn't understand how to accomplish
this. In this case, I'm not concerned about the missing references.

Thank You,

AllenG
0 Likes
Message 5 of 8

Anonymous
Not applicable
What do I do if i want to count how many of each patrs (and assemblyes)
there is... (need to make a complete partslist, with filenames)

Lasse

"Sanjay Ramaswamy (Autodesk)" skrev i en
meddelelse news:5207980@discussion.autodesk.com...
I've modified your code, but haven't done any testing on this:

Private Sub FileRef(FileName As String)

Dim oApprentice As ApprenticeServerComponent
Set oApprentice = New ApprenticeServerComponent

Dim oDoc As ApprenticeServerDocument
Set oDoc = oApprentice.Open(FileName)

MsgBox oDoc.AllReferencedDocuments.Count

Dim oRefDoc As ApprenticeServerDocument
For Each oRefDoc In oDoc.AllReferencedDocuments

Form1.lstAvailableFiles.AddItem oRefDoc.FullFileName

Next

Set oDoc = Nothing
Set oApprentice = Nothing

End Sub

Sanjay-

wrote in message news:5206879@discussion.autodesk.com...
Thank You Sanjay,

Could you please provide a code sample to do this? I ran across a similar
mention of this from Brian Ekins, But I didn't understand how to accomplish
this. In this case, I'm not concerned about the missing references.

Thank You,

AllenG
0 Likes
Message 6 of 8

Anonymous
Not applicable
Traversing the documents as in the code below will only give you the file
structure. In order to get the assembly structure (complete BOM
information), you'll need to traverse the ComponentOccurrence hierarchy.
Start with the Occurrences collection at the top level and recursively
iterate thru all sub-occurrences until you reach the leaf (Programming Help
has a few samples). Also, any reason why you don't want to access the bill
of materials thru the BOM APIs (introduced in R10)?

Sanjay-


"Lasse Frederiksen" wrote in message
news:5218376@discussion.autodesk.com...
What do I do if i want to count how many of each patrs (and assemblyes)
there is... (need to make a complete partslist, with filenames)

Lasse

"Sanjay Ramaswamy (Autodesk)" skrev i en
meddelelse news:5207980@discussion.autodesk.com...
I've modified your code, but haven't done any testing on this:

Private Sub FileRef(FileName As String)

Dim oApprentice As ApprenticeServerComponent
Set oApprentice = New ApprenticeServerComponent

Dim oDoc As ApprenticeServerDocument
Set oDoc = oApprentice.Open(FileName)

MsgBox oDoc.AllReferencedDocuments.Count

Dim oRefDoc As ApprenticeServerDocument
For Each oRefDoc In oDoc.AllReferencedDocuments

Form1.lstAvailableFiles.AddItem oRefDoc.FullFileName

Next

Set oDoc = Nothing
Set oApprentice = Nothing

End Sub

Sanjay-

wrote in message news:5206879@discussion.autodesk.com...
Thank You Sanjay,

Could you please provide a code sample to do this? I ran across a similar
mention of this from Brian Ekins, But I didn't understand how to accomplish
this. In this case, I'm not concerned about the missing references.

Thank You,

AllenG
0 Likes
Message 7 of 8

Anonymous
Not applicable
I need to make this from a standalone appication, and as far as i can see,
the BOM API only works from inside IV....

I've tried the ComponentOccurrence, but sometimes it fails finding the
fullfilename:



Private Sub oGetComponents(InCollection As ComponentOccurrences, olevel As
String)

Dim objCompOccurrence As ComponentOccurrence
For Each objCompOccurrence In InCollection
Rename_Server.Label1.Caption = objCompOccurrence.Name
DoEvents
'On Error Resume Next
Rename_Server.List1.AddItem
objCompOccurrence.DefinitionReference.ReferencedFileDescriptor.FullFileName
'''here it fails
DoEvents
Call
Search_tree(objCompOccurrence.DefinitionReference.ReferencedFileDescriptor.FullFileName,
olevel)
'recursively call this function for the suboccurrences of the
current component
'On Error Resume Next
If
objCompOccurrence.DefinitionReference.ReferencedFileDescriptor.DocumentType
= kAssemblyDocumentObject Then
Call oGetComponents(objCompOccurrence.SubOccurrences,
objCompOccurrence.DefinitionReference.ReferencedFileDescriptor.FullFileName)
End If
'On Error GoTo 0
Next
End sub

It's not every time but it seems like it when it comes back from a
subassembly...

Lasse

"Sanjay Ramaswamy (Autodesk)" skrev i en
meddelelse news:5218932@discussion.autodesk.com...
Traversing the documents as in the code below will only give you the file
structure. In order to get the assembly structure (complete BOM
information), you'll need to traverse the ComponentOccurrence hierarchy.
Start with the Occurrences collection at the top level and recursively
iterate thru all sub-occurrences until you reach the leaf (Programming Help
has a few samples). Also, any reason why you don't want to access the bill
of materials thru the BOM APIs (introduced in R10)?

Sanjay-


"Lasse Frederiksen" wrote in message
news:5218376@discussion.autodesk.com...
What do I do if i want to count how many of each patrs (and assemblyes)
there is... (need to make a complete partslist, with filenames)

Lasse

"Sanjay Ramaswamy (Autodesk)" skrev i en
meddelelse news:5207980@discussion.autodesk.com...
I've modified your code, but haven't done any testing on this:

Private Sub FileRef(FileName As String)

Dim oApprentice As ApprenticeServerComponent
Set oApprentice = New ApprenticeServerComponent

Dim oDoc As ApprenticeServerDocument
Set oDoc = oApprentice.Open(FileName)

MsgBox oDoc.AllReferencedDocuments.Count

Dim oRefDoc As ApprenticeServerDocument
For Each oRefDoc In oDoc.AllReferencedDocuments

Form1.lstAvailableFiles.AddItem oRefDoc.FullFileName

Next

Set oDoc = Nothing
Set oApprentice = Nothing

End Sub

Sanjay-

wrote in message news:5206879@discussion.autodesk.com...
Thank You Sanjay,

Could you please provide a code sample to do this? I ran across a similar
mention of this from Brian Ekins, But I didn't understand how to accomplish
this. In this case, I'm not concerned about the missing references.

Thank You,

AllenG
0 Likes
Message 8 of 8

Anonymous
Not applicable
You can use BOM APIs from a standalone application accessing Inventor (there
is no difference between accessing Inventor APIs in-process or
out-of-process from Inventor except the performance). Also, BOM APIs are
also accessible from Apprentice since R10 SP2.

For iterating thru ComponentOccurrences look at the "Assembly Count
Occurrences" sample in programming help. Also, you are using obsolete APIs
in the code below (ComponentOccurrence.DefinitionReference is hidden and not
supported).

Sanjay-


"Lasse Frederiksen" wrote in message
news:5219688@discussion.autodesk.com...
I need to make this from a standalone appication, and as far as i can see,
the BOM API only works from inside IV....

I've tried the ComponentOccurrence, but sometimes it fails finding the
fullfilename:



Private Sub oGetComponents(InCollection As ComponentOccurrences, olevel As
String)

Dim objCompOccurrence As ComponentOccurrence
For Each objCompOccurrence In InCollection
Rename_Server.Label1.Caption = objCompOccurrence.Name
DoEvents
'On Error Resume Next
Rename_Server.List1.AddItem
objCompOccurrence.DefinitionReference.ReferencedFileDescriptor.FullFileName
'''here it fails
DoEvents
Call
Search_tree(objCompOccurrence.DefinitionReference.ReferencedFileDescriptor.FullFileName,
olevel)
'recursively call this function for the suboccurrences of the
current component
'On Error Resume Next
If
objCompOccurrence.DefinitionReference.ReferencedFileDescriptor.DocumentType
= kAssemblyDocumentObject Then
Call oGetComponents(objCompOccurrence.SubOccurrences,
objCompOccurrence.DefinitionReference.ReferencedFileDescriptor.FullFileName)
End If
'On Error GoTo 0
Next
End sub

It's not every time but it seems like it when it comes back from a
subassembly...

Lasse

"Sanjay Ramaswamy (Autodesk)" skrev i en
meddelelse news:5218932@discussion.autodesk.com...
Traversing the documents as in the code below will only give you the file
structure. In order to get the assembly structure (complete BOM
information), you'll need to traverse the ComponentOccurrence hierarchy.
Start with the Occurrences collection at the top level and recursively
iterate thru all sub-occurrences until you reach the leaf (Programming Help
has a few samples). Also, any reason why you don't want to access the bill
of materials thru the BOM APIs (introduced in R10)?

Sanjay-


"Lasse Frederiksen" wrote in message
news:5218376@discussion.autodesk.com...
What do I do if i want to count how many of each patrs (and assemblyes)
there is... (need to make a complete partslist, with filenames)

Lasse

"Sanjay Ramaswamy (Autodesk)" skrev i en
meddelelse news:5207980@discussion.autodesk.com...
I've modified your code, but haven't done any testing on this:

Private Sub FileRef(FileName As String)

Dim oApprentice As ApprenticeServerComponent
Set oApprentice = New ApprenticeServerComponent

Dim oDoc As ApprenticeServerDocument
Set oDoc = oApprentice.Open(FileName)

MsgBox oDoc.AllReferencedDocuments.Count

Dim oRefDoc As ApprenticeServerDocument
For Each oRefDoc In oDoc.AllReferencedDocuments

Form1.lstAvailableFiles.AddItem oRefDoc.FullFileName

Next

Set oDoc = Nothing
Set oApprentice = Nothing

End Sub

Sanjay-

wrote in message news:5206879@discussion.autodesk.com...
Thank You Sanjay,

Could you please provide a code sample to do this? I ran across a similar
mention of this from Brian Ekins, But I didn't understand how to accomplish
this. In this case, I'm not concerned about the missing references.

Thank You,

AllenG
0 Likes