Not all views have element Id?

Hey all, I wrote a script to get all views in project and get there element type Id so that I can select a specific type and I notice that some of the views ElementType return null - is there a reason for that?

In addition to that, I basically get the 3D view family type and compare the views Element Id’s in order to filter out the 3D family type. Question is: is there any recommendation on how to create a filter in the FilteredElementCollector to get the 3D view type in this early stage?
Thanks.

can you post the python or the DYN? Only way I think people can help on this.

All the python script does is return the list of all views object in the project (like seen in the pic) the issue is the DScript code to get the elements type id which is where it returns part of the views type as null. In this case you see that the id returns null but also the step prior when calling the ElementType those same views returned null…
If you still want the python I’ll have no problem and post it. I just think its irrelevant…

Hi Zvith…do you have viewtemplate in there ?

In the python code? I have simply what is in the pic above - I got all the view elements in the project and wrote the code to get the ElementType ID.
I managed to get the intersecting elements that are also 3D family types.
I was just wondering why there were some views that when getting their elementType it returns null and if that is something normal in case I would come across it again further down the road.

Regarding creating a filter, I was just wondering if it is possible to get create a filter that does the job of getting only the views that are 3D like by the following script:

*Following is the code I use to collect all view elements in project:

collector = FilteredElementCollector(doc)
collector.OfCategory(BuiltInCategory.OST_Views).WhereElementIsNotElementType()
views = collector.ToElements()

OUT = views

I don’t know if the “WhereElementIsNotElementType()” method was necessary but it still gives the output needed.

Some of those will be view templates, browsers and sheets I think, they overlap with the view class in a collector last I tried. The nulls are likely triggered by 3d view templates which can’t be passed through dynamo (only within a python node).

4 Likes

yes Gavin think thats the issue here…

2 Likes

So I understand that there are elements under the views class that don’t have ElementTypes, correct?

Correct, the Views class includes also what we call ViewTemplates, ProjectBrowser, and references for views such as Architectural Plan, Structural Section… …

Considering you are starting from a Python script to collecting all the views, I’d suggest you apply a filter to your collection like this:

all_views = FilteredElementCollector(doc).OfClass(View).WhereElementIsNotElementType()

filter = lambda v: not v.IsTemplate and v.GetTypeId() != ElementId.InvalidElementId

all_views = [v for v in all_views if filter(v)]
all_viewType_ids = [v.GetTypeId() for v in all_views]

OUT = all_views, all_viewType_ids

In this case, I also exported the id of the types, since I understood it was what you were looking for. In case you don’t want, it’s just about to change the last row in “OUT = all_views”

4 Likes

I changed the code and it gives me the list of all views’ ids but for some reason the equal condition returns all of them false, even though you one should return positive (I marked the matching Ids in the pic)…

Another minor issue which is occuring in a must the my custom nodes is that when I put a comment in the output - it appears as part of the output name and not as a description. Any solution to this?

The Node's Ouputs Comment Input

The Appearance On The Custom Node

image

Comments should be put first in the output and preceded by two forward slashes. On the next line you put your variable name for the output. Some words wont be accepted if they are used in code blocks elsewhere (e.g. list, if, or).

about the matching issue. It is because of the class of the objects: from python are coming “ElementId”, while from the dynamo OOTB are coming integers.

Converting them both to integers or strings should do the trick.

1 Like

Thats done the job. Thanks!

1 Like

Hi @Giuseppe_Dotto thank you for your python

maybe only
filter = lambda v: v.GetTypeId() != ElementId.InvalidElementId
skip already all views templates, why you use also not v.IsTemplate ? Thanks in advance
Cheers