Help me to get a CSV file from LookUp Table.

Help me to get a CSV file from LookUp Table.

holyhuman1
Contributor Contributor
678 Views
2 Replies
Message 1 of 3

Help me to get a CSV file from LookUp Table.

holyhuman1
Contributor
Contributor

Hi, all! 

I've been struggling get a CSV file from LookUp Table in specific Family. I thought it is easy but there are always "file access exception" when using FamilySizeTableManager.ExportSizeTable().

 

here's my code.

public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
//
//.......
//

FamilySymbol fs = (elem as FamilyInstance).Symbol;

FamilySizeTableManager fstm = FamilySizeTableManager.GetFamilySizeTableManager(doc, fs.Family.Id);

using (Transaction trans = new Transaction(doc))
{
trans.Start("Start");

if (fstm.ExportSizeTable("Really exist name in Lookuptable", AssemblyDirectory))
{
// success
}
else
{
// fail.
}

trans.Commit();
}
}

 

holyhuman1_0-1622621054397.png

 

 

Are there anyone who already encountered and solved this issue?

 

thank you!

 

0 Likes
Accepted solutions (1)
679 Views
2 Replies
Replies (2)
Message 2 of 3

jeremy_tammik
Alumni
Alumni
Accepted solution

The ExportSizeTable method takes two arguments: the table name to export and a file path to export it to:

 

https://www.revitapidocs.com/2021.1/40539d6c-8288-94cb-0052-2e8203d15e43.htm

 

The file path must be a valid text file path and you must have write access to that.

 

You file path variable name is `AssemblyDirectory`. That sounds like a directory name to me, not a file path. Maybe that is your problem. Furthermore, you may not have write access to that directory. Try a different file path.

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 3

holyhuman1
Contributor
Contributor

Thank you jeremy! i finally found the problem. the code should be like this.

 

//

FamilySymbol fs = (elem as FamilyInstance).Symbol;

FamilySizeTableManager fstm = FamilySizeTableManager.GetFamilySizeTableManager(doc, fs.Family.Id);

using (Transaction trans = new Transaction(doc))
{
trans.Start("Start");

// if (fstm.ExportSizeTable("Really exist name in Lookuptable", AssemblyDirectory))

if (fstm.ExportSizeTable("Really exist name in Lookuptable", AssemblyDirectory + "Really exist name in Lookuptable"+".csv" ))
{
// success
}
else
{
// fail.
}

trans.Commit();
}
}

 

Thank you again!!

0 Likes