Analytical model filtering for FilteredElementsCollector?

Analytical model filtering for FilteredElementsCollector?

WorldDue
Enthusiast Enthusiast
1,005 Views
5 Replies
Message 1 of 6

Analytical model filtering for FilteredElementsCollector?

WorldDue
Enthusiast
Enthusiast
 UIApplication uiApp = commandData.Application;
            Document doc = uiApp.ActiveUIDocument.Document;

            FilterIntegerRule rule = new FilterIntegerRule(new ParameterValueProvider(new ElementId(BuiltInParameter.STRUCTURAL_ANALYTICAL_MODEL)), new FilterNumericEquals(), 1);
            ElementParameterFilter filter = new ElementParameterFilter(rule);

            FilteredElementCollector filterCol = new FilteredElementCollector(doc);
            filterCol.Where(e => e.CanHaveAnalyticalModel()); //This absolutely did nothing???!
            filterCol.WhereElementIsNotElementType();
            filterCol.WherePasses(filter);


            var eleList = (List<Element>)filterCol.ToElements();
            if(eleList.Count==0)
            {
                TaskDialog.Show("Hint", "There are no enabled AnalyticalModels");
            }


            foreach (Element e in eleList)
            {
                using (Transaction trans = new Transaction(doc))
                {
                    trans.Start("Disabling Analytical Model");
                   bool success= e.get_Parameter(BuiltInParameter.STRUCTURAL_ANALYTICAL_MODEL).Set(0);
                    trans.Commit();

                }

            }

I have noticed that this code can filter elements based on which have enabled analytical model to disable them, however if I used the linq where extended function to query for any element that can have analytical models, without filtering for this custom rule made in the above code, it just gives back many irrelevant elements? I wonder why did this happen?

0 Likes
1,006 Views
5 Replies
Replies (5)
Message 2 of 6

RPTHOMAS108
Mentor
Mentor

Lots of things you wouldn't imagine can have an analytical model but not in reality.

 

Fewer have STRUCTURAL_ANALYTICAL_MODEL built-in parameter with .IsReadOnly = false

 

Are you saying the filter doesn't work, try it with a wall sweep (OST_Cornices). I believe the problem is that common base elements allow analytical models e.g. You can't set it on an architectural wall but you can if you turn the wall into a structural wall, however the wall class returns true since it can have analytical model depending on form of wall.

 

 

0 Likes
Message 3 of 6

WorldDue
Enthusiast
Enthusiast

Thing is, it even picked up Levels and annotation models...

0 Likes
Message 4 of 6

RPTHOMAS108
Mentor
Mentor

Probably not working then as Levels return false for .CanHaveAnalyticalModel (like all other annotation categories).

 

C#

 

UIApplication App = commandData.Application;
            Document Doc = App.ActiveUIDocument.Document;
            const BuiltInParameter AmP = BuiltInParameter.STRUCTURAL_ANALYTICAL_MODEL;

            FilteredElementCollector FEC = new FilteredElementCollector(Doc);
            IEnumerable<Element> Ien = FEC.WhereElementIsNotElementType().Where(J => J.CanHaveAnalyticalModel() == true)
                .Where(jx => jx.get_Parameter(AmP).AsInteger() == 1);

            using (Transaction Tx = new Transaction(Doc, "Disable analytical model"))
            {
                if (Tx.Start() == TransactionStatus.Started)
                {
                    foreach (Element item in Ien)
                    {
                        item.get_Parameter(AmP).Set(0);
                       
                    }
                    Tx.Commit();
                }
            }
            return Result.Succeeded;

 

VB

       Dim App As UIApplication = commandData.Application
        Dim Doc As Document = App.ActiveUIDocument.Document
        Const AmP As BuiltInParameter = BuiltInParameter.STRUCTURAL_ANALYTICAL_MODEL

        Dim FEC As New FilteredElementCollector(Doc)
        Dim Ien As IEnumerable(Of Element) = FEC.WhereElementIsNotElementType.Where(Function(J) J.CanHaveAnalyticalModel = True). _
            Where(Function(jx) jx.Parameter(AmP).AsInteger = 1)

        Using Tx As New Transaction(Doc, "Disable analytical model")
            If Tx.Start = TransactionStatus.Started Then
                For Each item As Element In Ien
                    item.Parameter(AmP).Set(0)
                Next
                Tx.Commit()
            End If
        End Using

        Return Result.Succeeded
Message 5 of 6

RPTHOMAS108
Mentor
Mentor

In the above you should add the check for .IsReadOnly as originally noted.

0 Likes
Message 6 of 6

hvdsidf
Enthusiast
Enthusiast

Dear All,

 

I run your code but there is an error as below:

Problem Disable Model Analytic.JPG

And in Revit, it shows this message:

Problem Disable Model Analytic 1.JPG

 

Please help me, I'm a beginner with Revit API.

 

Thanks alot for your help  and Best Regards,

0 Likes