Message 1 of 20
Changing projects; VBA vs. manual
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Summary: I find that changing the project (*.ipj) within a VBA macro results in errors that don't occur when i change manually (by way of the Project manager).
The situation:
- For every client project there is a unique Inventor project file;
- A collection of 'standards', assy with drawing, to be copied to a project and modified there;
- Inventor (and Vault Basic) 2015.
I have a elaborate 'copy design' macro (in VBA). The macro:
- copies a drawing or assembly (including referenced document) from one project to another;
renames all the files according to new project and subject; - edits iproperties of files according new project and subject;
- replaces ReferencedFileDescriptors to new filenames and paths;
- all the copying and replacing is done within a single-user project-file that excists for this purpuse.
Global workflow:
- So the user starts within a project and target design loaded,
- User starts the 'copy design' macro,
- User is asked to input target project and subject,
- Macro activates a single-user project-file (copy_object.ipj),
- Copying and replacing of references takes place,
- Macro unloads everyting, activates target project-file and opens result.
Two problems arise, both of wich i attribute to the changing of project files in VBA:
- The replacing of ReferencedFileDescriptors goes haywire.
- This only happens if i leave the activating of the copy_object.ipj to the VBA macro itself.
- When the user changes to copy_object.ipj before using the macro, not a single problem with the ReferencedFileDescriptors.
- At the end when the target project-file is activated and the result is opened, it is not possible to check the design in the Vault. Solution is to manually change to a random different project and back.
My conclusion is, that activating a project by way of VBA code gets me in some sort of project twilight zone.
My question, how to fix this?
I tried to isolate and clean up all the project-related code into a sub routine. No difference. Code:
Sub ChangeProj(aProj As String)
If ThisApplication.Documents.Count > 0 Then
ThisApplication.Documents.CloseAll
End If
Dim aDesignProjectMgr As DesignProjectManager
Dim aProjectNew As DesignProject
Set aDesignProjectMgr = ThisApplication.DesignProjectManager
On Error Resume Next
Set aProjectNew = aDesignProjectMgr.DesignProjects.ItemByName(aProj)
If Err.Number <> 0 Then
aDesignProjectMgr.DesignProjects.AddExisting (aProj)
Set aProjectNew = aDesignProjectMgr.DesignProjects.ItemByName(aProj)
End If
Err.Clear
On Error GoTo 0
aProjectNew.Activate
End SubManual changing of projects like this: