Create Plan Views with out Duplicates

Create Plan Views with out Duplicates

J33C316
Advocate Advocate
279 Views
1 Reply
Message 1 of 2

Create Plan Views with out Duplicates

J33C316
Advocate
Advocate

The follow code creates a new plan view based on a level. It gets it's name from the level. Unfortunately if it's run again it creates a duplicate view who's name is the same except it appends a (1). See image. I'd like it not to create the duplicate view. Not sure how or where to loop through the existing view names.

 

Any suggestions?

 

                                    ViewPlan newfpview = ViewPlan.Create(doc, vft.Id, level.Id);
                                    newfpview.Name = level.Name;

2020-08-21_9-28-36.jpg 

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

bhprest
Advocate
Advocate

You can use a FilteredElementCollector to collect the views that interest you. This returns a collection that you can iterate over and test your logic against.

 

I would think that comparing the names of the views though is error prone. A ViewPlan has a LevelId property which is the ElementId of the level that the plan represents. The operation may prove to be more stable/predictable if you include this in your comparison logic.

0 Likes