Announcements
Autodesk Community will be read-only between April 26 and April 27 as we complete essential maintenance. We will remove this banner once completed. Thanks for your understanding

How to modify element name

846081597
Enthusiast Enthusiast
229 Views
2 Replies
Message 1 of 3

How to modify element name

846081597
Enthusiast
Enthusiast

I want to create a plugin primarily for modifying the names of elements in the current project file(contains walls, slabs, and family instances, etc)
The code is as follows

Document doc = m_revit.ActiveUIDocument.Document;

FilteredElementCollector collector = new FilteredElementCollector(doc);
collector.WhereElementIsNotElementType(); 

Transaction ts = new Transaction(doc, "update");
ts.Start();

int num=0;
foreach (Element elem in collector)
{

   num++;

   if (elem != null)
     {

         string newname=elem.Name+num.ToString();

         elem.Name = newname;

     }

}

ts.Commit();

 

But it reports an error:

This element does not support assignment of a user-specified name.

Please help me.

0 Likes
Accepted solutions (1)
230 Views
2 Replies
Replies (2)
Message 2 of 3

Mohamed_Arshad
Advisor
Advisor
Accepted solution

Hi @846081597 

 

You need to consider several edge cases when renaming an element. For example, if you are renaming a wall, you can only rename the WallType name. To rename the WallType, you cannot directly rename the element. Instead, you need to first access the WallType and then rename it. Therefore, please check the element carefully before renaming it. Kindly refer to the code and image below for additional reference for wall.

 

Code Snippet

 

 using (Transaction setName= new Transaction(doc,"Set Name"))
 {
     setName.Start();

    WallType wallType= doc.GetElement( wall.GetTypeId()) as WallType;

     wallType.Name = "New Name";

     setName.Commit();
 }

 

 

Image Reference

Mohamed_Arshad_0-1734349707700.png

 

Hope this will Helps 🙂

Thanks & Regards,
Mohamed Arshad K
Message 3 of 3

846081597
Enthusiast
Enthusiast

Thank you very much, you are a genius!!
My problem has been solved.
Thank you.

0 Likes