Bentley二次开发教程29-交互窗口-案例实战3-文件选择复制工具

文件选择复制工具

该工具会根据用户选择获得需要赋值元素的文件,读取文件信息后根据用户选择的模型动态读取模型中的元素信息,并实时调整条件筛选多选框中元素类型,元素图层,ItemType信息等,同时根据多选框中的设置动态锁定/解锁下拉框,用机制保证就算用户没有使用该工具的经验,只要根据插件给出的信息即可直接上手。最后点击执行后,程序会根据当前的筛选条件动态赋值模型中的元素,同时当RadioButton选中的是输出生成信息时,输出复制结果。并且在复制过程中,使用ProgressBar显示复制进程。
该工具涉及到的WinForm控件有:TextBox,Button,ComboBox,ListBox,RadioButton,Label,CheckBox,ProgressBar。
在这里插入图片描述
在这里插入图片描述

using Bentley.DgnPlatformNET;
                    if(foundItem==false)//判断元素上是否挂接了ItemType
                    {
                        m_selectedElems.Remove(m_selectedElems[i]);//从列表中移除该项
                        i--;//计数减一
                        continue;//重新开始循环
                    }
                }
            }            
            m_label_elemscount.Text = m_selectedElems.Count().ToString();//在标签中输出经过筛选后的元素个数
        }

        private void CopyElementIntoActiveModel()
        {
            #region ProgressBar
            m_progressBar_copyprogress.Minimum = 1;//设置进度条的最小值
            m_progressBar_copyprogress.Maximum = 100;//设置进度条的最大值
            m_progressBar_copyprogress.Value = 1;//设置进度条的值
            m_progressBar_copyprogress.Step = 100 / m_selectedElems.Count;//设置进度条的步长
            #endregion

            for (int i=0;i<m_selectedElems.Count;i++)//遍历元素容器中的元素
            {
                using (ElementCopyContext copyContext = new ElementCopyContext(m_dgnModel))//复制元素
                {                    
                    m_progressBar_copyprogress.PerformStep();//进度条按照步长推进
                    copyContext.DoCopy(m_selectedElems[i]);//复制元素到当前的模型空间中
                    //DependencyManager.ProcessAffected();
                }                
            }

            m_progressBar_copyprogress.Value = 100;//设置进度条的值
            if (m_radioButton_outputinfo.Checked == true)//判断指定单选项是否被选择
            {
                MessageCenter.Instance.ShowInfoMessage(m_selectedElems.Count + " elems import success", m_selectedElems.Count + " elems import success", true);//输出模型导入结果
            }            
        }      

        private void AddItemTypeIntoListBox()
        {
            m_listBox_itemtype.Items.Clear();//清空列表框中的项
            ItemTypeLibrary itemTypeLibrary = ItemTypeLibrary.FindByName(m_comboBox_itemtype.Text, m_dgnFile);//从文件中中获得指定名称的ItemTypeLibrary
            foreach (ItemType itemType in itemTypeLibrary.ItemTypes)//遍历ItemTypeLibrary中的ItemType
            {
                m_listBox_itemtype.Items.Add(itemType.Name);//将ItemType项的名称添加到列表框中                
            }
        }
    }
}
namespace WinformUIIntroduction.UI
            this.m_checkBox_itemtype.AutoSize = true;
            this.m_checkBox_itemtype.Enabled = false;
            this.m_checkBox_itemtype.Font = new System.Drawing.Font("Microsoft YaHei UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.m_checkBox_itemtype.Location = new System.Drawing.Point(238, 192);
            this.m_checkBox_itemtype.Name = "m_checkBox_itemtype";
            this.m_checkBox_itemtype.Size = new System.Drawing.Size(15, 14);
            this.m_checkBox_itemtype.TabIndex = 27;
            this.m_checkBox_itemtype.UseVisualStyleBackColor = true;
            this.m_checkBox_itemtype.CheckedChanged += new System.EventHandler(this.checkBox5_CheckedChanged);
            // 
            // m_label_itemtype
            // 
            this.m_label_itemtype.AutoSize = true;
            this.m_label_itemtype.Font = new System.Drawing.Font("Microsoft YaHei UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.m_label_itemtype.Location = new System.Drawing.Point(12, 190);
            this.m_label_itemtype.Name = "m_label_itemtype";
            this.m_label_itemtype.Size = new System.Drawing.Size(62, 17);
            this.m_label_itemtype.TabIndex = 28;
            this.m_label_itemtype.Text = "ItemType";
            // 
            // m_comboBox_itemtype
            // 
            this.m_comboBox_itemtype.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.m_comboBox_itemtype.Enabled = false;
            this.m_comboBox_itemtype.FormattingEnabled = true;
            this.m_comboBox_itemtype.Location = new System.Drawing.Point(111, 189);
            this.m_comboBox_itemtype.Name = "m_comboBox_itemtype";
            this.m_comboBox_itemtype.Size = new System.Drawing.Size(121, 21);
            this.m_comboBox_itemtype.TabIndex = 29;
            this.m_comboBox_itemtype.SelectedIndexChanged += new System.EventHandler(this.comboBox5_SelectedIndexChanged);
            // 
            // FilterCopyMenu
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(299, 478);
            this.Controls.Add(this.m_comboBox_itemtype);
            this.Controls.Add(this.m_label_itemtype);
            this.Controls.Add(this.m_checkBox_itemtype);
            this.Controls.Add(this.m_listBox_itemtype);
            this.Controls.Add(this.m_textbox_filePath);
            this.Controls.Add(this.m_button_importpath);
            this.Controls.Add(this.m_label_importpath);
            this.Controls.Add(this.m_comboBox_importmodel);
            this.Controls.Add(this.m_button_execute);
            this.Controls.Add(this.m_radioButton_nooutputinfo);
            this.Controls.Add(this.m_label_elemscount);
            this.Controls.Add(this.m_label_elems);
            this.Controls.Add(this.m_radioButton_outputinfo);
            this.Controls.Add(this.m_progressBar_copyprogress);
            this.Controls.Add(this.m_checkBox_color);
            this.Controls.Add(this.m_comboBox_color);
            this.Controls.Add(this.m_label_color);
            this.Controls.Add(this.m_checkBox_level);
            this.Controls.Add(this.m_comboBox_level);
            this.Controls.Add(this.m_label_level);
            this.Controls.Add(this.m_checkBox_type);
            this.Controls.Add(this.m_checkBox_checkall);
            this.Controls.Add(this.m_label_type);
            this.Controls.Add(this.m_comboBox_type);
            this.Controls.Add(this.m_label_filter);
            this.Controls.Add(this.m_label_importmodel);
            this.MaximizeBox = false;
            this.Name = "FilterCopyMenu";
            this.ShowIcon = false;
            this.Text = "FilterCopyMenu";
            this.TopMost = true;
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion
        private System.Windows.Forms.Label m_label_importmodel;
        private System.Windows.Forms.Label m_label_filter;
        private System.Windows.Forms.ComboBox m_comboBox_type;
        private System.Windows.Forms.Label m_label_type;
        private System.Windows.Forms.CheckBox m_checkBox_checkall;
        private System.Windows.Forms.CheckBox m_checkBox_type;
        private System.Windows.Forms.Label m_label_level;
        private System.Windows.Forms.CheckBox m_checkBox_level;
        private System.Windows.Forms.ComboBox m_comboBox_level;
        private System.Windows.Forms.CheckBox m_checkBox_color;
        private System.Windows.Forms.ComboBox m_comboBox_color;
        private System.Windows.Forms.Label m_label_color;
        private System.Windows.Forms.ProgressBar m_progressBar_copyprogress;
        private System.Windows.Forms.RadioButton m_radioButton_outputinfo;
        private System.Windows.Forms.Label m_label_elems;
        private System.Windows.Forms.Label m_label_elemscount;
        private System.Windows.Forms.RadioButton m_radioButton_nooutputinfo;
        private System.Windows.Forms.Button m_button_execute;
        private System.Windows.Forms.ComboBox m_comboBox_importmodel;
        private System.Windows.Forms.Label m_label_importpath;
        private System.Windows.Forms.Button m_button_importpath;
        private System.Windows.Forms.TextBox m_textbox_filePath;
        private System.Windows.Forms.ListBox m_listBox_itemtype;
        private System.Windows.Forms.CheckBox m_checkBox_itemtype;
        private System.Windows.Forms.Label m_label_itemtype;
        private System.Windows.Forms.ComboBox m_comboBox_itemtype;
    }
}

在这里插入图片描述

注意事项

  • 在MicroStation二次开发的环境下使用WinForm时,需要将继承的Form修改为Bentley.MstnPlatformNET.WinForms.Adapter
  • 在MicroStation中需要调用界面时,需要首先对界面进行声明,然后使用模态显示(ShowDialog)和非模态显示(Show),模态与非模态窗体的主要区别是窗体显示的时候是否可以操作其他窗体。模态窗体不允许操作其他窗体,非模态窗体可以操作其他窗体。
  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值