Search code examples
c#revit-apirevitrevitpythonshellpyrevit

Revit API - New Wall Type - How to arrange layers?


I'm working on creating new wall types from scratch through the Revit API and I've gotten far (in my eyes) however I have one final problem to solve.

How do I arrange the layers of the wall the way I want? the wall gets created with all of the layers inside the core boundary which obviously is not ideal. I'm trying to get the Finish 1 and Finish 2 layers on the outside to either side of the core boundary

Any and all help is appreciated.

My wall gets created like this:

enter image description here

Here are the sources I've been looking at but haven't found anything that shows how to re-arrange the layers.

https://thebuildingcoder.typepad.com/blog/2009/06/core-structural-layer.html

https://thebuildingcoder.typepad.com/blog/2013/08/setting-the-compound-structure-core-and-shell-layers.html

https://thebuildingcoder.typepad.com/blog/2012/03/updating-wall-compound-layer-structure.html <-- probably the most informative but I'm not finding a "setlayerIndex" command

Here is my code below: Code

using (Transaction tx = new Transaction(doc))
            {
                tx.Start("ButtonName");
                newWallType = firstWallType.Duplicate("New Wall") as WallType;
                ElementId oldLayerMaterialId = firstWallType.GetCompoundStructure().GetLayers()[0].MaterialId;
                MaterialFunctionAssignment oldLayerFunction = firstWallType.GetCompoundStructure().GetLayers()[0].Function;
                MaterialFunctionAssignment newLayerFuncion = MaterialFunctionAssignment.Finish1;
                Debug.Print("newLayerFuncion: " + newLayerFuncion)


                CompoundStructureLayer newLayer = new CompoundStructureLayer(.25, newLayerFuncion, oldLayerMaterialId);
                CompoundStructureLayer newLayer2 = new CompoundStructureLayer(.5, MaterialFunctionAssignment.Finish2, oldLayerMaterialId);

                CompoundStructure structure = newWallType.GetCompoundStructure();

                IList<CompoundStructureLayer> layers = structure.GetLayers();


                layers.Add(newLayer);
                layers.Add(newLayer2);
                structure.SetLayers(layers);

                newWallType.SetCompoundStructure(structure);

                tx.Commit();
            }

            return Result.Succeeded;
        }



Solution

  • After much toiling, a good nights rest, and re-reading jeremey's link

    I just needed to add structure.SetNumberOfShellLayers(ShellLayerType.Exterior, 1); in the right place, after the structure.SetLayers(layers);