Set Materials on CompoundStructureLayer

Set Materials on CompoundStructureLayer

Anonymous
Not applicable
2,986 Views
7 Replies
Message 1 of 8

Set Materials on CompoundStructureLayer

Anonymous
Not applicable

Hi

I want to change the material on all the layers of Walls and Floors to the same material

I get the MaterialId, loop through all the Layers, make a new layer with the same thicknes and function but with the new material and then set the layer to match the new layer, but... it doesn't work

 

What do I do wrong ??

 

 

My code look like this:

 

public void ChangeMaterialonLayers(CompoundStructure LC_CS, ElementId MatId)
{

    IList<CompoundStructureLayer> cslayers = LC_CS.GetLayers();

    int LayerIndex = 0;
    foreach (CompoundStructureLayer csl in cslayers)
    {
       CompoundStructureLayer TempLayer = new CompoundStructureLayer(csl.Width, csl.Function, MatId);
       LC_CS.SetLayer(LayerIndex, TempLayer);

       LayerIndex++;
    }

}

 

Regards Anders

0 Likes
Accepted solutions (1)
2,987 Views
7 Replies
Replies (7)
Message 2 of 8

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @Anonymous,

After setting the Compound structure with the compound structure layers ,Set the compound structure to the wall type or floor type.

 wall.WallType.SetCompoundStructure( compound structure );

I think the below link will help you

https://thebuildingcoder.typepad.com/blog/2011/03/many-issues-resolved.html#1264438 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

Message 3 of 8

Anonymous
Not applicable

Hi

Thanks, that works :-), on Floors and ceilings

but, on the walls I got an exception: "This operation is valid only for non-vertical compound structures...."

What is different for Walls ?

0 Likes
Message 4 of 8

jeremytammik
Autodesk
Autodesk

Have you tested to ensure that what you are trying to achieve programmatically works manually through the user interface at all?

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 5 of 8

Anonymous
Not applicable

Yes 🙂

Manually it is the same process to change materials on the layers on Floors and Walls and the same code works fine on ceilings and Floors, but not on walls. and the exception is specific about non-vertically compound, and that must be the walls, or ?? 🙂

But I don't see the differents

Regards

Anders

0 Likes
Message 6 of 8

FAIR59
Advisor
Advisor

maybe it has to do with the layerId , which maybe different from the index in the array.

 

LayerId.JPG 

CompoundStructureLayer TempLayer = new CompoundStructureLayer(csl.Width, csl.Function, MatId);
LC_CS.SetLayer(csl.LayerId, TempLayer);

 

0 Likes
Message 7 of 8

Anonymous
Not applicable

If I look at a Floor and a Wall via RevitLookup, the Layers have the same LayerID, starting from 0

and if I change the code to only change the material on the First Layer [0], it will do it on the Floors but still not on the Walls  !!

0 Likes
Message 8 of 8

FAIR59
Advisor
Advisor
Accepted solution

I don't know why the Exception gets thrown for walls and not for floors. 

There are 2 methoeds that work:

  1. Use  SetMaterialId()
    foreach( CompoundStructureLayer l in structure.GetLayers())
    {
    	structure.SetMaterialId(l.LayerId, mat.Id);
    }	
    walltype.SetCompoundStructure(structure);
    
  2. Make a List of newLayers
    List<CompoundStructureLayer> layers = new List<CompoundStructureLayer>();
    foreach( CompoundStructureLayer l in structure.GetLayers())
    {
    	CompoundStructureLayer newLayer = new CompoundStructureLayer(l.Width,l.Function,mat.Id);
            layers.Add(newLayer);
    }	
    structure.SetLayers(layers);
    walltype.SetCompoundStructure(structure);