Getting "Document" from "Occurrence"

Getting "Document" from "Occurrence"

Anonymous
Not applicable
3,412 Views
8 Replies
Message 1 of 9

Getting "Document" from "Occurrence"

Anonymous
Not applicable
Hi,

I have a typical problem: I know that there is enough code in the SDK and on this forum for traversing an Assembly using "Occurrences" and "SubOccurrences" , but I would like to know if it can be done differently. I would like to know if after getting a particular "Occurrence" I can convert it into an "Document" - If so how? To explain my point, I am putting some comments ('''' DIFFERENT WAY ) in the usual sample code below:

Public Sub AssemblyTraversal()
' Get the active document, assuming it's an assembly.
Dim oAsmDoc As AssemblyDocument
Set oAsmDoc = ThisApplication.ActiveDocument

' Begin the assembly traversal.
Call TraverseAsm(oAsmDoc.ComponentDefinition.Occurrences, 1)
End Sub

' The Level argument is used to control the amount of indent for the output.
Private Sub TraverseAsm(oOccurrences As ComponentOccurrences, Level As Integer)

' Iterate through the current list of occurrences.
Dim oOcc As ComponentOccurrence

For Each oOcc In oOccurrences

' Print the name of the current occurence.
Debug.Print Space(Level * 3) & oOcc.Name

'''' DIFFERENT WAY
' HOW Can one get Document Object out of the "oOcc " object here

' If the current occurrence is a subassembly then call this sub
' again passing in the collection for the current occurrence.
If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then
Call TraverseAsm(oOcc.SubOccurrences, Level + 1)
End If
Next
End Sub
0 Likes
3,413 Views
8 Replies
Replies (8)
Message 2 of 9

Anonymous
Not applicable
Why do you want to "convert" it to a "Document"? What you do want to
accomplish?

Try "oOcc.Definition.Document.FullFileName" and use it to open that
occurence.

--
T. Ham
Mechanical Engineer
CDS Engineering BV

Dual Pentium XEON 2.2 Ghz
2 GB SDRAM
NVIDIA QUADRO4 700 XGL (Driver = 77.18)
18 GB SEAGATE SCSI Hard Disc
3Com Gigabit NIC

Windows 2000 Professional SP4
Autodesk Inventor Series 9 SP4
Autodesk Inventor Series 10 SP2
--

wrote in message news:5013541@discussion.autodesk.com...
Hi,

I have a typical problem: I know that there is enough code in the SDK and on
this forum for traversing an Assembly using "Occurrences" and
"SubOccurrences" , but I would like to know if it can be done differently. I
would like to know if after getting a particular "Occurrence" I can convert
it into an "Document" - If so how? To explain my point, I am putting some
comments ('''' DIFFERENT WAY ) in the usual sample code below:

Public Sub AssemblyTraversal()
' Get the active document, assuming it's an assembly.
Dim oAsmDoc As AssemblyDocument
Set oAsmDoc = ThisApplication.ActiveDocument

' Begin the assembly traversal.
Call TraverseAsm(oAsmDoc.ComponentDefinition.Occurrences, 1)
End Sub

' The Level argument is used to control the amount of indent for the output.
Private Sub TraverseAsm(oOccurrences As ComponentOccurrences, Level As
Integer)

' Iterate through the current list of occurrences.
Dim oOcc As ComponentOccurrence

For Each oOcc In oOccurrences

' Print the name of the current occurence.
Debug.Print Space(Level * 3) & oOcc.Name

'''' DIFFERENT WAY
' HOW Can one get Document Object out of the "oOcc " object here

' If the current occurrence is a subassembly then call this sub
' again passing in the collection for the current occurrence.
If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then
Call TraverseAsm(oOcc.SubOccurrences, Level + 1)
End If
Next
End Sub
0 Likes
Message 3 of 9

Anonymous
Not applicable
I have written a function(TraverseDoc() ) which takes the generic "Document" as parameter to traverse it's subcomponents. Hence, after getting an "occurrence", I would like to get it's "Document" object and pass it as an argument to TraverseDoc().

Thanks for the information ,though -- I will definitely try opening the "occurrence" - but on after thoughts will it not be an costly operation.

Regards,
Amol
0 Likes
Message 4 of 9

Anonymous
Not applicable
If you want to know if the occurence is a part or assembly document, try
this:

If oOcc.DefinitionDocumentType = kPartDocumentObject Then
Debug.Print Space(Level * 3) & oOcc.Name & " is a Part Document"
ElseIf oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then
Debug.Print Space(Level * 3) & oOcc.Name & " is an Assembly
Document"
Else
Debug.Print Space(Level * 3) & oOcc.Name & " is not a Part or an
Assembly Document"
End If

--
T. Ham
Mechanical Engineer
CDS Engineering BV

Dual Pentium XEON 2.2 Ghz
2 GB SDRAM
NVIDIA QUADRO4 700 XGL (Driver = 77.18)
18 GB SEAGATE SCSI Hard Disc
3Com Gigabit NIC

Windows 2000 Professional SP4
Autodesk Inventor Series 9 SP4
Autodesk Inventor Series 10 SP2
--

wrote in message news:5013584@discussion.autodesk.com...
I have written a function(TraverseDoc() ) which takes the generic "Document"
as parameter to traverse it's subcomponents. Hence, after getting an
"occurrence", I would like to get it's "Document" object and pass it as an
argument to TraverseDoc().

Thanks for the information ,though -- I will definitely try opening the
"occurrence" - but on after thoughts will it not be an costly operation.

Regards,
Amol
0 Likes
Message 5 of 9

Anonymous
Not applicable
Thanks Ham for the information.

I discovered another way to access the generic document type, which is as below:

<>
CComPtr pCurrOccurrence;
hr = pComponentOcuurences->get_Item(lOccurenceCount, &pCurrOccurrence);

CComPtr pComponentDefOfOcc;
hr = pCurrOccurrence->get_Definition(&pComponentDefOfOcc);

LPDISPATCH pDispCurrDocument;
//Get the generic "Documetnt" type using the get_Document AAPI
pComponentDefOfOcc->get_Document(&pDispCurrDocument);

DocumentPtr pCurrentDocument = pDispCurrDocument;//type-cast if needed by (Document*)
hr = pCurrentDocument->get_DocumentType(&tempDocumentTypeEnum);

<>

Will there be an overhead in this way of accessing the Document. I feel if I open the Document from the fullName of Occurrence, then it will be more taxing as compared to this appraoch.Can you please let me know your views.

TIA,

Regards,
Amol
0 Likes
Message 6 of 9

Anonymous
Not applicable
In VB this is:



For Each oOcc In oOccurrences

Dim oCompDef as ComponentDefinition
Dim oDocument as Document

Set oCompDef = oOcc.Definition
Set oDocument = oCompDef.Document

' check the type of the document
If oOcc.DefinitionDocumentType = kPartDocumentObject

Dim oPartDoc as PartDocument
Set oPartDoc = oDocument

' do something useful here

End If

Next oOcc
0 Likes
Message 7 of 9

Anonymous
Not applicable
If you just want a document dependency tree then you don't need to use
occurrences at all. There are two different approaches depending on what
you need. In the first approach will result in a tree of all of the
documents that are currently loaded. For example, if when you opened an
assembly and it isn't able to find a part a dialog pops up asking the user
to find or they choose to skip that file. If they skip the file then it
won't show up in the tree.

In the second approach it will show files whether they were able to load or
not, with one limitation. If an assembly is not able to load then you won't
be able to determine what would have been in that assembly. Both approaches
work with the general Document object.

In the first approach you'll use the ReferencedFiles property of the
Document objet. This returns a collection of the Document objects
referenced by the document you call the property on. You can recurse
through these documents to get a full tree. If a document doesn't reference
another document, which is common for parts, then the collection will be
empty (the Count will be 0).

In the second approach you'll use the ReferencedFileDescriptors property of
the Document object. This returns a collection of object that represent the
description of a reference. This exists whether or not the actual reference
could be made. You can use the ReferenceStatus property of the object to
determine if the reference to the other document was actually made. If it
was then you use the ReferencedDocument property of the
ReferencedFileDescriptor object to get the referenced document. You can
continue the recursive traversal using this approach to create the full
tree.
--
Brian Ekins
Autodesk Consulting

wrote in message news:5013584@discussion.autodesk.com...
I have written a function(TraverseDoc() ) which takes the generic "Document"
as parameter to traverse it's subcomponents. Hence, after getting an
"occurrence", I would like to get it's "Document" object and pass it as an
argument to TraverseDoc().

Thanks for the information ,though -- I will definitely try opening the
"occurrence" - but on after thoughts will it not be an costly operation.

Regards,
Amol
0 Likes
Message 8 of 9

Anonymous
Not applicable
Brian Thank you for the descriptive illustration.

I appreciate the logic provided by you to traverse an Assembly structure. But, I find one anomaly in that approach - this approach, of traversing Assembly through "ReferencedFiles" or through "ReferencedFileDescriptors" API (and Objects) will not give be information of shared components. For e.g. if I have a Assembly which contains a Part document inserted in it two times, then this logic gives me only one Part Document ( I wrote a small utility for this to verify this). Further, I will not be able to get the transformation matrix of the Part document using this appraoch( I need to verify this once programmatically). Do you feel, using the approach (as mentioned by you) has some scope of getting the count of of the shared parts/ sub-assembly (components). Is there a way in this appraoch to get the transformation matrix.

I am in the process of writing a generic utility to get all the dependencies. Will let you know my logic, once I am done with that.

By any chance, is there a document avaible (not necessarily API / programming) that illustrates different kind of relationships that exists between different kind of Inventor Files. Also, if there is parallel API/programming related document which illustrates the relationships between Inventor files then it will be easy for me to get the complete picture.

Thanks and Regards,
Amol
0 Likes
Message 9 of 9

Anonymous
Not applicable
I was under the impression that you just cared about the document
references, not the occurrences. There is another collection that gives you
a combination of document and occurrence information. This is the
ImmediateReferencedDefinitions property of the AsssemblyComponentDefinition.
This returns a ComponentDefinitionReferences collection. Each item in this
collection corresponds to a document being referenced. From each of the
ComponentDefinitionReference objects you can get the list of occurrences
that use that reference using its ImmediateOccurrences property.
--
Brian Ekins
Autodesk Consulting


wrote in message news:5015794@discussion.autodesk.com...
Brian Thank you for the descriptive illustration.

I appreciate the logic provided by you to traverse an Assembly structure.
But, I find one anomaly in that approach - this approach, of traversing
Assembly through "ReferencedFiles" or through "ReferencedFileDescriptors"
API (and Objects) will not give be information of shared components. For
e.g. if I have a Assembly which contains a Part document inserted in it two
times, then this logic gives me only one Part Document ( I wrote a small
utility for this to verify this). Further, I will not be able to get the
transformation matrix of the Part document using this appraoch( I need to
verify this once programmatically). Do you feel, using the approach (as
mentioned by you) has some scope of getting the count of of the shared
parts/ sub-assembly (components). Is there a way in this appraoch to get the
transformation matrix.

I am in the process of writing a generic utility to get all the
dependencies. Will let you know my logic, once I am done with that.

By any chance, is there a document avaible (not necessarily API /
programming) that illustrates different kind of relationships that exists
between different kind of Inventor Files. Also, if there is parallel
API/programming related document which illustrates the relationships between
Inventor files then it will be easy for me to get the complete picture.

Thanks and Regards,
Amol
0 Likes