multi value list of appearances

multi value list of appearances

blandb
Mentor Mentor
1,571 Views
13 Replies
Message 1 of 14

multi value list of appearances

blandb
Mentor
Mentor

I know there is a way to get all of the materials of a current library by using:

 

Multivalue.List("Material") = iproperties.materials

 

Is there a way to do this same thing, but grab a list of apperances instead?

 

Multivalue.List("appearance") = iproperties.appearances  ??

 

Thanks in advance

Autodesk Certified Professional
0 Likes
Accepted solutions (2)
1,572 Views
13 Replies
Replies (13)
Message 2 of 14

theo.bot
Collaborator
Collaborator
Accepted solution

The Ilogic snippets don't offer this. But when you access the active appearance library, you can get the list by using a small loop. Capture all display names and put them in a arraylist. Then set the array list as input for your parameter.
Here's a sample:

Dim oDoc As AssemblyDocument
oDoc = ThisDoc.Document

Dim oAppearance As AssetsEnumerator
oAppearance=ThisApplication.ActiveMaterialLibrary.AppearanceAssets

Dim oAsset As Asset

'Colors
Dim oColors As New ArrayList

For Each oAsset In oAppearance
	oColors.Add(oAsset.DisplayName)
Next

MultiValue.List("P_Assets") = oColors

 

 

Message 3 of 14

throttle1253Z225
Contributor
Contributor

Thanks for the response. What if I had a secondary appearance Library I needed to target instead of the active library?

0 Likes
Message 4 of 14

WCrihfield
Mentor
Mentor

If you know the name of that custom asset library, you can plug that in where I'm specifying '1' in the code below.

Dim oApAssetNames As New List(Of String)
oApAssets = ThisApplication.AssetLibraries.Item(1).AppearanceAssets
'oApAssets = ThisApplication.AssetLibraries.Item("AssetLibName").AppearanceAssets
For Each oApAsset As Asset In oApAssets
	oApAssetNames.Add(oApAsset.DisplayName)
Next
Try
	MultiValue.List("Appearances") = oApAssetNames
Catch
	Dim UPs As UserParameters = ThisDoc.Document.ComponentDefinition.Parameters.UserParameters
	UP = UPs.AddByValue("Appearances", "", UnitsTypeEnum.kTextUnits)
	MultiValue.List("Appearances") = oApAssetNames
End Try

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 14

throttle1253Z225
Contributor
Contributor

Thanks for that as well! This gave me the same result of some code I found online yesterday. What I am running into (and maybe because I'm choosing a non-active library) but the parameter is being populated correctly, but when I pull that parameter into a form, it will not show the current value. When I click on the drop down, the list appears, and then shows when I select something. Launch the form again, and the line is blank again until I hit the drop down.

 

This led me to think there was something bogus in the code.

 

Any ideas as to why it would be blanking out?

0 Likes
Message 6 of 14

blandb
Mentor
Mentor

My apologies, somehow, I was signed in under a different account. But the other responses were me lol.

Autodesk Certified Professional
0 Likes
Message 7 of 14

WCrihfield
Mentor
Mentor

This is likely because of the iLogic snippet we are using, and its settings, but could also simply be because we did not actually set a Value to the parameter, after settings its list of available values.  This is a factor.  Here is a link to the settings for that iLogic snippet. (MultiValue.SetValueOptions and MultiValue.UpdateAfterChange).  But as I said, we may simply need to set an actual Value to the parameter, not just its list of values.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 8 of 14

WCrihfield
Mentor
Mentor
Accepted solution

Yep.  When I add those two extra lines in there:

MultiValue.SetValueOptions(True)
MultiValue.UpdateAfterChange = True

just before the Try...Catch block, that fixes the issue of the parameter not having a current value after setting the list of values to it.  There is also an equivalent/alternative API method that could be used instead of that MultiValue iLogic only snippet.  The UserParameter object has an ExpressionList property, which then has a SetExpressionList method that I often use.  That has some similar settings too.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 9 of 14

blandb
Mentor
Mentor

This is weird, when I did this at the beginning all was fine, but I tried doing some other things (adding a suppression of the paint color in the form when set to default), and then the list went away? 

 

But if I set the AssetLibraries.Item to (1) then all is fine again. But if I type in the name of the library, the list goes away until i pick the drop down?

 

Dim oApAssetNames As New List(Of String)
oApAssets = ThisApplication.AssetLibraries.Item("name of second library").AppearanceAssets
'oApAssets = ThisApplication.AssetLibraries.Item("AssetLibName").AppearanceAssets
For Each oApAsset As Asset In oApAssets
	oApAssetNames.Add(oApAsset.DisplayName)
Next
Try
	MultiValue.List("PAINT_COLOR") = oApAssetNames
Catch
	Dim UPs As UserParameters = ThisDoc.Document.ComponentDefinition.Parameters.UserParameters
	UP = UPs.AddByValue("PAINT_COLOR", "", UnitsTypeEnum.kTextUnits)
	MultiValue.List("PAINT_COLOR") = oApAssetNames
End Try
MultiValue.SetValueOptions(True)
MultiValue.UpdateAfterChange = True


If PAINT_TYPE = "DEFAULT" Then
	PAINT_COLOR = "RAL7032_Pebble_grey"
	SUPRESS_PAINT = "FALSE"
	Component.Color("TRANSITION PATTERN") = PAINT_COLOR
	Component.Color("ANGLE PATTERN") = PAINT_COLOR
	Component.Color("ADAPTER") = PAINT_COLOR
Else
	SUPRESS_PAINT = "TRUE"
	Component.Color("TRANSITION PATTERN") = PAINT_COLOR
	Component.Color("ANGLE PATTERN") = PAINT_COLOR
	Component.Color("ADAPTER") = PAINT_COLOR
End If

 

Autodesk Certified Professional
0 Likes
Message 10 of 14

WCrihfield
Mentor
Mentor

Well...those two settings lines are 'preparatory' type settings, which means they are best used 'before' you do something with the other MultiValue.List or MultiValue.SetList type calls.  In my last note, I mentioned that I placed them just 'before' the Try...Catch block of code.  Once those two settings are established, then when something happens later with a MultiValue call, those settings will dictate certain behavior of it, like setting a value to the parameter after setting its list, and updating the document after setting the list.  I'm not sure simply moving those two lines to above the Try...Catch block will meet your needs or not, but it would be the simplest next step to try out.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 11 of 14

WCrihfield
Mentor
Mentor

I suppose we could try adding some extra checks in there to help make it more robust.  I believe that it should throw an error if you specify an Index that is out of range, or a name that can't be found, when getting the specific AssetLibrary object, so we could put a Try...Catch around that, but most likely not needed if everything there is stable.  We could also check the oApAssets.Count before the loop, then check the oApAssetNames.Count to make sure it is not zero before setting that list to the parameter.  I'm not sure what else you may have going on with the 'SUPRESS_PAINT' though.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 12 of 14

blandb
Mentor
Mentor

All that does is just greys out option to choose a color in the form if the type is set to default, because the default color is the RAL7032. If it is set to a custom color, then a user can choose any color in a second appearance library. This is because there is only a select set of appearances that the customer offers vs. our standard colors. Yes, these colors do exist in our primary active library along with a bunch of others, but to keep a user from selecting something that isn't available for this customer, that is why I am targeting a second library.

Autodesk Certified Professional
Message 13 of 14

blandb
Mentor
Mentor

Moving this up made the values stay, but when I go to "default" it does set the components the correct color (RAL7032) and will grey out my form, but leaves the last color used in the drop-down display vs setting it to the "RAL7032" as told to set.

Autodesk Certified Professional
0 Likes
Message 14 of 14

blandb
Mentor
Mentor

I got it..Thanks.

Autodesk Certified Professional
0 Likes