Hi,
I have retrived the materialAssetID of Cherry material and it returned to me the Elementid of the apearance asset of the mentioned material. Then I have tried to set a value to one of the materialAssetIDs of my element materials like this :
Material.materialAssetID.setValue(…The materialAssetId of Cherry material…).
the error is Ican’t change the value of an element id. This is the Python code I have written for that:
import clr
import math
clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.DB import*
#set the active Revit application and document
app = revit.Application
doc = revit.ActiveUIDocument.Document
#define a transaction variable and describe the transaction
t = Transaction(doc, 'This is mz new transaction')
#start a transaction in the Revit database
t.Start()
#Add Code
#Get the apearance id of the intended material
#get all the elements ids in the document
collector = FilteredElementCollector( doc ).OfClass( Material )
materialsEnum = collector.ToElements()
print(materialsEnum[0].Name)
IntendedMaApName = 'Cherry'
MatApAsId = 0
for i in materialsEnum:
if i.Name == 'Cherry':
print(i.Name)
#get the apearance Id of the intended material
MatApAsId = i.AppearanceAssetId
#get the materials of the selected element in the Revit UI
selection = uidoc.Selection;
selectedIds = uidoc.Selection.GetElementIds();
#get sellected Element
SellectedElement = doc.GetElement(selectedIds[0])
print(SellectedElement)
#get all the ids of the materials assigned to that element
EleMatIds = Element.GetMaterialIds(SellectedElement, False)
print(EleMatIds[1])
#get the material of the materialid
SellectedMaterial = doc.GetElement(EleMatIds[1])
#get The apearance id of the selected material element
appearanceId = SellectedMaterial.AppearanceAssetId
print(appearanceId)
#Apearance element of the selected material element
appearanceElem = doc.GetElement(appearanceId)
print(appearanceElem)
#Changing ApearanceAssetId of the sellected material into the Id of Cherry material
print(MatApAsId)
SellectedMaterial.AppearanceAssetId.SetValue(MatApAsId)
#appearanceId = MatApAsId
#commit the transaction
t.Commit()
#window.Close()
I am using the Python shell in revit for the debugging !.
If you can help me to understand how I can change the value of this ElementId so the imported material will have the same apearance of the cherry material would be really helpful !.
Cheers, Ghaith