Asset Libraries - Display Name

Asset Libraries - Display Name

Anonymous
Not applicable
932 Views
4 Replies
Message 1 of 5

Asset Libraries - Display Name

Anonymous
Not applicable

I would like for my code to display a list of the Appearances (Asset Libraries) in a pick list for a user to choose from but am struggling to come up with the code to do so. Can anyone please help?

 

I have this so far, but obviously it isn't working

 

 

Dim oLib As AssetLibrary
Dim oLib_Array As New ArrayList
For Each oLib In ThisApplication.AssetLibraries oLib_Array.add(oLib_Array.DisplayName) oLib_Array_Selected = InputListBox("Choose a library from the list above", oLib_Array, oLib_Array.item(0), "Libraries", "List of Libraries")
Next

thanks to anyone who can help 🙂 

0 Likes
Accepted solutions (1)
933 Views
4 Replies
Replies (4)
Message 2 of 5

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

@Anonymous,

 

Try below iLogic code to get display names of assets in Inventor.

Dim oLib_Array As New ArrayList
Dim oAssetlib As AssetLibrary
For Each oAssetlib In ThisApplication.AssetLibraries
    Dim oAsset As Asset
    For Each oAsset In oAssetlib.AppearanceAssets
         oLib_Array.Add(oAsset.DisplayName)
    Next
Next
oLib_Array_Selected = InputListBox("Choose a library from the list above", oLib_Array, oLib_Array.Item(0), "Libraries", "List of Libraries")

MessageBox.Show(oLib_Array_Selected, "Title")

Thanks and regards


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 3 of 5

Anonymous
Not applicable

Hi @chandra.shekar.g 

 

Many thanks for helping with this - really appreciated.. I have now adapted this to my code. My code is to change the colours of parts within an assembly. All appeared to be working well, but after some testing it wasn't quite right and I was hoping you could help, I think I know what the issue is but not so sure how to fix it to be honest...:(

 

I can display the list of all assets to the user in a pick list and the user can choose a new selection from the list.

It will change the colour of all parts but only if the correct appearance library is selected beforehand. ie to get the code to change the parts to a selection from the RAL Colors library, then I need to pre select that, then run the code and it works fine (hope that makes sense !!)

is there any way to make the code activate the library that the selection comes from?

 

Untitled.png    

 

Format:HTML Format Version:1.0 StartHTML: 165 EndHTML: 13697 StartFragment: 314 EndFragment: 13665 StartSelection: 314 EndSelection: 314SyntaxEditor Code Snippet

Sub Main()

'Get the active Assembly document.
Dim oAsmDoc As AssemblyDocument 
oAsmDoc = ThisApplication.ActiveDocument

Dim oLib As AssetLibrary
Dim sAppearance As String

Dim oAsset_Array As New ArrayList
Dim oAssetlib As AssetLibrary

' Iterate through all of the documents referenced by the assembly.
Dim oDoc As Document
For Each oDoc In oAsmDoc.AllReferencedDocuments
 
' Verify that the document is a part.
If oDoc.DocumentType = kPartDocumentObject Then
Dim oPartDoc As PartDocument
oPartDoc = oDoc

Dim oAppearanceAssets As AssetsEnumerator
oAppearanceAssets = oPartDoc.AppearanceAssets
For Each oAssetlib In ThisApplication.AssetLibraries
Dim oAsset As Asset
    
'Dim oAsset_Array As New ArrayList
    For Each oAsset_Array_X In oAssetlib.AppearanceAssets
    oAsset_Array.add(oAsset_Array_X.DisplayName)
    If msg = vbCancel Then
    Exit For
    End If
    Next
Next
'present the user with the list to choose from
100:
oAsset_Array_Selected = InputListBox("Choose a colour from the list above", oAsset_Array, oAsset_Array.item(0), "Colours", "List of Colours")
    If oAsset_Array_Selected = "" Then Goto 100:

    oPartDoc.ActiveRenderStyle = oDoc.RenderStyles.Item(oAsset_Array_Selected)

End If    
Exit For
    
Next

'update the files
InventorVb.DocumentUpdate()

End Sub

 

 

0 Likes
Message 4 of 5

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous,

 

Try below iLogic code to activate "RAL Colors" asset library.

Sub Main()

	'Get the active Assembly document.
	Dim oAsmDoc As AssemblyDocument 
	oAsmDoc = ThisApplication.ActiveDocument

	Dim oLib As AssetLibrary
	Dim sAppearance As String

	Dim oAsset_Array As New ArrayList
	Dim oAssetlib As AssetLibrary

	' Iterate through all of the documents referenced by the assembly.
	Dim oDoc As Document
	For Each oDoc In oAsmDoc.AllReferencedDocuments
	 
	' Verify that the document is a part.
	If oDoc.DocumentType = kPartDocumentObject Then
	Dim oPartDoc As PartDocument
	oPartDoc = oDoc

	Dim oAppearanceAssets As AssetsEnumerator
	oAppearanceAssets = oPartDoc.AppearanceAssets
	oAssetlib = ThisApplication.AssetLibraries.Item("RAL Colors")
	ThisApplication.ActiveAppearanceLibrary = oAssetlib
	 
    
	'Dim oAsset_Array As New ArrayList
    For Each oAsset_Array_X In oAssetlib.AppearanceAssets
	    oAsset_Array.Add(oAsset_Array_X.DisplayName)
	    If msg = vbCancel Then
	    	Exit For
	    End If
	Next 
	'present the user with the list to choose from
	100:
	oAsset_Array_Selected = InputListBox("Choose a colour from the list above", oAsset_Array, oAsset_Array.Item(0), "Colours", "List of Colours")
	    If oAsset_Array_Selected = "" Then GoTo 100:

	    oPartDoc.ActiveRenderStyle = oDoc.RenderStyles.Item(oAsset_Array_Selected)

	End If    
	Exit For
	    
	Next

	'update the files
	InventorVb.DocumentUpdate()

End Sub

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 5 of 5

Anonymous
Not applicable

At first glance It looked to me that you just activated the RAL library, and I didn't think that would fix it if a user subsequently tried to select an appearance  then from the Inventor Material Library, or any other library for that mater... but strangely it does fix it?

 

not sure why, but it does?

 

thanks Chandra.

 

0 Likes