go to view - "faster"

go to view - "faster"

Joris.vd.Meulen
Collaborator Collaborator
579 Views
3 Replies
Message 1 of 4

go to view - "faster"

Joris.vd.Meulen
Collaborator
Collaborator

I've read a topic about the section - go to view which works but is slow. or perhaps I don't get it.

 

Goal:

I select a section and when the script runs, I want to make that section the active view.

 

Problem:

The section you select is a DB.Element (with category OST_VIEWERS) not a view. 

So I have to get the proper view.

 

Solution:

Suggested in an other topic was: get the corresponding view through FilteredElementCollector.

 

My approach (python but you get the point):
s = the selected section

    if s.Category.Name == "Views":
        viewer_name = s.Name
        collector = DB.FilteredElementCollector(revit.doc).OfCategory(DB.BuiltInCategory.OST_Views).WhereElementIsNotElementType().ToElements()
        for view in collector:            
            if view.Name == viewer_name:
                revit.activeview = view
                break
This works, BUT it is slow or at least: it is slower compared to select view, right mouse click, go to view.
 
So my question: how to improve this?
love python coding
0 Likes
580 Views
3 Replies
Replies (3)
Message 2 of 4

Joris.vd.Meulen
Collaborator
Collaborator

Hmm this would be better for starters

if s.Category.Name == "Views":
    refview = s.get_parameter(ID_PARAM) 
    revit.activeview = doc.getelement(refview)
love python coding
0 Likes
Message 3 of 4

dante.van.wettum
Advocate
Advocate

maybe this will make it some faster:

 

to get all views in your model:

 

FilteredElementCollector allViews = new FilteredElementCollector(doc).OfClass(typeof(Autodesk.Revit.DB.View));

 

 

you an also change the Autodesk.Revit.DV.View to be more specific.

e.g. if your looking specifically for plan views; your looking for "ViewPlan" instead of the generic view.

more about type of views here:

https://www.revitapidocs.com/2015/fb92a4e7-f3a7-ef14-e631-342179b18de9.htm

0 Likes
Message 4 of 4

sragan
Collaborator
Collaborator

I'm wondering if C# would run faster than Python?  This seems to indicate yes:

 

C# vs Python: What's the Difference? | Career Karma

 

 Quoting them "C# is a compiled language and Python is an interpreted one. Python’s speed depends heavily on its interpreter; with the main ones being CPython and PyPy. Regardless, C# is much faster in most cases. 

For some applications, it can be up to 44 times faster than Python. "

 

But if you are using visual studio, I'm not sure.   Maybe VS just compiles python into a DLL that is very similar to the same DLL it would make for a C# program?

 

Maybe the experts here know? 

0 Likes