Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

Changing a Material's Manufacturer Parameter via API

eric.isaac2KKE9
Enthusiast

Changing a Material's Manufacturer Parameter via API

eric.isaac2KKE9
Enthusiast
Enthusiast

Hi all,

 

I'm trying to change a Material's "Manufacturer" parameter via the API in Revit 2024. The script reports success (no errors, debug prints reflect the change) for changing the parameter, but I don't see the change actually reflected in the Revit editor. Am I doing something incorrect here?

 

with revit.Transaction('Edit Material Manufacturer'):
    print(material.LookupParameter('Manufacturer').AsString())
    material.LookupParameter('Manufacturer').Set(newManufacturer)
    print(material.LookupParameter('Manufacturer').AsString())

 

The above is in Python, but if there is a good example in C#, that works just as well for helping me debug this! I've also tried using get_Parameter w/ the BuiltInParameter, but the result was the same.

0 Likes
Reply
Accepted solutions (1)
544 Views
5 Replies
Replies (5)

scgq425
Advocate
Advocate

hi @eric.isaac2KKE9 : in u code , may be u need to use look up to find material true value . u code just changed the material string  ,but material is a element we need to set a elementid so u can check u `newManufacuter`,  the result will cant see changed in document , if u want to changed this material u can use this code , and changed this to python :

scgq425_0-1717143669246.png

 

LanHui Xu
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

0 Likes

TripleM-Dev.net
Advisor
Advisor

Hi @eric.isaac2KKE9,

 

I think you need to call the method SetValueString and not Set in this case. (see: SetValueString Method 

 

If you call .Set with a string it assumes the Parameter datatype is string, and will fail as a Material Parameter needs a ElementId (that represents a material)

 

I have no idea if this works by giving the material name however, never tried it.

 

- Michel

 

0 Likes

eric.isaac2KKE9
Enthusiast
Enthusiast

@TripleM-Dev.net Unfortunatley, calling SetValueString also fails, and the changes aren't reflected in the print statements. My best guess is that something internally works differently for material parameters, and I'm not getting enough info to determine what (via python). The datatype is a string in this case.

 

I do appreciate the input; but I may need to put this one down for now (already spent most of a day trying to modify this parameter w/o much to show for it). Also tried a few of the edit scopes as a random guess, no dice there either.

0 Likes

TripleM-Dev.net
Advisor
Advisor
Accepted solution

O, the other post pointed me in the wrong direction.

 

You want to change a parameter of a material itself and not set a material element to a material parameter, which should be a ElementId value.

 

Forget about "SetValueString", Set should work on a Text parameter.

 

I've just tried it with "BuiltInParameter.ALL_MODEL_MANUFACTURER" and in the C# api it works, maybe Python does something else, the material as far as parameters is concerned should be handled as a element would.

 

Maybe try it on any other ElementType, they all have the Manufacturer parameter and see if that works?

 

Below the piece I used (the ID 533 is the material id)

 

Element elem = doc.GetElement(new ElementId(533));
using (Transaction myT = new Transaction(doc, "test"))
{
myT.Start();
elem.get_Parameter(BuiltInParameter.ALL_MODEL_MANUFACTURER).Set("Test value manufacturer");
myT.Commit();
}

 

 

Result:

material manufacturer edit.png

 

eric.isaac2KKE9
Enthusiast
Enthusiast

Thank you for confirming that it is working on your end! I am still encountering the odd behavior (for materials and other elements, just tested with a wall), but it sounds like this may not have anything to do with the Revit API's intended functionality - for the time being, we found another way to make the automation we were interested in.

 

I accepted the solution because it does address what I was hoping to know, so thank you!

0 Likes