ApprenticeServer recursive copy

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I'm trying to evaluate an assembly and renamie all the subassemblies, and I'm trying to do it recursively. Here's the code:
______
Public Shared Function CopyAssy(ByVal assyFilePath As String) As String
Dim appServerDocument As Inventor.ApprenticeServerDocument
Dim appFileSaveAs As Inventor.FileSaveAs
appServerDocument = apprenticeServer.Open(assyFilePath)
'Process all the sub assemblies first
For Each refFileDesc As ReferencedFileDescriptor In appServerDocument.ReferencedFileDescriptors
If refFileDesc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
'Recurse
Dim newAssy As String = CopyAssy(refFileDesc.FullFileName)
refFileDesc.PutLogicalFileNameUsingFull(newAssy) 'Fails here - file "newAssy" doesn't exist
End If
Next refFileDesc
'Rename the assy
Dim newAssyNum As String = GetNextAssyNum()
Dim newAssyPath As String = AutoPath(newAssyNum)
If Not My.Computer.FileSystem.DirectoryExists(newAssyPath) Then
My.Computer.FileSystem.CreateDirectory(newAssyPath)
End If
appFileSaveAs = apprenticeServer.FileSaveAs
appFileSaveAs.AddFileToSave(appServerDocument, newAssyPath & newAssyNum & ".iam")
appFileSaveAs.ExecuteSaveAs() 'This line doesn't throw an error, but the file is not copied
appServerDocument.Close()
Return newAssyPath & newAssyNum & ".iam"
End Function
______
The problem is that the subassemblies aren't copied, the line near the end where I call "ExecuteSaveAs" doesn't throw an error, it just doesn't copy the file. Then when the recursive call to CopyAssy returns and I call "PutLogicalFileNameUsingFull", it fails because the file doesn't exist.
Is there anything wrong with doing this kind of thing recursively? Can Apprentice Server have more than one document Open at a time? Any other issues?
Thanks,
Tom