Error in code

Error in code

Anonymous
Not applicable
407 Views
2 Replies
Message 1 of 3

Error in code

Anonymous
Not applicable

Hi, everyone,

 

Can someone tell me where is the mistake in following code:

 

Public Sub TestSelection()
   Dim InvDoc As Document
   Set InvDoc = ThisApplication.ActiveDocument

   Dim oPartDoc As PartDocument
   Set oPartDoc = InvDoc.ReferencedDocuments(1)

   Call oPartDoc.Activate
End Sub

 

I have an assembly with two parts inside. I want to activate first of them (like Edit command in browser), but I got message "Method 'Activate' of object 'PartDocument' failed".

0 Likes
Accepted solutions (1)
408 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
Accepted solution

Hi,

 

I hope this will be help you out.

 

Public Sub TestSelection()
Dim InvDoc As Document
Set InvDoc = ThisApplication.ActiveDocument
If InvDoc.DocumentType = kAssemblyDocumentObject Then
Dim oAssyDoc As AssemblyDocument
Set oAssyDoc = ThisApplication.ActiveDocument

Dim oRefDocs As DocumentsEnumerator
Set oRefDocs = oAssyDoc.AllReferencedDocuments
For tt = 1 To oRefDocs.Count
Dim oDoc As Document
Set oDoc = oRefDocs.Item(tt)
If oDoc.DocumentType = kPartDocumentObject Then
Dim oOccEnum As ComponentOccurrencesEnumerator
Set oOccEnum = oAssyDoc.ComponentDefinition.Occurrences.AllReferencedOccurrences(oDoc)
Dim oOcc As ComponentOccurrence
Set oOcc = oOccEnum.Item(1)
Call oOcc.Edit
End If
Next tt
End If
End Sub

 

Message 3 of 3

Anonymous
Not applicable
Thank you very much. I understand now where was mistake. I have to work with occurrences not with documents.

Thanks again.
0 Likes