Dim oFileLocations As FileLocations oFileLocations = oInvApp.FileLocations ' Display the workspace. 'Debug.Print("Workspace: " & oFileLocations.Workspace) Dim asNames() As String Dim asPaths() As String ' Get the list of workgroup paths. Dim iNumWorkgroups As long 'Call oFileLocations.Workgroups(iNumWorkgroups, asNames, asPaths) Call oFileLocations.Workgroups(iNumWorkgroups, asNames, asPaths) If iNumWorkgroups > 0 Then Debug.Print("Workgroup Paths") ' Iterate through the list of workgroups. The array is filled ' zero based, so the iteration begins a zero. For i = 0 To iNumWorkgroups - 1 Debug.Print(" " & asNames(i) & " = " & asPaths(i)) If asPaths(i) = asPaths(2) Then sFilePath = asPaths(2) + "\" Debug.Print(sFilePath)
the attached code works fine with VBA.... how do i get it to work in VB express? the problem is in asNames and asPath are giving a Null reference.
Thanks,
Bill
Ok, so I've found that the "FileLocations" object has been removed from the API for 2011.... I can not find any examples for identifying the file folders though. Anyone have the correct way to get this information?
Thanks,
Bill
I figured out that my code is correct. The problem that is occurring is that when I change the project via the API. Inventor does not fully "set" the project.... I have created a couple of scenarios where I switch the "active" project between the "default" project, a newly created project and a couple of existing projects, non actually work, I can see where it physically changes the project... It just holds onto the previously referenced project paths etc. If you pause the execution of the code and use your mouse to double click on the project it does switch references so that you can gain access to the newly active project paths..... How can I control this without using the mouse?
Anyone?
Thanks,
Bill
I am a bit lost in the code that you posted, but I think that you want to change the Project "JOB" file ".ipj".
'load items into combobox Dim oDPM As DesignProjectManager = oInvApp.DesignProjectManager For Each oProject As DesignProject In oDPM.DesignProjects ComboBox1.Items.Add(oProject.Name) Next ' on combobox1 index change we will change the project file Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged Dim oDPM As DesignProjectManager = oInvApp.DesignProjectManager Dim oProject As DesignProject = oDPM.DesignProjects.Item(ComboBox1.SelectedIndex + 1) oProject.Activate() End Sub
Mike,
yea, I don't explain things very clearly. I can get my code to change from one project file to another. What I can't get it to do is read the workgroups associated with each project file once it has changed. If i run my code placing a break point at a location so that i can manually (double click with my mouse button) a new project file, I can gain access to all of the workgroups associated with a project file. If i don't stop the code with a breakpoint, the code will change the project file, it just won't register any workgroups or workgroup paths. This is what I have been trying to get to work in VB.net....
Dim oDesignProjectMgr As DesignProjectManager oDesignProjectMgr = oInvApp.DesignProjectManager Dim oProject As DesignProject oProject = oDesignProjectMgr.DesignProjects.AddExisting(strFinalFile & strQt & ".ipj") oProject.Activate()
This snipit of code will add a new project to Inventor, "strFinalFile" is my path to the new *.ipj and "strQt" is the name of my new file and of course ".ipj" gives the project file the proper extension, this is all set to my variable 'oProject". I then activate the project file in Invetor by calling 'oProject.Activate". This does work properly and does change the project, it however does not want to register the workgroups within the project as it does when you manually change project in Inventor.
I try to find the workgroups in an additional sub with the following code....
Dim DesignProjectManager As DesignProjectManager DesignProjectManager = oInvApp.DesignProjectManager Dim DesignProjects As DesignProject DesignProjects = DesignProjectManager.ActiveDesignProject Dim WorkGroupPaths As ProjectPaths WorkGroupPaths = DesignProjects.WorkgroupPaths Dim i As Long For i = 1 To WorkGroupPaths.Count Debug.Print(WorkGroupPaths.Item(i).Name) Debug.Print(WorkGroupPaths.Item(i).Path) Next i
Any help or work around would be greatly appreciated....
Bill
I see now, I have the same problem in my testing. I have not found a solution for this at this time but will let you know if I find one.
Hi Mike,
What I figured out yesterday is that it does work if you do not set the project "active". I'm not sure why that would be. It seems like awkward logic. If you don't set the project active, you can read all of the workgroup paths. My only worry is if the project is not active and I pragmatically control some parameters of several different models then pragmatically assembly those piece into an assembly.... Will there be any pathing issues when a users goes to manually open a project and manipulate the assembly? Ping this message back if you find anything out.
I would like to hear from Autodesk on this one... If this is by design or if it is a bug etc...
Thanks Again,
Bill
This is a bug in the DesignProject API. We should have it fixed in an upcoming version of Inventor.
Here's a workaround. After you Activate a project, you have to reset the object:
oProject.Activate() oProject = Nothing System.GC.Collect() System.GC.WaitForPendingFinalizers() oProject = oInvApp.DesignProjectManager.ActiveDesignProject
System.GC.Collect() is a heavy-duty function, and you shouldn't call it too often. But I assume that you won't be switching to a different design project 60 times per second.
Alternatively, It should be possible to get your original FileLocations code to work, if you want to try that.
Mike,
Thanks for the response. I was hoping that someone from Autodesk would chime in. The work around works great, I thought that it may be a bug, but was not sure.
Thanks,
Bill