Library from part

Library from part

JoAntt
Enthusiast Enthusiast
799 Views
2 Replies
Message 1 of 3

Library from part

JoAntt
Enthusiast
Enthusiast

Hi

 

Trying to get the library name from either a material asset or from the dokument without having to 

get the material name from a part and then search thru all libraries to find the name of the library.

 

Any ideas?

 

 

0 Likes
Accepted solutions (1)
800 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor

Hi @JoAntt.  So, if you already have a MaterialAsset object, that object has a property called Parent, which will return an Object, that will either be an AssetLibrary, or a Document.  Which one you get probably depends on if the MaterialAsset is a local copy within the document, or the original from the library.  That Parent property is probably as close as you will come to the route you want.

 

The whole searching through multiple libraries to find it by its name thing, may not pan out if it is a common name like "Red", because it may be found in multiple libraries.  Also, keep in mind that Assets have both Name and DisplayName properties, and the Name property may not contain the Value you are expecting, but that is the one used by the Item() property when looping through a library by Item.   Also keep in mind that usually a library contains both materials and appearances, or at least they are capable of that.  So, you could actually have the same library as your material library, and for your appearance library.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 3

JoAntt
Enthusiast
Enthusiast
Accepted solution

This is how it turned out.

Its close enough for what im doing, but if someone have a better way please let me know!

 

         Dim CurrentMat As MaterialAsset = ThePart.ActiveMaterial

            For Each AssLib As AssetLibrary In m_inventorApplication.AssetLibraries
                For Each oMaterial As MaterialAsset In AssLib.MaterialAssets
                    If oMaterial.CategoryName = CurrentMat.CategoryName Then
                        If oMaterial.DisplayName = CurrentMat.DisplayName Then
                            TheLibraryName = AssLib.DisplayName
                        End If
                    End If
                Next
            Next

 

0 Likes