<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Get an up-to-date material preview image file path in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/get-an-up-to-date-material-preview-image-file-path/m-p/7752212#M52912</link>
    <description>&lt;P&gt;Hi Maxime,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, you are correct. It looks like preview is generated only when visible in UI. I am afraid that you cannot write the code without additional API being available... I'll see what we can do about that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best regards,&lt;/P&gt;
&lt;P&gt;-Boris.&lt;/P&gt;</description>
    <pubDate>Mon, 05 Feb 2018 16:14:19 GMT</pubDate>
    <dc:creator>bshafiro</dc:creator>
    <dc:date>2018-02-05T16:14:19Z</dc:date>
    <item>
      <title>Get an up-to-date material preview image file path</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/get-an-up-to-date-material-preview-image-file-path/m-p/7731827#M52908</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I thought the new Revit 2018.1 API dedicated to materials would help me solve a quite old issue, but it seems that it is not the case.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to retrieve (then show) the image preview of a material. It is the image at the top of the rendering tab (or asset) in the material editor.&lt;/P&gt;&lt;P&gt;From what I have understood, this image is updated/regenerated&amp;nbsp;:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;if not created yet, when you open the rendering tab for the first time&lt;/LI&gt;&lt;LI&gt;when you change one of the rendering properties&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The image location path seems to be stored in the&amp;nbsp;AssetProperty called "thumbnail". It can be :&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;relative, if it points to a preset material image in the ADSK library. For instance "Mats\WallPaint\Presets\t_Paint-057.png".&lt;/LI&gt;&lt;LI&gt;absolute. For instance it can point to the "temp" folder when you just regenerated the file. In that case the path is like "materialthumbnails_pid_NNN\XXX.png" or "MaterialRapidRT_PIDNNNNN\XXX.png"&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I write this piece of code to get the wanted path :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;AppearanceAssetElement aae = _document.GetElement(mat.AppearanceAssetId) as AppearanceAssetElement;
                        if (null != aae)
                        {
                            Asset asset = aae.GetRenderingAsset();
                            if (null != asset)
                            {
                                if (asset[SchemaCommon.Thumbnail] is AssetPropertyString ap)
                                {
                                    string path = ap.Value;

                                    if (path.StartsWith("Mats") || path.StartsWith("Maps")) // Revit default
                                    {
                                        path = path.Insert(0, @"C:\Program Files (x86)\Common Files\Autodesk Shared\Materials\2018\assetlibrary_base.fbm\");
                                    }
                                    else if (path.StartsWith("material", true, System.Globalization.CultureInfo.CurrentCulture))
                                    {
                                        path = path.Insert(0, @"%tmp%\");
                                    }

                                    if (!string.IsNullOrEmpty(path) &amp;amp;&amp;amp; File.Exists(path))
                                    {
                                        Bitmap bmp_representation = new Bitmap(Image.FromFile(path), size); 
                                    }
                                }
                            }
                        }&lt;/PRE&gt;&lt;P&gt;This works fine for some materials, but for most of them the retrieved path does not exist. Why ? I think it is because the image has not been regenerated &lt;STRONG&gt;&lt;U&gt;in the current Revit session&lt;/U&gt;&lt;/STRONG&gt;. &lt;U&gt;&lt;STRONG&gt;So ideally I would like the API to have a function that updates&amp;nbsp;a material preview image, so that the corresponding path points to an existing and up-to-date PNG file.&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also tried to first edit the rendering asset (without making any changes), in the hope that would update the preview image, but no success : for nearly all the materials, the preview image is the UnifiedBitmap default PNG.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;using (Transaction trans = new Transaction(_document, "Fake transaction"))
                        {
                            trans.Start();
                            using (AppearanceAssetEditScope editScope = new AppearanceAssetEditScope(_document))
                            {
                                Asset editableAsset = editScope.Start(mat.AppearanceAssetId);
                                
                                editScope.Commit(true);
                            }
                            trans.Commit();
                        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your ideas/suggestions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Maxime&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jan 2018 13:30:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/get-an-up-to-date-material-preview-image-file-path/m-p/7731827#M52908</guid>
      <dc:creator>m.vallee</dc:creator>
      <dc:date>2018-01-29T13:30:37Z</dc:date>
    </item>
    <item>
      <title>Re: Get an up-to-date material preview image file path</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/get-an-up-to-date-material-preview-image-file-path/m-p/7742609#M52909</link>
      <description>&lt;P&gt;Dear Maxime,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your query.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm surprised the new functionality does not already provide all you need out of the box.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I asked the development team for you, in any case.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope this helps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best regards,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jeremy&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2018 11:39:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/get-an-up-to-date-material-preview-image-file-path/m-p/7742609#M52909</guid>
      <dc:creator>jeremytammik</dc:creator>
      <dc:date>2018-02-01T11:39:22Z</dc:date>
    </item>
    <item>
      <title>Re: Get an up-to-date material preview image file path</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/get-an-up-to-date-material-preview-image-file-path/m-p/7747044#M52910</link>
      <description>&lt;P&gt;Dear Maxime,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your query.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, I agree that an appropriate convenience method to get the preview image for&amp;nbsp;a Material&amp;nbsp;is missing in the current Materials API. I'll file an issue for our developers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;On the workaround that you tried: I think you almost solved it. The problem is that you created an empty transaction that did not change anything. If you open a transaction (and edit scope), then actually change one of the properties in the Asset (that causes the new image to be generated), also store the old value. Commit the edit scope, close the transaction. Then open transaction again (and edit scope), change the same property of the same Asset back to the stored old value. Commit the scope, close the transaction. So, the Material is now in the original unchanged state, but it is guaranteed to have the preview image generated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope this helps.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2018 16:42:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/get-an-up-to-date-material-preview-image-file-path/m-p/7747044#M52910</guid>
      <dc:creator>bshafiro</dc:creator>
      <dc:date>2018-02-02T16:42:39Z</dc:date>
    </item>
    <item>
      <title>Re: Get an up-to-date material preview image file path</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/get-an-up-to-date-material-preview-image-file-path/m-p/7751072#M52911</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your answers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/2222788"&gt;@bshafiro&lt;/a&gt;&amp;nbsp;I tried what you say, but it didn't work. I modified a color then reset it like it was with two consecutive transactions :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;                        Bitmap bmp_representation = null;
                        Size size = new Size(64, 64);
                        int factor = 25;

                        using (Transaction trans = new Transaction(_document, "Fake transaction"))
                        {
                            trans.Start();
                            using (AppearanceAssetEditScope editScope = new AppearanceAssetEditScope(_document))
                            {
                                Asset editableAsset = editScope.Start(mat.AppearanceAssetId);
                                AssetPropertyDoubleArray4d metalColorProp = editableAsset["common_Tint_color"] as AssetPropertyDoubleArray4d;

                                Autodesk.Revit.DB.Color color = metalColorProp.GetValueAsColor();
                                byte red = color.Red;
                                byte green = color.Green;
                                byte blue = color.Blue;
                                red = (byte)LimitValue(red + factor);
                                green = (byte)LimitValue(green + factor);
                                blue = (byte)LimitValue(blue + factor);

                                if (metalColorProp.IsValidValue(color))
                                    metalColorProp.SetValueAsColor(new Autodesk.Revit.DB.Color(red, green, blue));
                                editScope.Commit(true);
                            }
                            trans.Commit();
                        }
                        using (Transaction trans = new Transaction(_document, "Fake transaction"))
                        {
                            trans.Start();
                            using (AppearanceAssetEditScope editScope = new AppearanceAssetEditScope(_document))
                            {
                                Asset editableAsset = editScope.Start(mat.AppearanceAssetId);
                                AssetPropertyDoubleArray4d metalColorProp = editableAsset["common_Tint_color"] as AssetPropertyDoubleArray4d;

                                Autodesk.Revit.DB.Color color = metalColorProp.GetValueAsColor();
                                byte red = color.Red;
                                byte green = color.Green;
                                byte blue = color.Blue;
                                red = (byte)LimitValue(red - factor);
                                green = (byte)LimitValue(green - factor);
                                blue = (byte)LimitValue(blue - factor);

                                if (metalColorProp.IsValidValue(color))
                                    metalColorProp.SetValueAsColor(new Autodesk.Revit.DB.Color(red, green, blue));
                                editScope.Commit(true);
                            }
                            trans.Commit();
                        }&lt;/PRE&gt;&lt;P&gt;The paths of the image previews I get after that are "" or "Maps\UnifiedBitmap\UnifiedBitmap.png". There is no preview image generated in my "temp" folder.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think the image previews are regenerated only when they are shown in the Material Editor UI, and that we can't do it programmatically as of today...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards.&lt;/P&gt;&lt;P&gt;Maxime&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2018 09:38:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/get-an-up-to-date-material-preview-image-file-path/m-p/7751072#M52911</guid>
      <dc:creator>m.vallee</dc:creator>
      <dc:date>2018-02-05T09:38:46Z</dc:date>
    </item>
    <item>
      <title>Re: Get an up-to-date material preview image file path</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/get-an-up-to-date-material-preview-image-file-path/m-p/7752212#M52912</link>
      <description>&lt;P&gt;Hi Maxime,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, you are correct. It looks like preview is generated only when visible in UI. I am afraid that you cannot write the code without additional API being available... I'll see what we can do about that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best regards,&lt;/P&gt;
&lt;P&gt;-Boris.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2018 16:14:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/get-an-up-to-date-material-preview-image-file-path/m-p/7752212#M52912</guid>
      <dc:creator>bshafiro</dc:creator>
      <dc:date>2018-02-05T16:14:19Z</dc:date>
    </item>
    <item>
      <title>Re: Get an up-to-date material preview image file path</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/get-an-up-to-date-material-preview-image-file-path/m-p/7758488#M52913</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your answer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I stay tune for more information.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Maxime&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2018 12:52:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/get-an-up-to-date-material-preview-image-file-path/m-p/7758488#M52913</guid>
      <dc:creator>m.vallee</dc:creator>
      <dc:date>2018-02-07T12:52:06Z</dc:date>
    </item>
    <item>
      <title>Re: Get an up-to-date material preview image file path</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/get-an-up-to-date-material-preview-image-file-path/m-p/8871459#M52914</link>
      <description>&lt;P&gt;Hello Boris,&lt;/P&gt;&lt;P&gt;I am working on an application that could also use the material appearance asset preview generated in the UI. If this capability can be made available in the API, it would be greatly appreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;Carlo&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jun 2019 17:07:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/get-an-up-to-date-material-preview-image-file-path/m-p/8871459#M52914</guid>
      <dc:creator>cliceaHGEUZ</dc:creator>
      <dc:date>2019-06-25T17:07:46Z</dc:date>
    </item>
    <item>
      <title>Re: Get an up-to-date material preview image file path</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/get-an-up-to-date-material-preview-image-file-path/m-p/13932545#M85028</link>
      <description>&lt;P&gt;Resurfacing this thread. Any progress on this since 2018?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Dec 2025 21:00:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/get-an-up-to-date-material-preview-image-file-path/m-p/13932545#M85028</guid>
      <dc:creator>mkeung</dc:creator>
      <dc:date>2025-12-04T21:00:48Z</dc:date>
    </item>
  </channel>
</rss>

