Testing if a material exists in a library

meGVGMF
Advocate
Advocate

Testing if a material exists in a library

meGVGMF
Advocate
Advocate

Hi,

 

I'm trying to see if the material of the active model state exists in a given library.

 

I thought I'd be able to use the `MaterialAsset.Name` property, which for library ones is a UUID, but seems to be a simple string for, at least, `ThisDoc.Document.ActiveMaterial`.

 

Is it possible to access this UUID somewhere within the `Document` object?

 

Thanks

0 Likes
Reply
318 Views
4 Replies
Replies (4)

Cadkunde.nl
Collaborator
Collaborator

No clue what UUID is. But if I want to find the material in the library i use something like this:

 

Dim oApp As Inventor.Application = ThisApplication
Dim oDoc As PartDocument = ThisDoc.Document
Dim assetLib As AssetLibrary = oApp.AssetLibraries.Item("Inventor Material Library")

For Each oAsset As Inventor.MaterialAsset In assetLib.MaterialAssets
If oAsset.DisplayName = oDoc.ActiveMaterial.DisplayName Then
	MsgBox("Yay! Found it")
End If
Next

A.Acheson
Mentor
Mentor

The only way I know to do this is to loop through the library assets looking for the string value. Can you supply the code your working with? This vba sample for appearance would do just that when asset changed for material. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan

meGVGMF
Advocate
Advocate

I'm actually trying to get around using `.DisplayName`, because if the name changes the material would go unrecognized.

The universally unique identifier/UUID value of the `.Name` for assets in the library is a 128-bit string in the format 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' that is, for all intents and purposes, unique.

Using this instead would cause fewer false negatives in the comparison and allow for more flexibility in the logic.

0 Likes

meGVGMF
Advocate
Advocate
Thanks, but I'm trying to get around using the `.DisplayName` for identification.
0 Likes