Walltype delete Layers

Walltype delete Layers

sonicer
Collaborator Collaborator
285 Views
1 Reply
Message 1 of 2

Walltype delete Layers

sonicer
Collaborator
Collaborator

I have created a new wall type(first position - core and other layers are finish1, total count layers 7.

Why I can't delete all this layers?

I can delete only two the layers, but third time make it error and shot down without some error message.

Also if I debug code it freeze it and also Revit.

 

this is code

using (Transaction trans = new Transaction(_doc, "delete Layer"))
{
trans.Start();
structura.DeleteLayer(1);
structura.DeleteLayer(1);
structura.DeleteLayer(1);
structura.DeleteLayer(1);
newWall.SetCompoundStructure(structura);
trans.Commit();
}

sonicer_1-1673809068747.png

 

0 Likes
286 Views
1 Reply
Reply (1)
Message 2 of 2

Moustafa_K
Collaborator
Collaborator

I think you should use WallType instance that you extracted the "structura" from, and not newWall instance. because you are changing the wall Type properties. otherwise, it would be better to send a full code to reproduce your question.

see the below code and works fine for me:

  var eleRef = RvtApi.UiDoc.Selection.PickObject(ObjectType.Element);
                var wallEle = RvtApi.Doc.GetElement(eleRef) as Wall;
                if (wallEle == null) { return; }

                var wType = wallEle.Document.GetElement(wallEle.GetTypeId()) as WallType;
                var structura = wType.GetCompoundStructure();

                using (Transaction trans = new Transaction(RvtApi.Doc, "delete Layer"))
                {
                    trans.Start();
                    structura.DeleteLayer(1);
                    structura.DeleteLayer(1);
                    structura.DeleteLayer(1);
                    structura.DeleteLayer(1);

                    wType.SetCompoundStructure(structura);
                    trans.Commit();
                }

 

Moustafa Khalil
Cropped-Sharp-Bim-500x125-Autodesk-1