AssetPropertyDoubleArray4d.SetValueAsColor throws exception for some materials

harrymattison
Advocate
Advocate

AssetPropertyDoubleArray4d.SetValueAsColor throws exception for some materials

harrymattison
Advocate
Advocate

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

 

 
 
 
 
 
 
 
 
0 Likes
Reply
922 Views
6 Replies
Replies (6)

harrymattison
Advocate
Advocate
0 Likes

harrymattison
Advocate
Advocate
0 Likes

jeremytammik
Autodesk
Autodesk

Dear Harry,

 

Thank you for your report and sample material.

 

Just to make sure:

 

Does the RVT file include a macro to run?

 

Does your video demonstrate running that macro?

 

Sorry to hear about this.

 

I logged the issue REVIT-155228 [AssetPropertyDoubleArray4d.SetValueAsColor throws exception for some materials -- 15964656] with our development team for this on your behalf as it requires further exploration and possibly a modification to our software. Please make a note of this number for future reference.

 

You are welcome to request an update on the status of this issue or to provide additional information on it at any time quoting this change request number.

 

This issue is important to me. What can I do to help?

 

This issue needs to be assessed by our engineering team and prioritised against all other outstanding change requests. Any information that you can provide to influence this assessment will help. Please provide the following where possible:

 

  • Impact on your application and/or your development.
  • The number of users affected.
  • The potential revenue impact to you.
  • The potential revenue impact to Autodesk.
  • Realistic timescale over which a fix would help you.
  • In the case of a request for a new feature or a feature enhancement, please also provide detailed Use cases for the workflows that this change would address.

 

This information is extremely important. Our engineering team have limited resources, and so must focus their efforts on the highest impact items. We do understand that this will cause you delays and affect your development planning, and we appreciate your cooperation and patience.

 

Best regards,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes

harrymattison
Advocate
Advocate

@jeremytammik  Thank you for reporting the bug

Does the RVT file include a macro to run? - Yes

Does your video demonstrate running that macro? - Yes

 

  • Impact on your application and/or your development. - Prevents our tool from creating new materials that use assets with a user-specified color
  • The number of users affected. - This bug prevents all users of the Revit API from having a reliable solution for setting asset colors
  • Realistic timescale over which a fix would help you. - ASAP
0 Likes

jeremytammik
Autodesk
Autodesk

Thank you for the update, appreciation,  answers and business case.

 

I added them to the development issue for you.

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes

jeremytammik
Autodesk
Autodesk

Dear Harry,

 

You are in luck. The development team already analysed you issue and say:

 

The root cause of this exception is that the material AA has 2 invalid appearance properties: Generic image and Bump image; these files cannot be found.

 

Please pay attention to the infotip on the red blocks:

  

capturefilemissing.png

   

You can also verify this problem by looking at the journal file. The issue is logged here:

 

  ' 0:< Property unifiedbitmap_Bitmap is not valid in IAssetInstance!
  ' 0:< Property generic_bump_map is not valid in IAssetInstance!

  

One way to fix this is to ensure that the images exist or remove them.

   

What do you think about this turnaround time?

  

Cheers,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes