Not able to change width of layer of compound structure of roof?

Not able to change width of layer of compound structure of roof?

Anonymous
Not applicable
535 Views
2 Replies
Message 1 of 3

Not able to change width of layer of compound structure of roof?

Anonymous
Not applicable

Hello,

 

I tried several ways to change width of layer of roof, but no luck, here is my code, and attachment if my sample file:

 

    [TransactionAttribute(TransactionMode.Manual)]
    public class Class1 : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            var doc = commandData.Application.ActiveUIDocument.Document;
            ExtrusionRoof filteredElement = null;
            var filteredElementFilter = new ElementClassFilter(typeof(ExtrusionRoof));
            FilteredElementCollector filteredElements = new FilteredElementCollector(doc);
            filteredElements = filteredElements.WherePasses(filteredElementFilter);
            using (Transaction transaction = new Transaction(doc))
            {
                try
                {
                    if (transaction.Start("update roof width") == TransactionStatus.Started)
                    {
                        foreach (ExtrusionRoof element in filteredElements)
                        {
                            var elementType = doc.GetElement(element.GetTypeId()) as RoofType;
                            if (elementType != null)
                            {
                                var cs = elementType.GetCompoundStructure();
                                var layers = cs.GetLayers();
                                foreach (var layer in layers)
                                {
                                    layer.Width = 0.0328; //10mm, not work
                                    break;
                                }
                                //cs.SetLayerWidth(0, 0.0328); // not work
                                //cs.SetLayers(layers); // not work
                                break;
                            }
                        }
                        transaction.Commit();
                    }
                    else
                    {
                        TaskDialog.Show("ERROR", "Start transaction 'update roof width' failed!");
                    }
                }
                catch (Exception ex)
                {
                    TaskDialog.Show("ERROR", ex.ToString());
                    if (transaction.GetStatus() == TransactionStatus.Started)
                        transaction.RollBack();
                }
            }
            return Result.Succeeded;
        }
    }
0 Likes
536 Views
2 Replies
Replies (2)
Message 2 of 3

naveen.kumar.t
Autodesk Support
Autodesk Support

HI @Anonymous,

 

Refer the below link to update the compound structure layers

Update Compound Structure Layer


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 3

Anonymous
Not applicable

Thanks for your reply.

but unfortunately, I tried the api in Revit 2016, it doesn't work.

there is the code im using, none of the indices I tried is useful:

 (For wall, it throws for some of the index, for extrusion roof, no exception but also no change)

 

var cs = elementType.GetCompoundStructure();
var newWidth = 0.00328; // 10mm
var layers = cs.GetLayers();
var idx = cs.GetFirstCoreLayerIndex();
var idx2 = cs.GetCoreBoundaryLayerIndex(ShellLayerType.Exterior);
var idx3 = cs.GetCoreBoundaryLayerIndex(ShellLayerType.Interior);

var ii = idx;
try
{
    foreach (var layer in layers)
    {
        cs.SetLayerWidth(ii, newWidth);
        ii++;
    }
}
catch (Exception ex)
{
    TaskDialog.Show("ERROR", string.Format("{0} \r\n   {1}\r\nidx1-3: {2},{3},{4}\r\nlayers count:{5}", ex.Message, ii, idx, idx2, idx3, layers.Count));
}

 

0 Likes