Looking for a FileSaveAs object primer.

Looking for a FileSaveAs object primer.

Anonymous
Not applicable
525 Views
2 Replies
Message 1 of 3

Looking for a FileSaveAs object primer.

Anonymous
Not applicable

I am using Inventor Apprentice 2011 and VB.Net 2010.

 

I am trying to use the FileSaveAs object in a loop that will save copies of a number of files

 

--- Pseudo Code ---

Create oFileSaveAs Object.

For n = 0 to 100

  oFileSaveAs.AddFileToSave(oDoc(n), NewPath \ NewName(n))

Next

oFileSaveAs.ExecuteSaveCopyAs()

--- End Pseudo Code ---

 

Only one document is copied.

I was under the impression that more that one document could be added and all documents added would be copied.

 

Is there better documentation on this process?

0 Likes
526 Views
2 Replies
Replies (2)
Message 2 of 3

leefsma
Contributor
Contributor

Hi Gruff,

 

Multiple files can be saved through Apprentice. Below is a VB.Net example that illustrates how to save a copy of an assembly and its dependencies under a new location. This code also handles replacement of references automatically.

 

Private Sub Save(ByVal FullFilename As String, ByVal newFolder As String, ByVal prefix As String, ByVal suffix As String)

        Dim doc As Inventor.ApprenticeServerDocument = mApprenticeApp.Open(FullFilename)

        SaveRec(newFolder, doc, prefix, suffix)
        mApprenticeApp.FileSaveAs.ExecuteSaveCopyAs()

        doc.Close()

    End Sub

    Private Function newFileName(ByVal prefix As String, ByVal fullFileName As String, ByVal suffix As String) As String

        Dim fileInfo As New IO.FileInfo(fullFileName)
        Return prefix + fileInfo.Name.Substring(0, fileInfo.Name.Length - 4) + suffix + fileInfo.Extension

    End Function

    Private Sub SaveRec(ByRef NewFolder As String, ByRef doc As Inventor.ApprenticeServerDocument, ByVal prefix As String, ByVal suffix As String)

        Dim newFullFilename As String = NewFolder + newFileName(prefix, doc.FullFileName, suffix)

        Try
            mApprenticeApp.FileSaveAs.AddFileToSave(doc, newFullFilename)

            For Each refDoc As Inventor.ApprenticeServerDocument In doc.ReferencedDocuments
                SaveRec(NewFolder, refDoc, prefix, suffix)
            Next

        Catch ex As Exception
            'Content Center Parts will fail
            'System.Windows.Forms.MessageBox.Show(ex.Message, "Exception")
        End Try

    End Sub

 

 

Philippe Leefsma
Developer Consultant
Developer Technical Services
Global Subscription & Support
 

Autodesk EMEA

 

www.autodesk.com/joinadn

 

0 Likes
Message 3 of 3

Anonymous
Not applicable

Thank you for the response leefsma,

 

Perhaps that is what I've been doing wrong.  I've been creating an instance of the FileSaveAs class and using that.

 

On another note.  I am having trouble repointing the file references after copying the files.

I've not had success using the ReferencedFileDescriptor object

 

For Each oDesc As Inventor.ReferencedFileDescriptor In oDwg.ReferencedFileDescriptors 

 '...

  oDesc.PutLogicalFileNameUsingFull(NewFullName)

Next

 

Is there some method that I need to use to cause the changes to take affect?

0 Likes