Testing if a material exists in a library

Testing if a material exists in a library

Anonymous
Not applicable
526 Views
4 Replies
Message 1 of 5

Testing if a material exists in a library

Anonymous
Not applicable

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
527 Views
4 Replies
Replies (4)
Message 2 of 5

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
Message 3 of 5

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
Message 4 of 5

Anonymous
Not applicable

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
Message 5 of 5

Anonymous
Not applicable
Thanks, but I'm trying to get around using the `.DisplayName` for identification.
0 Likes