Trying to change wall materialID

Hello, all

I was trying to change wall ‘MateriId’ using python script in dynamo.
I think that I am almost done for doing that, but I failed. I couldn’t find the reason why I had failed.
I attached my model below, please help me to fix it.

Thanks!!

Please don’t make duplicate posts. You didn’t respond to the information on your previous one. This just makes it harder for you to get an answer.

I am sorry to make you confused. But, it isn’t a duplicate post.
The previous question was I uploaded the question without providing any coding, but this question was uploaded to know the cause because an error occurred in the part I was coding.

Thank you,

1 Like

I am having a similar issue with setting the wall material.

I have a single wall element which I am trying to change the material with a given material. From what I understand, you use the SetMaterialId method with the compoundStructureLayer, set the index of the layer (in my case there is only one so I set it to 0) and the material Id.

I am receiving an error that "No method matches given arguements for SetMaterialId…

import clr
import sys

import System
from System import Array
from System.Collections.Generic import *

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager 
from RevitServices.Transactions import TransactionManager 

clr.AddReference('RevitAPI')


import Autodesk 
from Autodesk.Revit.DB import *

doc = DocumentManager.Instance.CurrentDBDocument



elems = UnwrapElement(IN[0]) if isinstance(UnwrapElement(IN[0]),list) else [UnwrapElement(IN[0])]

wantedMat = IN[1]


wall = elems[0]

wallType = wall.WallType
comStruc = wallType.GetCompoundStructure()
layers = comStruc.GetLayers()

try:
    TransactionManager.Instance.EnsureInTransaction(doc)
    
    comStruc.SetMaterialId(0,wantedMat.Id)
    
finally:
    TransactionManager.Instance.TransactionTaskDone



OUT = wallType