Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Duplicate\Create WallType

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
jakub_ziolkowski
2631 Views, 2 Replies

Duplicate\Create WallType

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?

Tags (1)
2 REPLIES 2
Message 2 of 3

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;
        }

Message 3 of 3

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!");
            }

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community