title: Creating Materials Via API With Appearance Asset
body: <p>I have a CSV File with RGB Values that im using to create materials in Revit through Dynamo Python scripting, However the materials that are created does not have AppearanceAsset assigned to it(even though it has a appearance asset tab}.Since when i get the AppearanceAssetID for the Material it Returns '-1' which as per the API means there is no assigned asset to it. </p>
  
  <p>How do i create materials with Appearance IDs already assigned</p>
  
  <p>I want to access the Appearance asset and set the Color to it, Since normally only the <strong>graphics</strong> color is set and not the <strong>appearance</strong> Color.</p>
  
  <pre><code>import clr
  clr.AddReference('RevitAPI')
  from Autodesk.Revit.DB import *
  clr.AddReference('RevitServices')
  import RevitServices
  from RevitServices.Persistence import DocumentManager
  from RevitServices.Transactions import TransactionManager
  clr.AddReference('RevitNodes')
  import Revit
  clr.ImportExtensions(Revit.Elements)
  
  
  def ToRevitColor(dynamoColor):return Color(dynamoColor.Red, dynamoColor.Green, dynamoColor.Blue)
  def ToDynamoObject(revitObject, isRevitOwned=False):return revitObject.ToDSType(isRevitOwned)
  doc = DocumentManager.Instance.CurrentDBDocument
  
  newMaterials = []
  appassetid = []
  
  TransactionManager.Instance.EnsureInTransaction(doc)
  
  mat_name = IN[0]
  color = IN[1]
  
  
  for i,y in zip (mat_name, color):
      new_mat_id = Material.Create(doc, i)
      new_mat = doc.GetElement(new_mat_id)
      new_mat.Color = ToRevitColor(y)
      newMaterials.append(ToDynamoObject(new_mat))
      appassetid.append(new_mat.AppearanceAssetId)
  
  
  TransactionManager.Instance.TransactionTaskDone()
  
  OUT = newMaterials,appassetid
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/4iSOs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4iSOs.png" alt="material Created Graphics tab"></a></p>
  
  <p><a href="https://i.stack.imgur.com/lIJMG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lIJMG.png" alt="material Created appearance tab"></a></p>
  
  <p><a href="https://i.stack.imgur.com/WECLI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WECLI.png" alt="output for getting appearance asset ID"></a></p>
  
  <p><a href="http://www.revitapidocs.com/2018.1/d02d0677-341a-8d1a-d3eb-35ff82f01695.htm" rel="nofollow noreferrer">http://www.revitapidocs.com/2018.1/d02d0677-341a-8d1a-d3eb-35ff82f01695.htm</a></p>
  
  <p>the API Reference </p>