To retrieve Appearances from the current Appearance Library

To retrieve Appearances from the current Appearance Library

RoyWickrama_RWEI
Advisor Advisor
1,453 Views
5 Replies
Message 1 of 6

To retrieve Appearances from the current Appearance Library

RoyWickrama_RWEI
Advisor
Advisor

Ref: Inventor part document:

In my iLogic pursuits, currently I need to have all the appearances (from the current Appearance library) in a pull down menu so that desired appearance can be selected. The selected appearance to be assigned to the part. Similar to the following, but for the appearances.

 

Thanks.

 

Dim oMaterials As New ArrayList
For Each oMaterial In ThisDoc.Document.Materials
'msg = MessageBox.Show(oMaterial.Name, "Title",MessageBoxButtons.OKCancel)
oMaterials.add(oMaterial.Name)
If msg = vbCancel Then
Exit For
End If
Next

'present the user with the list to choose from
100:
oMaterial_IP = InputListBox("CHOOSE MATERIAL FROM ABOVE LIST", oMaterials, oMaterials.item(0), "MATERIAL SELECTION", "LIST OF MATERIALS")
If oMaterial_IP = "" Then Goto 100:
iProperties.Material = oMaterial_IP

 

 

Accepted solutions (2)
1,454 Views
5 Replies
Replies (5)
Message 2 of 6

t_hascj
Autodesk
Autodesk

Hi,

You can get appearances from active library byt this code

ThisApplication.ActiveAppearanceLibrary.AppearanceAssets



Thanks,
Jaroslav

Message 3 of 6

RoyWickrama_RWEI
Advisor
Advisor
Accepted solution

Hi Jaroslav (t_hascj)

 

With the help of your hint and getting more help from the forum, O got around mu need.

 

Sub oAppearance_Sub()

Dim oLib As AssetLibrary
Dim sAppearance As String

Dim invAppearanceProperty As Inventor.Property
'oLib = ThisApplication.AssetLibraries("Autodesk Appearance Library")
oLib = ThisApplication.AssetLibraries("RWEI TEXTURES")

Dim oTextures As New ArrayList
For Each oTexture In ThisApplication.ActiveAppearanceLibrary.AppearanceAssets
'oMsg = MessageBox.Show(oTexture.DisplayName, "Title",MessageBoxButtons.OKCancel)
oTextures.add(oTexture.DisplayName)
If msg = vbCancel Then
Exit For
End If
Next

'present the user with the list to choose from
100:
oTextures_Selected = InputListBox("CHOOSE TEXTURE FROM ABOVE LIST", oTextures, oTextures.item(0), "TEXTURE SELECTION", "LIST OF TEXTURES")
If oTextures_Selected = "" Then Goto 100:

MessageBox.Show("oTextures_Selected: " & oTextures_Selected, "Title")

oPartDoc = ThisDoc.Document		'oCompDef.Document

oPartDoc.ActiveAppearance.DisplayName = oTextures_Selected

End Sub

 

0 Likes
Message 4 of 6

RoyWickrama_RWEI
Advisor
Advisor
Accepted solution

I found it was not working though it did well before. So, I revised the code as follows:

 

Sub Main()
oAppearance_Sub()
ThisDoc.Save
End Sub

Sub oAppearance_Sub()
Dim oPartDoc As Inventor.PartDocument = ThisApplication.ActiveDocument
        
Dim oAppearanceAssets As AssetsEnumerator
oAppearanceAssets = oPartDoc.AppearanceAssets
Dim oAsset As Asset
	
Dim oAsset_Array As New ArrayList
For Each oAsset_Array_X In ThisApplication.ActiveAppearanceLibrary.AppearanceAssets
'oMsg = MessageBox.Show(oTexture.DisplayName, "Title",MessageBoxButtons.OKCancel)
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 TEXTURE FROM ABOVE LIST", oAsset_Array, oAsset_Array.item(0), "TEXTURE SELECTION", "LIST OF TEXTURES")
If oAsset_Array_Selected = "" Then Goto 100:

oAsset_X = oAsset_Array_Selected

For Each oAsset In oAppearanceAssets
	'Loop through the assetsvalues, that you see in the appearance dialogbox
    Dim oAssetValue As AssetValue
	'oMsgBox = MessageBox.Show("oAsset: " & oAsset.DisplayName, "oAsset")
	If oAsset.DisplayName = oAsset_X Then
	oPartDoc.ActiveAppearance = oAsset
	Exit For
	End If	
Next

End Sub
0 Likes
Message 5 of 6

C.Lourenco
Observer
Observer

I tried to use the code like this and it doesn't show the list of appearances, it shows something else. I'm trying this code to later create a multivalue parameter to use in a form.

 

Dim oPartDoc As Inventor.PartDocument = ThisApplication.ActiveDocument

Dim invAppearanceProperty As Inventor.Property
oLib = ThisApplication.AssetLibraries("Autodesk Appearance Library")
'oLib = ThisApplication.AssetLibraries("Kubor_Aparencias")

Dim oTextures As New ArrayList
For Each oTexture In ThisApplication.ActiveAppearanceLibrary.AppearanceAssets 
oTextures.Add(oTexture.Name)
If msg = vbCancel Then
Exit For
End If
Next

'present the user with the list to choose from
100:
oTexture_Selected = InputListBox("CHOOSE TEXTURE FROM ABOVE LIST", oTextures, oTextures.Item(0), "TEXTURE SELECTION", "LIST OF TEXTURES")
'If oTexture_IP = "" Then GoTo 100 :
	
oPartDoc.ActiveAppearance.DisplayName = oTexture_Selected

CLourenco_0-1645356404684.png

 

 

 

0 Likes
Message 6 of 6

matt_jlt
Collaborator
Collaborator

Here is the code that i am using. ITs a bit more complicated because i created a form within iLogic but it does the same thing with some extra options.

 

https://github.com/mattjlt/Inventor-Code-Library/blob/master/Scripts/MOD_Set%20All%20Colours.iLogicV...

 

0 Likes