Hello,
We have a custom program that we use to update file references using Apprentice. Once the references are update, we do a file save. However the file save does not work and throws an UnauthorisedAccessException with HResult value of E_ACCESSDENIED whenever the file needs migration.
Can you suggest a way to migrate the files using code?
We are planning on using Inventor to open and save the files, when migration is needed instead of using Apprentice. However we are seeing errors during Inventor file save as well (E_FAIL). Here is a very basic sample that we are using for inventor file save.
public class InventorHelper
{
private Application inventorApp;
public InventorHelper(Application inventorApp)
{
inventorApp = inventorApp;
}
public void OpenAndSaveFile(string fullFilePath)
{
Document file = OpenFile(fullFilePath);
SaveFile(file);
}
public Document OpenFile(string fullFilePath)
{
return inventorApp.Documents.Open(fullFilePath, false);
}
public void SaveFile(Document file)
{
AssemblyDocument doc = (AssemblyDocument)file;
file.Save();
file.Close();
}
}
Solved! Go to Solution.
Solved by Jon.Balgley. Go to Solution.
Hi --
1. Of course, you can use the "Task Scheduler" if you just want to migrate files. But perhaps you have some special requirements.
Here are some other thoughts:
2. For assembly documents, there is the "Save2" method which gives you control over the dependents. Maybe you need to use that? Not sure.
3. If you're saving them to another location (i.e,. if your example code is not representative of your real code), then sometimes there can be problems with "file resolution" for referenced files.
Anyway, it sounds like it is something specific to your files. If you'd like to send me a sample that is failing, you can email it to me at jon.balgley@autodesk.com .
Thanks Jon for your reply.
1) We cannot use Task scheduler, as the migrate needs to happen in my program which updates the assembly references.
2) I tried Save2(), it also a gives the same error.
3) I think this is what might be happening. As I have updated the vault file associations in my code, could that be causing the file resolution errors when saving the file in Inventor. Should I be doing a ReplaceReference in inventor in order to fix the reference again?
http://adndevblog.typepad.com/manufacturing/2016/03/replacereference-vs-filesaveas-vs-onfileresoluti...
Can you please confirm if we can do migration using Apprentice APIs?
Regards,
Deepthi
Please assume it is not possible to use Apprentice to do migration. The doc for FileSaveAs.AddFileToSave is pretty clear when it says, "Please note: Saving of files in Apprentice is not allowed on files that require migration (any file that has not already been migrated to the same version of the Apprentice server). The current document's NeedsMigrating property must return False before the FileSaveAs object can successfully be returned."
If I find out any more information about it, I'll report it here.
Does Inventor Document->Save() or Save2() support migration?
My Inventor Document-Save() is throwing an exception even after I replace references using FileDescriptor->ReplaceReference(). The COMException with HResult E_FAIL does not tell us anything about the error. Is there a way I can get a better error message or error code?
Yes, using the Save or Save2 API from "real" Inventor will migrate the files. In fact, if I understand correctly, your simple example should just work. Just open and save. In full Inventor. Use the Save2 API if you want to control the migration/non-migration of all the children of the assembly. If you have to do any ReplaceReference stuff, etc., then you must be doing something else besides in-place migration. Perhaps try doing the in-place migration by itself, at first (on a copy of a sample assembly).
This proved to be a simple unrelated mistake. The basic open-and-save technique worked fine (we used Save2).
Do you happen to have a sample of how I could add this to an existing VB.Net program? I am trying to migrate files but my program is using apprentice server and it cannot migrate files. I am not much of a programmer but if I get a start, I can usually figure it out. Just to clarify, task scheduler is not a good solution for us. Thanks!