Revit Secondary Development Import Component Info to Database
Data volume of components in revit is large. Database is needed when doing standardization or audit software. Importing data into database enables calculation to verify separated from software, which is also a kind of burden reduction for alternative software.
demo
Get component - Test project casually select several components to output data
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
var refer = uidoc.Selection.PickObjects(ObjectType.Element, "pick onjects");
List<string> categorys = new List<string>();
List<int> elementIds = new List<int>();
List<string> symbolNames = new List<string>();
foreach(Reference re in refer)
{
Element e = doc.GetElement(re);
string symbolName = e.Name;
string category = e.Category.Name;
int elementId = e.Id.IntegerValue;
symbolNames.Add(symbolName);
categorys.Add(category);
elementIds.Add(elementId);
}Connect to Database
- Because it is a test, mysql connection is set to local connection. This step should be creating Mysql file to transfer to server database for reading
1 | public MySQLConnection2(List<int> elementids,List<string> symbolNames,List<string> categorys) |
- Display in form. Frontend code is relatively simple, just pass data stream in
1 |
|

Up to this step data can be extracted and utilized, but empty rows or empty columns will appear in datagrid of frontend. Need to set parametersdataGridView1.AllowUserToAddRows = false; change value to false. Reference link: https://blog.csdn.net/wanglejun/article/details/39231075
All articles on this blog are licensed under CC BY-NC-SA 4.0 unless otherwise stated.


