Python - Adding Fields to a Schedule

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Dear Revit Fam,
I am trying to create a python program that will take whatever elements we want from a view and export them to a single schedule. In this case, I am trying to take the name, count, and comments from a boxout element and create a schedule populated with these three fields. Here's the thing- no Dynamo. My boss wants me to do this by hand so that I can learn how to program in python, and create functionality for the company. But for the life of me I cannot figure out why this isn't working I have tried many many things and have scoured the internet. It's like the add fields command is fine, but it doesn't understand what specific field I want? It insists that the field Count (for example) is not defined, even though towards the bottom you can see I have a list command that prints all the available fields. Please help a beginner out I m losing my mind!!
Here is my code:
import os
import clr
import sys
import Autodesk
from Autodesk.Revit.DB import BuiltInCategory as Bic
from Autodesk.Revit.DB import FilteredElementCollector as Fec
from Autodesk.Revit.DB import Transaction
from Autodesk.Revit.DB import FamilyManager as FM
from Autodesk.Revit.DB import*
#reference to the current open Revit model
doc=__revit__.ActiveUIDocument.Document
#Parameters
length_param="Sleeve_Depth"
height_param= "Sleeve_Width"
thickness_param="Sleeve_Length"
eVolve_param="eVolve_KitId"
#Select all conduit fittings and filter for box outs
boxouts = Fec(doc).OfCategory(Bic.OST_ConduitFitting).WhereElementIsNotElementType().ToElements()
tx= Transaction(doc, 'Box Out Dimensions')
tx.Start()
for boxout in boxouts: #here we push out the dimensions of our boxouts to the comments section
if boxout.LookupParameter(eVolve_param).AsString() == "BOS":
length=boxout.LookupParameter(length_param).AsValueString()
height=boxout.LookupParameter(height_param).AsValueString()
thickness=boxout.LookupParameter(thickness_param).AsValueString()
boxout.LookupParameter("Comments").Set( length + "L" +' x '+ height +"H" + ' x ' + thickness + "Thick")
id = ElementId.InvalidElementId; # this might be a problem, but we have it because we ultimtely want a multi-category view
tx.Commit()
## *************************************** Adding Fields to Schedule ********************************************
tx.Start()
#Create Schedule
vs = ViewSchedule.CreateSchedule(doc, id)
# Name Schedule
vs.Name='Box Out Schedule'
# Create List of scheduable Fields, so I know what to call in AddField
list = vs.Definition.GetSchedulableFields()
##**************************************** Throwing Spaghetti at the wall *************************************************
#Attempt to add Feilds to Schedule here
#vs.Definition.AddField(Count) ##Says Count not defined
#vs.Definition.AddField(boxout) ## says expected a FieldType but got a Family Instance
#vs.Definition.AddField(boxout, Count) ## Count not defined
# for sf in list: ##Returns list of available fields, is very long, I saved to NotePad
# print(sf.ParameterId) ## but it returns all the paramID's and Types, I dont understand why is says
# print(sf.GetName(doc)) ## Count not defined
# print(sf.GetType())
# print(15*'-')
tx.Commit()
#*********************************************** END ***********************************************
I feel that this should be a super simple command, but for the life of me I cannot get it to work. Thanks!!!