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?
Solved! Go to Solution.
Solved by ctm_mka. Go to Solution.
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
Hello Cristian,
I'm not sure I understand what you're trying to do. Can you elaborate?
Hi,
Sincerely
christian.stan
@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);
@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
@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);
,
Can't find what you're looking for? Ask the community or share your knowledge.