<?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 Unable to get AppearanceAssetId from material in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/unable-to-get-appearanceassetid-from-material/m-p/9303262#M36774</link>
    <description>&lt;P&gt;I am attempting to create a new material and then apply a image to the material. I need the&amp;nbsp;AppearanceAssetId in order to use "AppearanceAssetEditScope". The problem is that AppearanceAssetId always returns -1 even after creating a material with the following code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;private void CreateMaterial(Document document)&lt;BR /&gt;{&lt;BR /&gt;SubTransaction createMaterial = new SubTransaction(document);&lt;BR /&gt;createMaterial.Start();&lt;BR /&gt;Material materialNew = null;&lt;/P&gt;&lt;P&gt;//Try to copy an existing material. If it is not available, create a new one.&lt;BR /&gt;Material masonry_Brick = GetMaterial(document, "Brick, Common");&lt;BR /&gt;if (masonry_Brick != null)&lt;BR /&gt;{&lt;BR /&gt;materialNew = masonry_Brick.Duplicate(masonry_Brick.Name + "_new");&lt;BR /&gt;System.Diagnostics.Debug.WriteLine(masonry_Brick.MaterialClass);&lt;BR /&gt;materialNew.MaterialClass = "Brick";&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;ElementId idNew = Material.Create(document, "New Brick Sample");&lt;BR /&gt;materialNew = document.GetElement(idNew) as Material;&lt;BR /&gt;materialNew.Color = new Autodesk.Revit.DB.Color(255, 0, 0);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;createMaterial.Commit();&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;// This is always -1?&lt;BR /&gt;//materialNew.AppearanceAssetId&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have been reading the building coders content but can't seem to get that Id?&lt;/P&gt;&lt;P&gt;&lt;A href="https://thebuildingcoder.typepad.com/blog/2019/04/set-material-texture-path-in-editscope.html#2" target="_blank" rel="noopener"&gt;https://thebuildingcoder.typepad.com/blog/2019/04/set-material-texture-path-in-editscope.html#2&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The following code does&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 07 Feb 2020 13:27:35 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2020-02-07T13:27:35Z</dc:date>
    <item>
      <title>Unable to get AppearanceAssetId from material</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/unable-to-get-appearanceassetid-from-material/m-p/9303262#M36774</link>
      <description>&lt;P&gt;I am attempting to create a new material and then apply a image to the material. I need the&amp;nbsp;AppearanceAssetId in order to use "AppearanceAssetEditScope". The problem is that AppearanceAssetId always returns -1 even after creating a material with the following code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;private void CreateMaterial(Document document)&lt;BR /&gt;{&lt;BR /&gt;SubTransaction createMaterial = new SubTransaction(document);&lt;BR /&gt;createMaterial.Start();&lt;BR /&gt;Material materialNew = null;&lt;/P&gt;&lt;P&gt;//Try to copy an existing material. If it is not available, create a new one.&lt;BR /&gt;Material masonry_Brick = GetMaterial(document, "Brick, Common");&lt;BR /&gt;if (masonry_Brick != null)&lt;BR /&gt;{&lt;BR /&gt;materialNew = masonry_Brick.Duplicate(masonry_Brick.Name + "_new");&lt;BR /&gt;System.Diagnostics.Debug.WriteLine(masonry_Brick.MaterialClass);&lt;BR /&gt;materialNew.MaterialClass = "Brick";&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;ElementId idNew = Material.Create(document, "New Brick Sample");&lt;BR /&gt;materialNew = document.GetElement(idNew) as Material;&lt;BR /&gt;materialNew.Color = new Autodesk.Revit.DB.Color(255, 0, 0);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;createMaterial.Commit();&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;// This is always -1?&lt;BR /&gt;//materialNew.AppearanceAssetId&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have been reading the building coders content but can't seem to get that Id?&lt;/P&gt;&lt;P&gt;&lt;A href="https://thebuildingcoder.typepad.com/blog/2019/04/set-material-texture-path-in-editscope.html#2" target="_blank" rel="noopener"&gt;https://thebuildingcoder.typepad.com/blog/2019/04/set-material-texture-path-in-editscope.html#2&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The following code does&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2020 13:27:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/unable-to-get-appearanceassetid-from-material/m-p/9303262#M36774</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-02-07T13:27:35Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to get AppearanceAssetId from material</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/unable-to-get-appearanceassetid-from-material/m-p/9303723#M36775</link>
      <description>&lt;P&gt;This was actually a misunderstanding on my side on how assets work with materials. I ended up creating a duplicate asset then assigning it to my duplicate material&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ElementId appearanceAssetId = materialNew.AppearanceAssetId;&lt;BR /&gt;AppearanceAssetElement assetElem = materialNew.Document.GetElement(appearanceAssetId) as AppearanceAssetElement;&lt;/P&gt;&lt;P&gt;AppearanceAssetElement duplicateAssetElement = assetElem.Duplicate(LayerName + "-asset");&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;materialNew.AppearanceAssetId = duplicateAssetElement.Id;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2020 16:21:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/unable-to-get-appearanceassetid-from-material/m-p/9303723#M36775</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-02-07T16:21:51Z</dc:date>
    </item>
  </channel>
</rss>

