How to refresh/open the projects window VBA

How to refresh/open the projects window VBA

gablewatson44
Explorer Explorer
374 Views
4 Replies
Message 1 of 5

How to refresh/open the projects window VBA

gablewatson44
Explorer
Explorer

Currently using inventor 2024, i have written a macro that automatically creates a workgroup path based on the file location of whatever is opened. I am using a work around with Sendkeys that quickly opens and closes the project window using a custom shortcut:

' Type P, R, O then Escape
SendKeys "P", True
SendKeys "R", True
SendKeys "O", True
SendKeys "{ESC}", True

 

while this works, i would rather use a form to completely control this macro thus requiring a different method of refreshing the project window, ideally something internal through VBA. Is there any way of doing this?

 

gablewatson44_1-1752590162650.png

 

0 Likes
375 Views
4 Replies
Replies (4)
Message 2 of 5

gablewatson44
Explorer
Explorer

I forgot to say that I need to do this in order for the workgroup path to register, otherwise it will not show up. If there is a work around that completely omits the use of the projects window that would be even better

0 Likes
Message 3 of 5

WCrihfield
Mentor
Mentor

HI @gablewatson44.  Can you please explain the overall goals you are trying to achieve with this.  I can not imagine any reason why anyone would need to visibly show, then close the projects dialog.  Do you know how to access the Projects normally through the Inventor API?  If not, you can get there through the following object path.

Application.DesignProjectManager 

DesignProjectManager.ActiveDesignProject 

DesignProjectManager.DesignProjects 

DesignProjects 

DesignProject 

...and so on.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 5

gablewatson44
Explorer
Explorer

When running the code that adds the current path into the workgroup search paths, the added path will not register until i either A.) physically open the projects window or B.) close and restart inventor. 

 

Here is the code being used:

Public Function AddCurrentFolderToWorkgroupSearchPaths()

Dim InvApp As Inventor.Application
Set InvApp = ThisApplication

 

' Get the full file path of the active document
Dim fullPath As String
fullPath = InvApp.ActiveDocument.FullFileName

 

' Extract just the folder path
Dim folderPath As String
folderPath = FilePath(fullPath)

 

' Get active design project
Dim projectMgr As DesignProjectManager
Set projectMgr = InvApp.DesignProjectManager

Dim activeProj As DesignProject
Set activeProj = projectMgr.ActiveDesignProject

 

' Check if the folder already exists in the Workgroup Search Paths
Dim pathExists As Boolean: pathExists = False
Dim i As Integer

Debug.Print activeProj.WorkgroupPaths.Item(2).path

For i = 1 To activeProj.WorkgroupPaths.count
If LCase(activeProj.WorkgroupPaths.Item(i).path) = LCase(folderPath) Then
pathExists = True
Exit For
End If
Next i

 

' Add the folder if it doesn't already exist
If Not pathExists Then
Call activeProj.WorkgroupPaths.Add(folderPath, folderPath)
MsgBox "Path added to project Workgroup Search Paths: " & folderPath, vbInformation
Else
MsgBox "Path already exists in Workgroup Search Paths.", vbExclamation
End If



0 Likes
Message 5 of 5

WCrihfield
Mentor
Mentor

OK.  I think I understand better now.  We simply can not make edits to Project file that is currently active, while any Inventor documents are open.  So we must close all Inventor documents first, without closing Inventor, then we can edit the active project file...as long as no one else is also referencing or using that same project file.  If others are using it also, then they will all also have to close all documents, and maybe even close Inventor first.  Anyways, it seems like there may be two alternative options here.  Your code can close the currently active document (and all other open documents), after capturing its 'path', then hopefully it will allow the edits to the active project file.  Or, we could get the name of the currently active project, then activate a different project, so that the one we want to edit is not active, then do the edits to that project, then re-activate that project again when done.  I have not tested either route in quite a while, because I rarely ever need to edit any project settings, especially by code.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes