针对目前的设计生产模式来说,最终工程信息都会以图纸的形式进行表达。作为BIM模型,其中拥有海量的工程信息,但是如何将模型中的信息归类,快速整合并输出为符合公司出图标准的图纸或表格,也是目前BIM技术短时间无法取代传统CAD绘制出图模式的一大原因。这里,我们给大家分别介绍用于生成符合公司要求图表的工具Demo和绘制构件后自动生成图纸的工具Demo。
表格生成工具
该工具主要用于从模型中提取生成表格所需的信息,并自动生成表格。对于表格本身,若表格较为简单,可使用MicroStation内置的表格,若内置表格样式无法满足出图的需要,那么可以采用线与文字配合生成的方式,创建符合公司出图标准的图表,同时,表格数据还可输出为Excel文件的格式,提供多样形式的数据输出。
需求说明:
使用工具对构件进行筛选,选择完毕后从选择的元素中提取生成图表的有效信息生成图表,同时也可使用表格信息生成对应的Excel文件。
要求:
选择元素需要具有批量选择(框选/划选),单项选择(按住Ctrl点选)的正选/反选功能,完成选择后需要在界面显示生成图表的预览图,具有生成默认图表与自定义图表的功能,并可输出为Excel格式的表格文件。
分析:
该工具大致可分为三个阶段:选择模型中元素阶段,界面中预览图表与参数设置阶段,放置图表阶段。其中第一个与最后一个阶段涉及到交互式工具的使用,而中间的阶段涉及到界面的交互。
using Bentley.DgnPlatformNET;
txtBlock.AppendText(m_elems[j].Description);//设置文本块文字内容
break;
case 2:
txtBlock.AppendText(m_elems[j].ElementType.ToString());//设置文本块文字内容
break;
case 3:
txtBlock.AppendText(m_elems[j].IsInvisible.ToString());//设置文本块文字内容
break;
case 4:
txtBlock.AppendText(m_elems[j].IsValid.ToString());//设置文本块文字内容
break;
case 5:
txtBlock.AppendText(m_elems[j].LevelId.ToString());//设置文本块文字内容
break;
}
}
else if(DataFilterMenu.m_tableInfo.Item2 == 1)//通过元组参数判断
{
switch (i)//分支判断
{
case 0:
txtBlock.AppendText(m_elems[j].ElementId.ToString());//设置文本块文字内容
break;
case 1:
txtBlock.AppendText(m_elems[j].Description);//设置文本块文字内容
break;
}
}
else if (DataFilterMenu.m_tableInfo.Item2 == 2)//通过元组参数判断
{
switch (i)//分支判断
{
case 0:
txtBlock.AppendText(m_elems[j].ElementType.ToString());//设置文本块文字内容
break;
case 1:
txtBlock.AppendText(m_elems[j].IsInvisible.ToString());//设置文本块文字内容
break;
}
}
else if (DataFilterMenu.m_tableInfo.Item2 == 3)//通过元组参数判断
{
switch (i)//分支判断
{
case 0:
txtBlock.AppendText(m_elems[j].IsValid.ToString());//设置文本块文字内容
break;
case 1:
txtBlock.AppendText(m_elems[j].LevelId.ToString());//设置文本块文字内容
break;
}
}
TextElement text = (TextElement)TextElement.CreateElement(null, txtBlock);//定义文本元素
TransformInfo transform = new TransformInfo(DTransform3d.FromTranslation(insertPo));//声明变换信息
text.ApplyTransform(transform);//对元素应用变换信息
subElems.Add(text);//将元素添加到列表中
}
}
#endregion
#region MergeIntoCell
m_textTableElem = new CellHeaderElement(dgnModel, "CustomDataTable", DPoint3d.Zero, DMatrix3d.Identity,subElems);//声明单元元素
#endregion
}
}
private void DynamicDrawElems(Element element,DPoint3d locPo)
{
DTransform3d dTransform = DTransform3d.FromTranslation(locPo);//声明变换矩阵
TransformInfo trans = new TransformInfo(dTransform);//声明变换信息
element.ApplyTransform(trans);//对元素应用变换信息
RedrawElems redrawElems = new RedrawElems();//使用元素用于动态绘制
redrawElems.SetDynamicsViewsFromActiveViewSet(Session.GetActiveViewport());//设置视角
redrawElems.DrawMode = DgnDrawMode.TempDraw;//设置绘制模式
redrawElems.DrawPurpose = DrawPurpose.Dynamics;//设置绘制目标
redrawElems.DoRedraw(element);//使用元素用于动态绘制
dTransform.TryInvert(out DTransform3d dTransformInvert);//获得指定矩阵的逆矩阵
trans = new TransformInfo(dTransformInvert);//声明变换信息
element.ApplyTransform(trans);//对元素应用变换信息
}
private void PlaceDataTable(Element element, DPoint3d locPo)
{
TransformInfo trans = new TransformInfo(DTransform3d.FromTranslation(locPo));//声明变换信息
element.ApplyTransform(trans);//对元素应用变换信息
element.AddToModel();//将元素添加到模型中
}
}
}
using Bentley.DgnPlatformNET;
foreach (Element elem in m_elems)//遍历列表中的元素
{
DataRow drow = m_dt.NewRow();//新建数据行
if (m_comboBox_modelSelection.SelectedIndex == 0 || m_comboBox_modelSelection.SelectedIndex == 1)//判断下拉框索引值
{
drow[" ID "] = elem.ElementId.ToString();//对数据行的列设置项
drow[" Desc "] = elem.Description;
}
if (m_comboBox_modelSelection.SelectedIndex == 0 || m_comboBox_modelSelection.SelectedIndex == 2)
{
drow[" Type "] = elem.TypeName;
drow[" IsInvisible "] = elem.IsInvisible;
}
if (m_comboBox_modelSelection.SelectedIndex == 0 || m_comboBox_modelSelection.SelectedIndex == 3)
{
drow[" IsValid "] = elem.IsValid;
drow[" LevelId "] = elem.LevelId.ToString();
}
m_dt.Rows.Add(drow);//对数据表中添加数据行
}
m_dataGridView_elemProps.DataSource = m_dt;//设置数据源为定义的数据表
}
private void ExportDataGridToExcel()
{
SaveFileDialog exe = new SaveFileDialog();//声明文件保存对话框
exe.Filter = "Execl files (*.xls)|*.xls";//确定筛选文件格式
exe.FilterIndex = 0;//设置过滤器索引
exe.RestoreDirectory = true;//设置保存目录
exe.Title = "Export Excel File";//设置标题
exe.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);//设置初始化文件存放位置
exe.FileName = string.Format("{0}_{1}", DateTime.Now.ToString("yyyy-MM-dd HH时mm分ss秒"), "元素信息表");//设置文件名称
DialogResult dr = exe.ShowDialog();//获得对话框结果
if (dr != DialogResult.OK)//判断是否成功获取
{
return;//返回
}
#region 将DataTable中的数据转化为Excel格式的数据
Stream ms = exe.OpenFile();
StreamWriter sw = new StreamWriter(ms, Encoding.Default);
string str = "";
try
{
for (int i = 0; i < m_dt.Columns.Count; i++)
{
if (i > 0)
{
str += "\t";
}
str += m_dt.Columns[i];
}
sw.WriteLine(str);
for (int j = 0; j < m_dt.Rows.Count; j++)
{
string temp = "";
for (int k = 0; k < m_dt.Columns.Count; k++)
{
if (k > 0)
{
temp += "\t";
}
string cell = m_dt.Rows[j][k].ToString();
cell = cell.Replace(" ", "").Replace("\r", "").Replace("\n", "").Replace("\r\n", "");
temp += cell;
}
sw.WriteLine(temp);
}
sw.Close();
ms.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
finally
{
sw.Close();
ms.Close();
}
#endregion
}
}
}
namespace ExampleofCase.UI
// DataFilterMenu
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(505, 292);
this.Controls.Add(this.m_checkBox_exportExcel);
this.Controls.Add(this.m_radioButton_usecustom);
this.Controls.Add(this.m_radioButton_usedefault);
this.Controls.Add(this.m_button_importmodel);
this.Controls.Add(this.m_label_filter);
this.Controls.Add(this.m_comboBox_modelSelection);
this.Controls.Add(this.m_dataGridView_elemProps);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.Name = "DataFilterMenu";
this.ShowIcon = false;
this.Text = "DataFilterMenu";
this.TopMost = true;
this.Load += new System.EventHandler(this.DataFilterMenu_Load);
((System.ComponentModel.ISupportInitialize)(this.m_dataGridView_elemProps)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.DataGridView m_dataGridView_elemProps;
private System.Windows.Forms.ComboBox m_comboBox_modelSelection;
private System.Windows.Forms.Label m_label_filter;
private System.Windows.Forms.Button m_button_importmodel;
private System.Windows.Forms.RadioButton m_radioButton_usedefault;
private System.Windows.Forms.RadioButton m_radioButton_usecustom;
private System.Windows.Forms.CheckBox m_checkBox_exportExcel;
}
}