Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Deleting Fill Patterns

25 REPLIES 25
SOLVED
Reply
Message 1 of 26
R.van.den.Bor
3376 Views, 25 Replies

Deleting Fill Patterns

hey there,

 

I have a tool which deletes fill patterns in a family. Up till Revit 2014 it worked, but now in 2015 it doesn't anymore.

 

It looks like the standard Fill Patterns like Solid fill, Vertical, Diagonal up, Crosshatch ect. can't be deleted anymore?? 

 

With RevitLookup I concluded that all 'standard' fill patterns have an ElementId which consists of less digits then 'user fill patterns'.

So I've made the workaround like below, but this will only bypass them. Does anybody know how I can delete these standard fill patterns in a family ?

 

public static void RemoveFillPatterns(Document doc)
{
List<FillPatternElement> fillp = new FilteredElementCollector(doc).WherePasses(new ElementClassFilter(typeof(FillPatternElement))).OfType<FillPatternElement>().ToList();


foreach (FillPatternElement HatchPattern in fillp)
{
try
{
if (HatchPattern.Id.ToString().Length > 5) doc.Delete(HatchPattern.Id);
}
catch (Exception ex)
{

   // apperently a standard fill pattern which can't be deleted in 2015
   MessageBox.Show(ex.Message);
}
}
}

 

 

Kind regards,
Remy van den Bor
ICN Solutions B.V.
Liked this post or found it usefull, don't forget the Kudo It won't hurt (at least not me).
25 REPLIES 25
Message 21 of 26
06041983
in reply to: 06041983

Sorry for my bad english.
Message 22 of 26
06041983
in reply to: 06041983

Sorry for my bad english )

Message 23 of 26
jeremytammik
in reply to: 06041983

Yes, apparently that is normal. 

 

Don't worry about the language, it is fine!

 

Best regards,

 

Jeremy



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

Message 24 of 26
Hugh_Compton
in reply to: jeremytammik

 

Eek, I am finding that it is working to well - all of the patterns except the Solid Fill ones are being deleted even if they are used in some regions.

 

Is there a way to filter out the ones that are being used in Regions? 

 

Thanks

Message 25 of 26
kyeung
in reply to: R.van.den.Bor

Hello,

 

Is there already some sort of workaround for the solid fill deleting issue?

I now have a project with like 100 solid fills and would like to purge these. Dynamo couldn't delete them either...

Tried hatchkit as well without any results.

 

Anybody solved this?

Message 26 of 26
CJModis
in reply to: kyeung


@kyeungнаписал (-а):

Hello,

 

Is there already some sort of workaround for the solid fill deleting issue?

I now have a project with like 100 solid fills and would like to purge these. Dynamo couldn't delete them either...

Tried hatchkit as well without any results.

 

Anybody solved this?


Yes. Yesterday there was a similar task - I solved the problem in 5 minutes))
So, there is a file in which 30 solid hatches with the names "Сплошная заливка1", "Сплошная заливка2", etc. ("Solid Fill") Revit does not allow them to be deleted. So what do you need? That's right - they need to be changed first! It takes two transactions (maybe one - I did not try) - in the first one I change the fill pattern, and in the second I delete the element by the id. To replace the fill pattern, I took the first one that I found that is not solid - "Кирпич (Brick)".

using System;
using System.Linq;
using System.Windows;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;

namespace Reinforcement
{
    [Transaction(TransactionMode.Manual)]
    public class TestCommand : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            var doc = commandData.Application.ActiveUIDocument.Document;
            var fpe = new FilteredElementCollector(doc).OfClass(typeof(FillPatternElement)).Cast<FillPatternElement>().ToList();
            var f = fpe.First(fp => fp.Name.Equals("Кирпич")).GetFillPattern();
            foreach (FillPatternElement element in fpe)
            {
                try
                {
                    var elId = ElementId.InvalidElementId;
                    using (Transaction tr = new Transaction(doc, "TEST"))
                    {
                        tr.Start();
                        if (element.Name.Contains("Сплошная заливка") && !element.Name.Equals("Сплошная заливка"))
                        {
                            element.SetFillPattern(f);
                            elId = element.Id;
                        }

                        tr.Commit();
                    }
                    if(elId != ElementId.InvalidElementId)
                    using (Transaction tr = new Transaction(doc, "TEST"))
                    {
                        tr.Start();
                        doc.Delete(elId);
                        tr.Commit();
                    }
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.Message + Environment.NewLine + exception.StackTrace);
                }
            }
            return Result.Succeeded;
        }
    }
}

Profit

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community