My goal is to dupilcate/create new WallType and change the properties of structure compounds.
I would appreciate if somebody could help me with using of WallType.Duplicate() method.
I guess that main part of the source code will look like this:
FilteredElementCollector collector = new FilteredElementCollector(doc);
collector.OfClass(typeof(Wall));
foreach (Wall wall in collector)
{
WallType aWallType = wall.WallType;
if (WallKind.Basic == wall.WallType.Kind)
{
if (aWallType.Name == "Generic - 200mm") aWallType.Duplicate("MyNewWallType");
}
}
I am guessing also that first I will need to add "Generic - 200mm" WallType to revit Document DataBase (Autodesk.Revit.DB) in case of this type of wall have not been added before.
The source code mention above is not working properly. "MyNewWallType" is not shown in Revit wall type list.
I heard about Insert() method... maybe somebody is familiar with this subject?
Solved! Go to Solution.
I sort of solved my problem. We have two cases:
-------------------------------------------------------------------------------------------------
First one when we want to search only wallTypes which are existing in project
-------------------------------------------------------------------------------------------------
private Boolean CheckWallType(Document doc, string WallTypeName)
{
Boolean exist;
exist = false;
FilteredElementCollector collector = new FilteredElementCollector(doc);
collector.OfClass(typeof(Wall));
foreach (Wall wall in collector)
{
WallType aWallType = wall.WallType;
if (WallKind.Basic == wall.WallType.Kind)
{
if (aWallType.Name == WallTypeName)
{
TaskDialog.Show("Revit", "Wall exist!");
exist = true;
break;
}
}
}
return exist;
}
-----------------------------------------------------------------------------------------
Second one when we want to search through all document
-----------------------------------------------------------------------------------------
private Boolean CheckWallType(Document doc, string WallTypeName)
{
Boolean exist;
exist = false;
foreach (WallType aWallType in doc.WallTypes)
{
if (WallKind.Basic == aWallType.Kind)
{
if (aWallType.Name == WallTypeName)
{
TaskDialog.Show("Revit", "Wall exist!");
exist = true;
break;
}
}
}
return exist;
}
I got similar question here. I would like to change the walltype name of a wall through API, but it seems it does not work right.
foreach (Element collectedElem in collection) {
if (collectedElem.GetType().Name == "Wall") {
Wall wall = (Wall)collectedElem;
string wallValue=collectedElem.Level.Name+";"+collectedElem.Name;
TaskDialog.Show("Wallvalue", wallValue);
if (walltype.Contains(wallValue) == false)
{
walltype.Add(wallValue);
}
else {
wall.WallType.Name="NewName";
TaskDialog.Show("change value", wall.WallType.Name );
}
}
}
TaskDialog.Show("Test", "End of searching document!");
}