How delete Level element?

How delete Level element?

Anonymous
Not applicable
1,474 Views
4 Replies
Message 1 of 5

How delete Level element?

Anonymous
Not applicable

It's so surprise,the document.delete(ElementId id) can't delete the element of Level!By the way,I tried delete all ViewPlans which connect with the level before delete it!

0 Likes
1,475 Views
4 Replies
Replies (4)
Message 2 of 5

Joe.Ye
Alumni
Alumni
Hello, I just wrote some SharpDevelop code, the macro can delete any plan level without deleting any related views. public void ShowJoinedElemnet() { Document doc = this.ActiveUIDocument.Document; Selection sel = this.ActiveUIDocument.Selection; Reference ref1 = sel.PickObject(ObjectType.Element,"Please an element"); Element elem = doc.GetElement(ref1); ICollection ids = JoinGeometryUtils.GetJoinedElements(doc,elem); foreach(ElementId id in ids) { Element item = doc.GetElement(id); sel.Elements.Add(item); } } What's the error message did you get? Did you try start a transaction?


Joe Ye
Contractor
Developer Technical Services
Autodesk Developer Network
Message 3 of 5

Anonymous
Not applicable

Wow, man... I didn't expect the use of C# in revit. 

I've got the following error - "Expected class, delegate, enum, interface, or struct (CS1518) " 

I've got no clue what it means, but I'm willing to understand since I'm stuck at the same point as the person who opened the thread.

0 Likes
Message 4 of 5

jeremytammik
Autodesk
Autodesk

If you are surprised by the use of C# in the Revit API, I suggest you take a look at the getting started material:

 

http://thebuildingcoder.typepad.com/blog/about-the-author.html#2

 

Best regards,

 

Jeremy



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

Message 5 of 5

aurbinat
Explorer
Explorer

I created this method for deleting all levels in a document, the trick here is to pass the parameter for document.Delete(ICollection) with a ICollection, not as a single element. Since ICollection is only and interface I used List for adding ElmentId.  I think it could work even if you add just one element, which is your case.

public int DeleteExistingLevels(Document document){
            int deleted = 0;
            FilteredElementCollector collector = new FilteredElementCollector(document);
            ICollection<Element> levels = collector.OfClass(typeof(Level)).ToElements();
            List<ElementId> elementsToBeDeleted = new List<ElementId>();

            foreach(Element element in levels)
            {
                elementsToBeDeleted.Add(element.Id);
                deleted++;
            }
            document.Delete(elementsToBeDeleted);       
            return deleted;
        }

 

0 Likes