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: 

Finding view references

17 REPLIES 17
SOLVED
Reply
Message 1 of 18
J33C316
1819 Views, 17 Replies

Finding view references

J33C316
Advocate
Advocate

I have match line view references that I'm trying to delete with no luck. The problem is in the vrIds FilteredElementCollector. It doesn't find any.

 

Thanks in advance for the help.

 

var views = new FilteredElementCollector(doc).OfClass(typeof(View)).Cast<View>()
            .Where(vw => vw.ViewType == ViewType.FloorPlan || vw.ViewType == ViewType.CeilingPlan || vw.ViewType == ViewType.Elevation).ToList()
            .Where(vw => vw.IsTemplate == false);

            int vrCount = 0;

            using (Transaction vr = new Transaction(doc))
                try
                {
                    vr.Start("Delete View Refereneces");
                    foreach (var vw in views)
                    {
                        var vrIds = new FilteredElementCollector(doc, vw.Id)
                        .OfClass(typeof(FamilyInstance)).OfCategory(BuiltInCategory.OST_ReferenceViewer)
                        .ToElementIds();
                        foreach (var vr_id in vrIds)
                        {
                            doc.Delete(vr_id);
                            vrCount++;
                          }
                    }

 

0 Likes

Finding view references

I have match line view references that I'm trying to delete with no luck. The problem is in the vrIds FilteredElementCollector. It doesn't find any.

 

Thanks in advance for the help.

 

var views = new FilteredElementCollector(doc).OfClass(typeof(View)).Cast<View>()
            .Where(vw => vw.ViewType == ViewType.FloorPlan || vw.ViewType == ViewType.CeilingPlan || vw.ViewType == ViewType.Elevation).ToList()
            .Where(vw => vw.IsTemplate == false);

            int vrCount = 0;

            using (Transaction vr = new Transaction(doc))
                try
                {
                    vr.Start("Delete View Refereneces");
                    foreach (var vw in views)
                    {
                        var vrIds = new FilteredElementCollector(doc, vw.Id)
                        .OfClass(typeof(FamilyInstance)).OfCategory(BuiltInCategory.OST_ReferenceViewer)
                        .ToElementIds();
                        foreach (var vr_id in vrIds)
                        {
                            doc.Delete(vr_id);
                            vrCount++;
                          }
                    }

 

17 REPLIES 17
Message 2 of 18
jeremytammik
in reply to: J33C316

jeremytammik
Autodesk
Autodesk

I don't know what OST_ReferenceViewer stands for.

  

Do you?

  

Do the views that you wish to delete really have this category?

  

Use RevitLookup to check.

 

All you are using from the filtered element collector are the view element ids.

 

I would suggest extracting and storing only those ids in a list, and forgetting about the `views` variable.

 

That would make it cleaner and clearer.

 

 



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

0 Likes

I don't know what OST_ReferenceViewer stands for.

  

Do you?

  

Do the views that you wish to delete really have this category?

  

Use RevitLookup to check.

 

All you are using from the filtered element collector are the view element ids.

 

I would suggest extracting and storing only those ids in a list, and forgetting about the `views` variable.

 

That would make it cleaner and clearer.

 

 



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

Message 3 of 18
J33C316
in reply to: jeremytammik

J33C316
Advocate
Advocate

Hi Jeremy,

Thanks for the reply. I'm not trying to delete the view just trying to go through all of them and delete any view references in them. RevitLookup shows that they are of the category OST.ReferenceViewer. See attached image.

 

Thanks again for the help.

2020-07-30_8-14-55.jpg

 
 
0 Likes

Hi Jeremy,

Thanks for the reply. I'm not trying to delete the view just trying to go through all of them and delete any view references in them. RevitLookup shows that they are of the category OST.ReferenceViewer. See attached image.

 

Thanks again for the help.

2020-07-30_8-14-55.jpg

 
 
Message 4 of 18
jeremytammik
in reply to: J33C316

jeremytammik
Autodesk
Autodesk

Looks OK to me...

 



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

0 Likes

Looks OK to me...

 



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

Message 5 of 18
62BJW
in reply to: jeremytammik

62BJW
Advocate
Advocate

Me too but it still doesn't delete them. I have used similar code to delete other elements of different categories without issues. 

0 Likes

Me too but it still doesn't delete them. I have used similar code to delete other elements of different categories without issues. 

Message 6 of 18
jeremytammik
in reply to: 62BJW

jeremytammik
Autodesk
Autodesk

Maybe the view reference is not a self-determined independent element, but dependent on something else.

 

In that case, it can be considered a sort of view of cause, just a symptom.

 

In that case, it might help to find out what is generating it in the first place.

 



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

0 Likes

Maybe the view reference is not a self-determined independent element, but dependent on something else.

 

In that case, it can be considered a sort of view of cause, just a symptom.

 

In that case, it might help to find out what is generating it in the first place.

 



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

Message 7 of 18
J33C316
in reply to: jeremytammik

J33C316
Advocate
Advocate

This is probably not what you mean by "what is generating it in the first place" but just in case it is...

 

2020-07-30_11-14-15.jpg

 

 

0 Likes

This is probably not what you mean by "what is generating it in the first place" but just in case it is...

 

2020-07-30_11-14-15.jpg

 

 

Message 8 of 18
jeremytammik
in reply to: J33C316

jeremytammik
Autodesk
Autodesk

You can analyse exactly what the effect of running that commands is, specifically, what elements that adds to the Revit database, by using the element lister utility as described in How to research to find a Revit API solution:

  

https://thebuildingcoder.typepad.com/blog/2017/01/virtues-of-reproduction-research-mep-settings-onto...

 

Knowing what elements are added might help understand how to remove them again.

 



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

0 Likes

You can analyse exactly what the effect of running that commands is, specifically, what elements that adds to the Revit database, by using the element lister utility as described in How to research to find a Revit API solution:

  

https://thebuildingcoder.typepad.com/blog/2017/01/virtues-of-reproduction-research-mep-settings-onto...

 

Knowing what elements are added might help understand how to remove them again.

 



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

Message 9 of 18
62BJW
in reply to: jeremytammik

62BJW
Advocate
Advocate

Thanks. I've created an account on GiHub but can't seem to locate the element lister file(s). Having trouble navigating their site.

0 Likes

Thanks. I've created an account on GiHub but can't seem to locate the element lister file(s). Having trouble navigating their site.

Message 10 of 18
RPTHOMAS108
in reply to: 62BJW

RPTHOMAS108
Mentor
Mentor

What type of ViewPlan are you wanting to remove the items from, you've not listed all the plan ViewTypes in the collector?

 

ViewType.AreaPlan
ViewType.EngineeringPlan

0 Likes

What type of ViewPlan are you wanting to remove the items from, you've not listed all the plan ViewTypes in the collector?

 

ViewType.AreaPlan
ViewType.EngineeringPlan

Message 11 of 18
J33C316
in reply to: RPTHOMAS108

J33C316
Advocate
Advocate

I have it search all of these types.

 

ViewType.FloorPlan

ViewType.CeilingPlan

ViewType.Elevation

 

Thanks

0 Likes

I have it search all of these types.

 

ViewType.FloorPlan

ViewType.CeilingPlan

ViewType.Elevation

 

Thanks

Message 12 of 18
RPTHOMAS108
in reply to: J33C316

RPTHOMAS108
Mentor
Mentor

I can see that, are those the only types you are interested in? i.e. if the view discipline is Structural then the type will be EngineeringPlan not FloorPlan.

0 Likes

I can see that, are those the only types you are interested in? i.e. if the view discipline is Structural then the type will be EngineeringPlan not FloorPlan.

Message 13 of 18
jeremytammik
in reply to: 62BJW

jeremytammik
Autodesk
Autodesk

You don't need an account. You can download stuff without logging in at all.

 

I strongly recommend using GitHub if you do any programming yourself whatsoever!

 

You don't need to download the whole thing, just implement the Lab2_1_Elements:.

 

You can grab the code directly:

 

https://github.com/jeremytammik/AdnRevitApiLabsXtra/blob/master/XtraCs/Labs2.cs#L429-L540

 

It is totally trivial, really:

 

  • Grab all Revit database elements
  • List their element ids and whatever other information you require to a text file

 

With this command in place, you can compare two snapshots of the database by performing a diff between the two text files.

 



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

0 Likes

You don't need an account. You can download stuff without logging in at all.

 

I strongly recommend using GitHub if you do any programming yourself whatsoever!

 

You don't need to download the whole thing, just implement the Lab2_1_Elements:.

 

You can grab the code directly:

 

https://github.com/jeremytammik/AdnRevitApiLabsXtra/blob/master/XtraCs/Labs2.cs#L429-L540

 

It is totally trivial, really:

 

  • Grab all Revit database elements
  • List their element ids and whatever other information you require to a text file

 

With this command in place, you can compare two snapshots of the database by performing a diff between the two text files.

 



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

Message 14 of 18
vkelani
in reply to: J33C316

vkelani
Contributor
Contributor

Hi,

 

You can apply parameter filter to fec. Use BuiltinParameter ELEM_CATEGORY_PARAM_MT, elementid of this parameter will be your parameter value provider, and to the value to check would be View Reference AsValueString. This way, you will get all the view references in the view by using filteredelementcollector(doc, view.id).

 

Cheers,

Vishal Kelani

0 Likes

Hi,

 

You can apply parameter filter to fec. Use BuiltinParameter ELEM_CATEGORY_PARAM_MT, elementid of this parameter will be your parameter value provider, and to the value to check would be View Reference AsValueString. This way, you will get all the view references in the view by using filteredelementcollector(doc, view.id).

 

Cheers,

Vishal Kelani

Message 15 of 18
RPTHOMAS108
in reply to: J33C316

RPTHOMAS108
Mentor
Mentor
Accepted solution

Also the object is not a FamilyInstance, it is showing as Element in RevitLookup (it would tell you there it was FamilyInstance if it was one). Therefore you will likely not find it by filtering for class of type FamilyInstance. If you take that out you may find them.

Also the object is not a FamilyInstance, it is showing as Element in RevitLookup (it would tell you there it was FamilyInstance if it was one). Therefore you will likely not find it by filtering for class of type FamilyInstance. If you take that out you may find them.

Message 16 of 18
J33C316
in reply to: RPTHOMAS108

J33C316
Advocate
Advocate

you're right, I missed that. It's recycled code from another app of mine. I'll look into it. Thanks

0 Likes

you're right, I missed that. It's recycled code from another app of mine. I'll look into it. Thanks

Message 17 of 18
J33C316
in reply to: RPTHOMAS108

J33C316
Advocate
Advocate

That was it. Thank you very much!

0 Likes

That was it. Thank you very much!

Message 18 of 18
K.Calero_Arup
in reply to: RPTHOMAS108

K.Calero_Arup
Contributor
Contributor

@RPTHOMAS108 - After accessing these view reference elements, can they also be updated programatically so that the "Target View" (read only parameter) is modified to another view? Thank you

0 Likes

@RPTHOMAS108 - After accessing these view reference elements, can they also be updated programatically so that the "Target View" (read only parameter) is modified to another view? Thank you

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

Post to forums  

Autodesk Design & Make Report