Announcements

Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.

How to distinguish between 3D views that have viewers and not

sofia_feist
Enthusiast
Enthusiast

How to distinguish between 3D views that have viewers and not

sofia_feist
Enthusiast
Enthusiast

I'm using a FilteredElementCollector to get all the 3D views in my project. 

 

var views3D = new FilteredElementCollector(GlobalObjects.doc).OfClass(typeof(View3D)).Cast<View3D>();

 


This collector is returning all my 3D views, including a view that is not visible in my project browser. Trying to change the orientation of this invisible view (view3D.SetOrientation(viewOrientation3D)) is also returning an exception with the message:

 

{"View is missing its viewer."}

 

What is this "Viewer" property that makes some 3D views visible in the Project Browser and editable, while other not? I can't really look up this view with Revit LookUp since I can't find it anywhere but debugging the findings of my collector shows me that this view does not have an Origin, SketchPlane or CropBox. Are those it? How do I distinguish between 3D views that have viewers and 3D views that have not?

0 Likes
Reply
Accepted solutions (1)
338 Views
7 Replies
Replies (7)

christian.stan
Advocate
Advocate

Hello, There must be more effective, most certainly

I'm a beginner.

I have a problem with your GlobalObjects.doc

var views3D = new FilteredElementCollector(doc).OfClass(typeof(View3D)).Cast<View3D>();
            String mes="";
            foreach (View3D v in views3D)
					{
						mes+="\n"+v.Name;
					}
            TaskDialog.Show("Revit info",mes);
            var queryview= from v in views3D where v.Origin != null select v;
            List<View3D> views3Dfiltered=queryview.ToList<View3D>();
            String mes2="";
            foreach (View3D v in views3Dfiltered)
					{
						mes2+="\n"+v.Name;
					}
            TaskDialog.Show("Revit info",mes2);

 

Sincerely
christian.stan

0 Likes

sofia_feist
Enthusiast
Enthusiast

Hello Cristian,

I'm not sure I understand what you're trying to do. Can you elaborate?

0 Likes

christian.stan
Advocate
Advocate

Hi,

  1. I apply a collector like you but on my current document
  2. I scan the 3D views to extract the names
  3. I send these in a dialog box
  4. I create a blank View3d typed list
  5. I created a query that filters 3d views that do not have an origin
  6. I apply it
  7. I do another scan on my ecrete list
  8. I send this in a dialog box

Sincerely

christian.stan

0 Likes

ctm_mka
Advocate
Advocate
Accepted solution

@sofia_feist  based on the limited code you've provided (more is always better to help with) im guessing you are getting view templates. to filter them out, change your code to this:

var views3D = new FilteredElementCollector(GlobalObjects.doc).OfClass(typeof(View3D)).Cast<View3D>().Where(x=> x.IsTemplate == false);

sofia_feist
Enthusiast
Enthusiast

@ctm_mka Thank you for your answer! You are right! They were view templates. I thought View Templates would have a different datatype and not appear in my 3D view FilteredElementCollector.

As for the code I shared, that was literally all I'm running and I was confused as to why I was getting views that were not visible in my Project Browser. Thanks for the clarification

0 Likes

sofia_feist
Enthusiast
Enthusiast

@christian.stan Are you trying to refactor your code? If so, System.Linq methods have you covered and can replace for/foreach loops.

var views3D = new FilteredElementCollector(doc).OfClass(typeof(View3D)).Cast<View3D>();
string mes = String.Join("\n", views3D.Select(v => v.Name));
TaskDialog.Show("Revit info", mes);
string mes2 = String.Join("\n", views3D.Where(v => v.Origin != null).Select(v => v.Name));
TaskDialog.Show("Revit info", mes2);

 

christian.stan
Advocate
Advocate

hi, no I was trying to answer your problem, but M. @ctm_mka code is much more synthetic thanks for the tip with System.Linq

Sincerely

christian.stan