I would be grateful for any kind of help on this:
I created a new Schedule in Revit, which lists a couple of family instances.
Is it possible to get all those family instances in Dynamo, based on the Revit Schedule’s name?
Is it possible to do this without the use of Python programming or any additional Dynamo Packages? Just with regular Dynamo nodes?
Hi,
I manually added a numid parameter (integer type)
must be doable via the API (I didn’t have much time, but if you search there must be examples)
I fed him with the Id
I extracted the table (Thank you Mr. Mahon by the way see link posted previously) to recover the order of the elements from the numid parameter
I could not transform the text into int under python (I had an error message) from the table we have that you text it seems
import clr
import sys
import System
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import Element,FilteredElementCollector,Transaction,ViewSchedule,SectionType,TableView,ElementId
schedview=UnwrapElement(IN[0])
#Get the document
doc=schedview.Document
coll=FilteredElementCollector(doc,schedview.Id).WhereElementIsNotElementType().ToElements()
t=Transaction(doc,"associate Id to numid")
t.Start()
for e in coll:
p=e.LookupParameter("numid")
id=e.Id.IntegerValue
p.Set(id)
t.Commit()
lst_ord=[]
table = schedview.GetTableData().GetSectionData(SectionType.Body)
nRows = table.NumberOfRows
nColumns = table.NumberOfColumns
for row in range(2,nRows):
data=TableView.GetCellText(schedview, SectionType.Body, row, nColumns-1)
lst_ord.append(data)
OUT = lst_ord
edit: string id to num
for row in range(2,nRows):
data=TableView.GetCellText(schedview, SectionType.Body, row, nColumns-1)
dnum=int(data)
eid=ElementId(dnum)
lst_ord.append(doc.GetElement(eid))
OUT = lst_ord
Hi, here is a second approach by collecting the fields which are used to order
I only did this with one field
what’s more, you have to check the storagetype of the parameter (which I didn’t do, minimalist approach)
and manage the spell with several parameters that I don’t know how to do
here is
import clr
import sys
import System
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import Element,FilteredElementCollector,Transaction,ViewSchedule,SectionType,TableView,ElementId,ScheduleDefinition,Document
schedview=UnwrapElement(IN[0])
#Get the document
doc=schedview.Document
#collector element
coll=FilteredElementCollector(doc,schedview.Id).WhereElementIsNotElementType().ToElements()
#number off field sort
nbsort=schedview.Definition.GetSortGroupFieldCount()
#List off fields
nbfield=schedview.Definition.GetSortGroupFields()
#number off the field the first
numberoffthefield=nbfield[0].FieldId
#ascending or descending
cond=nbfield[0].SortOrder
if cond == 0:
bsort=False
else:
bsort=True
#get the field
field=schedview.Definition.GetField(numberoffthefield)
#get th name off the field
namefield=field.GetName()
#Sort the list with one field
coll.sort(key=lambda x:x.LookupParameter(namefield).AsDouble(),reverse=bsort)
OUT =coll
if it can be useful to others
Sincerely
christian.stan
I can only use AI for code, think it struggled with transactions in the code to keep the output list. API is not available to create project parameters in R23
Ended up creating a temp project parameter, fill in ID, add to schedule, order and delete temp parameter.
Opened up another can of worms if Itemize every instance is off. Does your method handle that? Trying to resolve the way I’m doing it but becomes quite complex, especially if you had 3 varied rows after each other in a column.
Ok think I got it. Checks if Itemize every instance is on. If on does the method before. If off, the script turns it on and puts the last sort by footer on (not sure if last or all is most robust, just one footer on seems to work). Then when it gets the column fields it separates a group of varied by an empty space because of the footer being on. Using this replace the empty to make a list of the grouped varied and get the first item. Then use this to get the right element order. Then set the schedule back to its old settings. Think this makes sense what I said