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: 

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

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
sofia_feist
362 Views, 7 Replies

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

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?

Labels (1)
7 REPLIES 7
Message 2 of 8

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

Message 3 of 8

Hello Cristian,

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

Message 4 of 8

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

Message 5 of 8
ctm_mka
in reply to: sofia_feist

@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);
Message 6 of 8
sofia_feist
in reply to: ctm_mka

@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

Message 7 of 8

@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);

 

Message 8 of 8

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

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

Post to forums  

Autodesk Design & Make Report