AssetPropertyDoubleArray4d.SetValueAsColor throws exception for some materials
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
This code works fine with some materials.
With other materials, SetValueAsColor throws an exception: "The input value is invalid for this AssetPropertyDoubleArray4d property"
Any suggestions how to get this working for all materials?
public void assetChange() { Document doc = this.Document; Material m = new FilteredElementCollector(doc).OfClass(typeof(Material)).Cast<Material>() .FirstOrDefault(q => q.Name == "BB"); Color color = new Color(0, 50, 0); using (Transaction t = new Transaction(doc, "d")) { t.Start(); bool useRender = m.UseRenderAppearanceForShading; m.UseRenderAppearanceForShading = false; setAssetColor(m, color); m.UseRenderAppearanceForShading = useRender; t.Commit(); } } private void setAssetColor(Material m, Color color) { Document doc = m.Document; using (AppearanceAssetEditScope editScope = new AppearanceAssetEditScope(doc)) { Asset asset = editScope.Start(m.AppearanceAssetId); List<AssetProperty> assets = getAssetList(doc.Application, asset); for (int idx = 0; idx < assets.Count; idx++) { AssetProperty ap = assets[idx]; if (ap.IsReadOnly || !(ap is AssetPropertyDoubleArray4d)) continue; AssetPropertyDoubleArray4d array4D = ap as AssetPropertyDoubleArray4d; try { array4D.SetValueAsColor(color); TaskDialog.Show("Done", array4D.Name); } catch (Exception ex) { TaskDialog.Show("Ex", array4D.Name + Environment.NewLine + ex.Message); } } editScope.Commit(false); } } public static List<AssetProperty> getAssetList(Autodesk.Revit.ApplicationServices.Application app, Asset renderingAsset) { List<AssetProperty> assets = new List<AssetProperty>(); if (renderingAsset.Size == 0) { renderingAsset = app.GetAssets(AssetType.Appearance).Cast<Asset>().FirstOrDefault(q => q.Name == renderingAsset.Name); } { for (int idx = 0; idx < renderingAsset.Size; idx++) { AssetProperty ap = renderingAsset[idx]; assets.Add(ap); } } return assets; }
ea6722b8-63e2-451d-8042-9286d4bf4658,640,650
Link copied