importing parameters from excel to revit by api and epplus

importing parameters from excel to revit by api and epplus

wahedfazeli
Enthusiast Enthusiast
3,001 Views
6 Replies
Message 1 of 7

importing parameters from excel to revit by api and epplus

wahedfazeli
Enthusiast
Enthusiast

hey everyone i import parameters into excel by epplus but i dont know when i change my excel file my revit  become changed too.this is my code.

i thank you for helping me

 {

Document doc = commandData.Application.ActiveUIDocument.Document;

string fileman = Path.Combine(Path.GetTempPath(), "MyExcel.xlsx");

if (File.Exists(fileman)) { File.Delete(fileman); }

using (ExcelPackage pg = new ExcelPackage(new FileInfo(fileman)))

{

ExcelWorksheet sheet = pg.Workbook.Worksheets.Add("Doors");

int row = 1;

foreach(Element e in FilteredElementCollector(doc).OfClass(typeof(FamilyInstance)).OfCategory(BuiltInCategory.OST_Doors)) {

sheet.Cells[row, 1].Value = e.Name;

sheet.Cells[row, 2].Value = e.Id;

sheet.Cells[row, 3].Value = e.Category;

row++; }

pg.Save();

} Process.Start(fileman);

return Result.Succeeded;

}

0 Likes
3,002 Views
6 Replies
Replies (6)
Message 2 of 7

jeremytammik
Autodesk
Autodesk

First of all, check out the FireRating SDK sample.

 

It shows how to export Revit parameter values to Excel and import back in the modified values to update the BIM.

 

Then move to the next step, including support for multiple projects and a cloud database:

 

https://github.com/jeremytammik/FireRatingCloud

 

Good luck and have fun.

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 7

wahedfazeli
Enthusiast
Enthusiast

Dear Jeremy

the codes of fire rating is so hard for me to understand i want to do this working with epplus and api .can you help me and improve my code or describe how to do this?

what code of api changing value of parameter for example i want to change keynote or width and area and cost and others?

 

0 Likes
Message 4 of 7

jeremytammik
Autodesk
Autodesk

Dear Wahed,

 

The essential bits of code are simple.

 

Have you worked through the Revit API getting started material?

 

That answers your question in full.

 

 

Btw, I do not know what epplus is.

 

Best regards,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 5 of 7

wahedfazeli
Enthusiast
Enthusiast

Dear Jeremy

i work but i still dont familiar with a lot of codes in the api

can you show me a simple syntax how to change value of one of the parameters of object in the revit api ?

can you show how to retrieve width or height or cost or keynotes or other parameters?

thank you very much

 

0 Likes
Message 6 of 7

reylorente1
Collaborator
Collaborator

What do you want to import or export? Because it is code, it is for exporting,To import I would have to start like this

 

string filename = "";
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
openFileDialog.Filter = "Excel Files (*.xlsx)|*.xlsx";
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
filename = openFileDialog.FileName;
}
else
return Result.Cancelled;

0 Likes
Message 7 of 7

lukaskohout
Advocate
Advocate

You need to get the element, on that get the desired parameter and set the value based on its type.

ElementId elId;         //your elementId
Guid guid;              // GUID of the shared parameter you are changing
double value = 100;     //value

Element el = openDocument.GetElement(elId);
Parameter p = el.get_Parameter(guid);
double originalValue = p.AsDouble();
p.Set(value);

All of this must be wrapped in some transaction.

BUT!!!!

You need to know exactly what you are changing and why. Some parameters are BuiltIn, some shared, some non-shared. Furthermore, every parameter can be type or instance.

Batch value editing is not that simple as it may look.

 

If you find FireRating SDK to complex, then you should go through the learning materials Jerem suggested.


Hitting Accepted Answer is a Community Contribution from me as well as from you.
======================================================================
0 Likes