如何通过RevitPythonShell/IronPython访问活动Revit明细表中的字段?
我正在为Revit 2016编写IronPython脚本。首先,我尝试访问活动Revit明细表中的值(作为文本),并将其加载到变量中。这对于非计算值足够有效 但是,我的一些日程表字段是经过计算的。这是一个示例计划(此处的所有值均已计算): Revit API显示了两种方法,分别称为如何通过RevitPythonShell/IronPython访问活动Revit明细表中的字段?,python,ironpython,revit-api,revitpythonshell,Python,Ironpython,Revit Api,Revitpythonshell,我正在为Revit 2016编写IronPython脚本。首先,我尝试访问活动Revit明细表中的值(作为文本),并将其加载到变量中。这对于非计算值足够有效 但是,我的一些日程表字段是经过计算的。这是一个示例计划(此处的所有值均已计算): Revit API显示了两种方法,分别称为TableView.GetCalculatedValueName()和,我很想使用它们,但它们的工作方式与宣传的不同 doc = __revit__.ActiveUIDocument.Document uidoc =
TableView.GetCalculatedValueName()
和,我很想使用它们,但它们的工作方式与宣传的不同
doc = __revit__.ActiveUIDocument.Document
uidoc = __revit__.ActiveUIDocument
schedule = doc.ActiveView
tableData = schedule.GetTableData()
print(tableData)
tableName = schedule.GetCellText(SectionType.Header,0,0)
qty = schedule.GetCalculatedValueText(SectionType.Body,4,1)
calcValName = schedule.GetCalculatedValueName(SectionType.Body,4,1)
print(tableName)
print("Calculated Qty is: " + qty)
print("Calculated Value Name is: " + calcValName)
运行此代码(在Revit中)将生成以下输出:
88-06134-01
Calculated Qty is:
Calculated Value Name is:
我想指出的是,使用
TableView.GetCellText()
实际上对计算值有效,但我真正想在这里使用的是GetCalculatedValueName()
。我也做了同样的事情,只是在c#for Revit 2019中。我希望你能理解
您可以访问明细表数据的值,而无需导出。首先,获取所有计划并逐个单元读取数据。其次,创建字典并以键、值对的形式存储数据。现在,您可以根据需要使用计划数据。我在2019年试过这个。
下面是实现
public void getScheduleData(Document doc)
{
FilteredElementCollector collector = new FilteredElementCollector(doc);
IList<Element> collection = collector.OfClass(typeof(ViewSchedule)).ToElements();
foreach (Element e in collection)
{
ViewSchedule viewSchedule = e as ViewSchedule;
TableData table = viewSchedule.GetTableData();
TableSectionData section = table.GetSectionData(SectionType.Body);
int nRows = section.NumberOfRows;
int nColumns = section.NumberOfColumns;
if (nRows > 1)
{
List<List<string>> scheduleData = new List<List<string>>();
for (int i = 0; i < nRows; i++)
{
List<string> rowData = new List<string>();
for (int j = 0; j < nColumns; j++)
{
rowData.Add(viewSchedule.GetCellText(SectionType.Body, i, j));
}
scheduleData.Add(rowData);
}
List<string> columnData = scheduleData[0];
scheduleData.RemoveAt(0);
DataMapping(columnData, scheduleData);
}
}
}
public static void DataMapping(List<string> keyData, List<List<string>>valueData)
{
List<Dictionary<string, string>> items= new List<Dictionary<string, string>>();
string prompt = "Key/Value";
prompt += Environment.NewLine;
foreach (List<string> list in valueData)
{
for (int key=0, value =0 ; key< keyData.Count && value< list.Count; key++,value++)
{
Dictionary<string, string> newItem = new Dictionary<string, string>();
string k = keyData[key];
string v = list[value];
newItem.Add(k, v);
items.Add(newItem);
}
}
foreach (Dictionary<string, string> item in items)
{
foreach (KeyValuePair<string, string> kvp in item)
{
prompt += "Key: " + kvp.Key + ",Value: " + kvp.Value;
prompt += Environment.NewLine;
}
}
Autodesk.Revit.UI.TaskDialog.Show("Revit", prompt);
}
public void getScheduleData(文档文档)
{
FilteredElementCollector=新的FilteredElementCollector(单据);
IList collection=collector.OfClass(typeof(ViewSchedule)).ToElements();
foreach(集合中的元素e)
{
ViewSchedule ViewSchedule=e作为ViewSchedule;
TableData table=viewSchedule.GetTableData();
TablesSectionData节=table.GetSectionData(SectionType.Body);
int nRows=section.NumberOfRows;
int nColumns=section.NumberOfColumns;
如果(nRows>1)
{
List scheduleData=新列表();
对于(int i=0;i
我也做了同样的事情,只是用c#for Revit 2019。我希望你能理解
您可以访问明细表数据的值,而无需导出。首先,获取所有计划并逐个单元读取数据。其次,创建字典并以键、值对的形式存储数据。现在,您可以根据需要使用计划数据。我在2019年试过这个。
下面是实现
public void getScheduleData(Document doc)
{
FilteredElementCollector collector = new FilteredElementCollector(doc);
IList<Element> collection = collector.OfClass(typeof(ViewSchedule)).ToElements();
foreach (Element e in collection)
{
ViewSchedule viewSchedule = e as ViewSchedule;
TableData table = viewSchedule.GetTableData();
TableSectionData section = table.GetSectionData(SectionType.Body);
int nRows = section.NumberOfRows;
int nColumns = section.NumberOfColumns;
if (nRows > 1)
{
List<List<string>> scheduleData = new List<List<string>>();
for (int i = 0; i < nRows; i++)
{
List<string> rowData = new List<string>();
for (int j = 0; j < nColumns; j++)
{
rowData.Add(viewSchedule.GetCellText(SectionType.Body, i, j));
}
scheduleData.Add(rowData);
}
List<string> columnData = scheduleData[0];
scheduleData.RemoveAt(0);
DataMapping(columnData, scheduleData);
}
}
}
public static void DataMapping(List<string> keyData, List<List<string>>valueData)
{
List<Dictionary<string, string>> items= new List<Dictionary<string, string>>();
string prompt = "Key/Value";
prompt += Environment.NewLine;
foreach (List<string> list in valueData)
{
for (int key=0, value =0 ; key< keyData.Count && value< list.Count; key++,value++)
{
Dictionary<string, string> newItem = new Dictionary<string, string>();
string k = keyData[key];
string v = list[value];
newItem.Add(k, v);
items.Add(newItem);
}
}
foreach (Dictionary<string, string> item in items)
{
foreach (KeyValuePair<string, string> kvp in item)
{
prompt += "Key: " + kvp.Key + ",Value: " + kvp.Value;
prompt += Environment.NewLine;
}
}
Autodesk.Revit.UI.TaskDialog.Show("Revit", prompt);
}
public void getScheduleData(文档文档)
{
FilteredElementCollector=新的FilteredElementCollector(单据);
IList collection=collector.OfClass(typeof(ViewSchedule)).ToElements();
foreach(集合中的元素e)
{
ViewSchedule ViewSchedule=e作为ViewSchedule;
TableData table=viewSchedule.GetTableData();
TablesSectionData节=table.GetSectionData(SectionType.Body);
int nRows=section.NumberOfRows;
int nColumns=section.NumberOfColumns;
如果(nRows>1)
{
List scheduleData=新列表();
对于(int i=0;i
您能提供一个最小的可复制案例吗?只有一两个单元格加上嵌入的Python宏的最小Revit模型?c、 你有没有让它工作过?这是一段时间以前的事了,但是没有人接受答案……你能提供一个最小的可重复的案例吗?只有一两个单元格加上嵌入的Python宏的最小Revit模型?c、 你有没有让它工作过?这是很久以前的事了,但是没有人接受答案。。。