Hello,
an example using Clipboard and Paste
# coding: utf-8
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc = uiapp.ActiveUIDocument
import System
from System import Environment
from System import Array
from System.Collections.Generic import *
clr.AddReference('System.Drawing')
import System.Drawing
from System.Drawing import *
clr.AddReference('System.Windows.Forms')
from System.Windows.Forms import Clipboard
clr.AddReferenceByName('Microsoft.Office.Interop.Excel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' )
from Microsoft.Office.Interop import Excel
from System.Runtime.InteropServices import Marshal
class ExcelUtils():
def __init__(self, expSettings, filepath, sizebitmap):
self.expSettings = expSettings
self.filepath = filepath
self.sizebitmap = sizebitmap
print self.filepath
def exportXls(self):
ex = Excel.ApplicationClass()
ex.Visible = True
ex.DisplayAlerts = False
workbook = ex.Workbooks.Add()
workbook.SaveAs(self.filepath)
ws = workbook.Worksheets[1]
nbr_row = len(self.expSettings)
nbr_colum = len(self.expSettings[0])
#
xlrange = ws.Range[ws.Cells(1, 2), ws.Cells(nbr_row, nbr_colum )]
xlrange.EntireRow.RowHeight = self.sizebitmap.Height
ws.Range("a1").EntireColumn.ColumnWidth = self.sizebitmap.Width / 4
a = Array.CreateInstance(object, nbr_row, nbr_colum - 1)
#
for indexR, row in enumerate(self.expSettings):
for indexC , value in enumerate(row):
if indexC == 0 and value is not None:
Clipboard.SetDataObject(value)
rng = ws.Range[ws.Cells(indexR + 1, 1), ws.Cells(indexR + 1 , 1)]
ws.Paste(rng, False)
else:
a[indexR, indexC - 1] = value
#copy Array in range
xlrange.Value2 = a
used_range = ws.UsedRange
for column in used_range.Columns:
column.AutoFit()
toList = lambda x : x if hasattr(x, '__iter__') else [x]
listcat = toList(UnwrapElement(IN[0]))
#make filter
lstbipCat = [System.Enum.ToObject(BuiltInCategory, x.Id.IntegerValue) for x in listcat]
filtercat = ElementMulticategoryFilter(List[BuiltInCategory](lstbipCat))
#collector
fecSymb = FilteredElementCollector(doc).OfClass(FamilySymbol).WherePasses(filtercat).ToElements()
outdata = []
imgSize = Size( 100, 100 )
for symb in fecSymb:
bitm = symb.GetPreviewImage(imgSize)
famName = symb.Family.Name
symbName = Element.Name.GetValue(symb)
outdata.append([bitm, famName, symbName])
#define folder to export
directory = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
objXls = ExcelUtils(outdata, directory + '\\test.xls', imgSize)
objXls.exportXls()
OUT = directory