Using Apprentice rather than Inventor

Using Apprentice rather than Inventor

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

Using Apprentice rather than Inventor

Anonymous
Not applicable

I've got a VBA macro in Inventor that includes iterating through all documents reference by an assembly, and appears to work well.  The relevant bit of code is

 

Dim oAsmDoc As AssemblyDocument
Set oAsmDoc = ThisApplication.ActiveDocument

 

Dim oRefDocs As DocumentsEnumerator
Set oRefDocs = oAsmDoc.AllReferencedDocuments
Dim oRefDoc As Document

 

For Each oRefDoc In oRefDocs

........

Next

 

I'm trying to do the same thing with Apprentice via VB6 using this code

 

Dim oApprentice As New ApprenticeServerComponent
Dim assyDoc As ApprenticeServerDocument
Set assyDoc = oApprentice.Open(fname)

 

Dim oRefFile As ApprenticeServerDocument
For Each oRefFile In assyDoc.ReferencedDocuments

......

Next

 

It partially works, but whereas the IV code lists documents below a referenced assembly, the Apprentice code doesn't.

 

Clearly the Apprentice code is wrong.

Guidance would be appreciated.

0 Likes
1,005 Views
7 Replies
Replies (7)
Message 2 of 8

Mike.Wohletz
Collaborator
Collaborator

You have it so far, the only thing that you need in addition to doing this in Inventor is the referenced document needs to now be opened by apprentice to do anything with it. I have attached a sample in .NET that is very close to the same thing you have going for you to look at.

 

   Public Sub apprenticeOpen(ByVal oDoc As String) Dim oApp As New ApprenticeServerComponent Dim assyDoc As ApprenticeServerDocument = oApp.Open(oDoc) For Each oRefDocs As ApprenticeServerDocument In assyDoc.AllReferencedDocuments Dim oRefDoc As ApprenticeServerDocument = oApp.Open(oRefDocs.FullDocumentName) 'now do something with the oRefDoc Next End Sub

 

0 Likes
Message 3 of 8

Anonymous
Not applicable

The third line in the Apprentice code I posted opens the file.

 

My problem is that if my top level assembly references sub-assemblies the Apprentice code doesn't 'drill down' to the flies referenced by the sub-assemblies.  With my IV macro this happens.

 

This is quite important to us as we are looking to release a seat of IV (and the draughtsmans time) from the routine of generating a 'pack' of pdf versions of IV idw's that are to be sent to sub-contractors.

In his last 'state of the company' address our MD said "we must control functional costs".

0 Likes
Message 4 of 8

Anonymous
Not applicable

Sorry Mike, I misunderstood what you were saying first time round.

 

If I create a sub and then call this sub every time I encounter an assembly drawing then I can 'drill down' to ALL parts however deep.

 

Thanks

 

Peter

0 Likes
Message 5 of 8

Mike.Wohletz
Collaborator
Collaborator

The difference is that in Inventor when you open a assembly you have alll the parts associated open as well and you just go through them, in apprentice when you open the assembly that is all that you have open and when you want its referenced items you have to open them up one at a time. Please don't forget to close and dispose of the apprentice server and the documents as I did not include that part in my code.

 

0 Likes
Message 6 of 8

Anonymous
Not applicable

Thank you for the additional information.  Where is the best source of information on using Apprentice, what are it's limitations etc. and could you expand on your comments -

 

Please don't forget to close and dispose of the apprentice server and the documents 

0 Likes
Message 7 of 8

Mike.Wohletz
Collaborator
Collaborator

I do not have a good source for additional information other than the sample code supplied with the SDK. This has some good info to look over and you will also find a tiny bit of information in the Programming help in Inventor.  I would like to have a full list of limitations but I also do not have that, I do know that it works great for getting and setting properties and viewing parts. One of my favorite things with apprentice is the ability to copy entire assemblies and all the referenced parts to make another almost the same. The only info I can give on limits is that it cannot run from inside an add-in and it can cause problems if the files need migrating.

To explain my code I have added the closing and also added what to do if you have more than one assembly deep etc.

 

Public Class AppreenticeApplication
    Private oApp As ApprenticeServerComponent
    Public Sub apprenticeOpen(ByVal oDoc As String)
        oApp = New ApprenticeServerComponent
        Dim assyDoc As ApprenticeServerDocument = oApp.Open(oDoc)
        If assyDoc.NeedsMigrating Then
            MsgBox(String.Format("{0} needs migrating before it can be processed", assyDoc.FullDocumentName), MsgBoxStyle.Critical)
            Exit Sub
        End If
        For Each oRefDocs As ApprenticeServerDocument In assyDoc.AllReferencedDocuments
            Dim oRefDoc As ApprenticeServerDocument = oApp.Open(oRefDocs.FullDocumentName)
            If oRefDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
                apprenticeOpen(oRefDoc.FullDocumentName)
            End If
            'now do something with the oRefDoc  
            oRefDoc.Close()
        Next
        assyDoc.Close()
        oApp.Close()
        oApp = Nothing
    End Sub
End Class

 

 

 

0 Likes
Message 8 of 8

Anonymous
Not applicable

Thank you for your additional guidance.

0 Likes