So, I’ve searched the site through google, and I couldn’t find something similar…which I am surprised by…
I have a script which collects all sections in the view, in this case a floor plan, and compares the placed sheet of the floor plan with the placed sheet of the section views. If they match, they stay. If they don’t, they are hidden in the view.
I run this script each time I publish a set of drawings, and would like it to work for any project…which it would…if it weren’t for one little dynamo quirk. I can’t select the views.
If I use the select by category and view, there is no good way for me to select the view category, other than to have a selection input for the user to select a section. The categories available don’t return the same ID as the targeted category (the one the user selects.)
I think the past, the categories drop-down contained two “views” as categories, and now it’s only one.
Anyways, I have the ID of the category, and I was wondering if a pythong-god could write me a short little script to select the category by ID:
-2000278
In return, I will thank you vigorously (or at least with an excalamation point) and give you a heart-shaped like.
You need to show us what you’ve done so far and where the exact issue lies. You can definitely select views by category, but if you’re making a UI selection currently then you’re probably selecting the viewport and not the actual view - which would have a different Id.
Do you even need to select views? Wouldn’t you want this to run on all views on sheet every time? It sounds like you’re making this more complicated than it needs to be.
Also, please don’t ask for people to do your work for you. Everyone is happy to help, but you’re ultimately responsible for doing your own work.
I’m a bit confused -
Do you want to get all non-elevation views from the project (so scheduled, plan views, ceiling plan views, details, etc.) or just a particular type?
If the former, why not use the drop-down for all views (in whatever the localization is), and then filter out elevation/section views by their type or view family (parameters if memory serves)?
It looks like the Id you’re referencing is from selecting a view from the UI, I’m assuming from a sheet. What does the node show you have selected? I’m guessing it’s grabbing the Viewport and not the View, which is why you’re seeing different Ids.
I agree with Jacob, there seems like there would be an easier way to select one or more views. Data-Shapes could also be an option to allow the user to select any number of views based on name or sheet information.
The issue is NOT with the view, it is referencing the correct view and there are definitely elements in it. For example, if I select a section / detail element and grab that category, it works.
But I don’t want to have to select a section every time, I want to roll-this out via pyrevit and have it work with one-click.
By the looks of it, I need to get the OST_Viewers.
I don’t much care if I use the “OST_Viewers” or the “ID,” I just need some way to get the correct category. In my localized version, I cannot find it. I’ve just spent another 30 Minutes on it and am nowhere closer to solving the issue.
What isn’t working? From what I can see you’ve got the one item in the one view… We lack the larger context of what you’re facing and an understanding of what you’re trying to achieve.
Again, what I want to do is very simple. I want to have a small python script return a category based on a defined ID. In this case, the ID is -2000278. If I use the OST_Viewers to get that category, that’s fine too.
The “simple” stuff, I’ve already done and have wasted a lot of time doing.
I’m still a bit lost, but trying to help. Often times when we search and search and search and come up empty I find it’s because we’re approaching the problem in a way which isn’t how the Revit API is built to work, which is why I’m trying to understand what you’re actually after. Without a graph or dataset it’s hard to understand what you’re after.
Since these are built-in categories, why not use the built-in category enumerator? If that doesn’t work for some reason, how about get element?
Ah. Thought you were looking for python guidance not working code, hence your reference to PyRevit. You’re going to have to build up some Python chops if you’re pushing that way.
As a start I suggest getting up to speed on your template, I like a variation of this one. Then you can start to push further.
This should get you what you’ve requested, though I’m not sure how stable it will be:
import sys , clr
[clr.AddReference(i) for i in ["RevitNodes", "RevitServices", "RevitAPI"]]
import Revit
clr.ImportExtensions(Revit.Elements)
import RevitServices, Autodesk
from RevitServices.Persistence import DocumentManager
from Autodesk.Revit.DB import Document, ElementId
doc = DocumentManager.Instance.CurrentDBDocument
targetId = ElementId(IN[0])
elem = doc.GetElement(targetId)
if elem: OUT = elem
else:
cat = [i for i in doc.Settings.Categories if i.Id == targetId][0]
if cat: OUT = cat
else:OUT = "Element with ID {} not in document.".format(str(idNumber))