DesignProjectManager issues, trying to add libraries to projects

DesignProjectManager issues, trying to add libraries to projects

spencer
Advocate Advocate
852 Views
5 Replies
Message 1 of 6

DesignProjectManager issues, trying to add libraries to projects

spencer
Advocate
Advocate

I decided to take another crack at getting projects to populate with the library info we use in every project, so we don't have to manually set these every time and inevitable forget.

So the situation is that we have 3 libraries in question, all are stored on a shared drive

The first is a library of parts and assemblies, which we insert/copy from often

The second is a custom appearance library, that we would prefer to be the default because it fits our usage more than the default Inventor one

The third is a custom material library, same deal as appearance

 

Ideally I would just set the 'Default' project with those libraries and new projects would inherit those, but that is not the case with Inventor.

Doing it code-wise, the big difficulty is that once the project is opened, it can't be edited, and the "OnActiveProjectChanged" event essentially fires after setting the project read-only so I can't leverage that.

And just now I conceded making it automatic and tried to use the "DesignProjectManager.AddOptionsButton()" function, only to find out that the button created by that will not actually fire its "OnClick" event, so I can't do anything with said button

 

Anyone else have an idea at this point?

0 Likes
853 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor

This won't solve your issue with manipulating the project through code, but it may help out along the way.

I highly recommend that you combine your custom Appearance Library stuff into your custom Material Library, because Material Libraries can contain both materials & appearances.  Both custom libraries are the same file type & formatted the same.  This makes updating styles much less complicated later on.  Then set that one custom material library as your "Active Library" in the Material Libraries & Appearance Libraries sections within the project.  You can leave the Autodesk Material Library and the Inventor Material Library listed under the Material Libraries section, and you can leave the Autodesk Appearance Library listed under the Appearance Libraries section, because they won't hurt anything.  Then all resources will be available at all times.

I hope this helps.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 6

spencer
Advocate
Advocate

I actually do have my custom appearance and materials as a single library, but to use them I still have to add the library as an appearance library and then again as a material library

0 Likes
Message 4 of 6

JelteDeJong
Mentor
Mentor

This iLogic rule will update all projects.

Dim materialLib As String = "C:\Users\Public\Documents\Autodesk\Inventor 2018\Design Data\Materials\InventorMaterialLibrary.adsklib"
Dim appearanceLib As String = "C:\Users\Public\Documents\Autodesk\Inventor 2018\Design Data\Materials\InventorMaterialLibrary.adsklib"

Dim projectManager As DesignProjectManager = ThisApplication.DesignProjectManager
Dim activeProject As DesignProject = projectManager.ActiveDesignProject
Dim notActiveProject As DesignProject = Nothing

For Each proj As DesignProject In projectManager.DesignProjects
    If (proj.Name.Equals(activeProject.Name)) Then
        Continue For
    End If
    notActiveProject = proj
    Try
        proj.MaterialLibraries.Add(materialLib)
    Catch ex As Exception
        MsgBox("Could not add material libraries to project: " & proj.Name)
    End Try
    Try
        proj.AppearanceLibraries.Add(appearanceLib)
    Catch ex As Exception
        MsgBox("Could not add appearance libraries to project: " & proj.Name)
    End Try
Next

Dim openDocs As List(Of String) = New List(Of String)()
For Each doc As Document In ThisApplication.Documents
    openDocs.Add(doc.FullFileName)
Next

' Following method closes all the documents in the current Inventor session. 
' Changes are not saved to any of the documents.
ThisApplication.Documents.CloseAll()

notActiveProject.Activate()
Try
    activeProject.MaterialLibraries.Add(materialLib)
Catch ex As Exception
    MsgBox("Could not add material libraries to project: " & activeProject.Name)
End Try
Try
    activeProject.AppearanceLibraries.Add(appearanceLib)
Catch ex As Exception
    MsgBox("Could not add appearance libraries to project: " & activeProject.Name)
End Try
activeProject.Activate()

For Each FullFileName As String In openDocs
    ThisApplication.Documents.Open(FullFileName)
Next

MsgBox("Update done")

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 5 of 6

spencer
Advocate
Advocate

I'm trying to get away from a solution like that, and move towards something more immediate/automatic, so when new projects are made Inventor doesn't immediately start barking about template styles.

0 Likes
Message 6 of 6

dusan.naus.trz
Advisor
Advisor

Very interesting solution. I have a question. How to set Active Appearance and Active Material for all projects? Your code is nice, I just haven't figured out how to add this to your code.

2023-06-16_20h23_03.png

0 Likes