1

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


Cflux
  • 1,423
  • 3
  • 19
  • 39
  • 1
    Have you tried first using the `CompoundStructure.SetNumberOfShellLayers` method? You probably need to set both `ShellLayerType.Interior` and `ShellLayerType.Exterior` layer counts before Inserting layers – Callum Apr 16 '20 at 22:33
  • that turned out to be it among other things. it took me a while to figure out that the numberOfShellLayers method goes AFTER the `structure.setLayers(layers)` part – Cflux Apr 16 '20 at 23:08

2 Answers2

2

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

Cflux
  • 1,423
  • 3
  • 19
  • 39
1

Please read the standard Revit API documentation on CompoundStructureLayer and its members. There is probably no need for setlayerIndex or an alternative way to achieve what you need.

Jeremy Tammik
  • 7,333
  • 2
  • 12
  • 17
  • The `layerId` is the [closest thing](https://www.revitapidocs.com/2020/7b6ace8a-7810-5e6d-760e-642361fbe916.htm) I've found to what I'm looking for but it clearly states: `The id of the layer - note that this may be different from the index in the array of layers in a CompoundStructure.` It also doesn't tell me where to look to access the array of layers. – Cflux Apr 16 '20 at 14:49
  • I found that if I use `insert` instead of `add`, like this `layers.Insert(0, newLayer);` I can control the index location but I'm still working on how to get it outside of the core boundaries. – Cflux Apr 16 '20 at 16:44