1、1Autodesk Confidential Information January 2010Using ApprenticeGary WassellDeveloper Technical Services2Autodesk Confidential Information January 2010Agenda Apprentice Definition Apprentice Functionalities Guidelines Apprentice vs.Inventor:Differences Saving Files with Apprentice3Autodesk Confidenti
2、al Information January 2010ApprenticeInventor DataInventor ApplicationClient AppAdd-InVBAApprenticeAdd-InClient App4Autodesk Confidential Information January 2010Apprentice ServerApprentice is an ActiveX component.Runs In-process with the client using it.Apprentice Server provides a subset of the In
3、ventor API.Can be used standalone(doesnt require Inventor).Provided at no cost(installed as part of Inventor View).Apprentice can be very efficient for certain tasks in comparison of connecting to Inventor out-of-process.5Autodesk Confidential Information January 2010Apprentice FunctionalitiesProvid
4、es read-only access to:Assembly structureB-RepDrawing sheets and views(limited access)iPartsiAssembliesBOMProvides read/write access to iProperties,attributes,and file references.6Autodesk Confidential Information January 2010Apprentice-GuidelinesShould NOT be used in-process to Inventor.Not in an A
5、dd-In(exe type of Add-In is ok).Not through Inventors VBA.Prior to Inventor 11,Apprentice was the only way to edit file references.(Design Assistant is build on top of Apprentice.)Prior to 2008,the Apprentice functionalities were provided in its own type library.Now Autodesk Inventor type library co
6、ntains all of the Apprentice functionality Add a reference to Inventor.Interop for an Apprentice project.7Autodesk Confidential Information January 2010Apprentice vs.Inventor:differencesInstantiated using“new ApprenticeServerComponent”No Documents collection in ApprenticeDocument object:ApprenticeSe
7、rverDocument(*.ipt&*.iam)ApprenticeServerDrawingDocument(*.idw)Apprentice cannot save a file from a previous version,i.e.that is not migrated.You will need to migrate the file prior to save it with Apprentice:To migrate a file,open it with Inventor,save it and close it.8Autodesk Confidential Informa
8、tion January 2010Apprentice-ExamplePrivate Sub ApprenticeSample()Create Apprentice.Dim oApprentice As ApprenticeServerComponent oApprentice=New ApprenticeServerComponent Open a document.Dim oDoc As ApprenticeServerDocument oDoc=oApprentice.Open(C:TempPart.ipt)MsgBox(Opened:&oDoc.DisplayName)End Sub9
9、Autodesk Confidential Information January 2010Saving Files with ApprenticeUse FlushToFile if the iProperties ONLY were modified:more efficient,since the document is not written back.Private Sub SetProperty(ByVal author As String)Dim oApprenticeDoc As ApprenticeServerDocument oApprenticeDoc=mApprenti
10、ceServer.Open(c:TempMyPart.ipt)Get Inventor Summary Information PropertySet Dim oPropertySet As PropertySet oPropertySet=oApprenticeDoc.PropertySets(F29F85E0-4FF9-1068-AB91-08002B27B3D9)Get Author property Dim oProperty As Inventor.Property=oPropertySet.Item(Author)oProperty.Value=author oApprentice
11、Doc.PropertySets.FlushToFile()oApprenticeDoc.Close()End Sub10Autodesk Confidential Information January 2010Saving Files with ApprenticeFor any other change use FileSaveAs object:Private Sub SaveFileSample()Dim oApprentice As New ApprenticeServerComponent Open a document.Dim oDoc As ApprenticeServerD
12、ocument oDoc=oApprentice.Open(C:TempAssembly1.iam)Do some change:iProperties and attributes and/or file references.Set a reference to the FileSaveAs object.Dim oFileSaveAs As FileSaveAs oFileSaveAs=oApprentice.FileSaveAs Save the file.Call oFileSaveAs.AddFileToSave(oDoc,oDoc.FullFileName)Call oFileSaveAs.ExecuteSave()End Sub11Autodesk Confidential Information January 2010






