コード例 #1
0
        private void ButFocus_Click(object sender, EventArgs e)//在NW中选择当前选择记录的
        {
            Document Doc        = Autodesk.Navisworks.Api.Application.ActiveDocument;
            TabPage  curTabPage = this.TCL1OfQF.SelectedTab;//获取当前选择的tab页面
            string   strId      = "";

            foreach (Control control in curTabPage.Controls) //遍历控件
            {
                if (control is DataGridView)                 //如果是datagridview,则在视图中选择元素
                {
                    DataGridView dgv = (DataGridView)control;
                    if (dgv.SelectedRows.Count == 0)
                    {
                        MessageBox.Show("未选中行!");
                        return;
                    }
                    for (int i = 0; i < dgv.SelectedRows.Count; i++)
                    {
                        strId = dgv.SelectedRows[i].Cells[0].Value.ToString();
                    }
                    Search search = new Search();
                    search.Selection.SelectAll();
                    //元素ID是int32类型,所以Displaystring找不到
                    search.SearchConditions.Add(SearchCondition.HasPropertyByDisplayName("元素", "Id").EqualValue(VariantData.FromInt32(Int32.Parse(strId))));

                    ModelItemCollection items = search.FindAll(Doc, true);
                    Doc.CurrentSelection.Clear();
                    Doc.CurrentSelection.CopyFrom(items);
                    if (items.Count > 0)
                    {
                        MessageBox.Show("已在视图中选中该元素!", "提示");
                    }
                }
            }
        }
コード例 #2
0
        private void ButSelect_Click(object sender, EventArgs e)
        {
            Document oDoc = Autodesk.Navisworks.Api.Application.ActiveDocument;

            Search search = new Search();

            search.Selection.SelectAll();
            //元素ID是int32类型,所以Displaystring找不到
            search.SearchConditions.Add(SearchCondition.HasPropertyByDisplayName("元素", "Id").EqualValue(VariantData.FromInt32(1243755)));

            ModelItemCollection items = search.FindAll(oDoc, true);

            if (items.Count == 0)
            {
                MessageBox.Show("未找到目标!");
                return;
            }
            oDoc.CurrentSelection.CopyFrom(items);
        }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: LeeSKII/Info9DProject
        private void BUTFocus_Click(object sender, EventArgs e)
        {
            Document Doc = Autodesk.Navisworks.Api.Application.ActiveDocument;

            List <string> listId = new List <string>();

            if (DGVTotal.SelectedRows.Count == 0)
            {
                MessageBox.Show("未选中行!");
                return;
            }
            for (int i = 0; i < DGVTotal.SelectedRows.Count; i++)
            {
                listId.Add(DGVTotal.SelectedRows[i].Cells[0].Value.ToString());
            }

            ModelItemCollection itemsCol = new ModelItemCollection();

            //元素ID是int32类型,所以Displaystring找不到
            for (int i = 0; i < DGVTotal.SelectedRows.Count; i++)
            {
                Search search = new Search();
                search.Selection.SelectAll();
                search.SearchConditions.Add(SearchCondition.HasPropertyByDisplayName("元素", "Id").EqualValue(VariantData.FromInt32(Int32.Parse(listId[i]))));
                ModelItemCollection items = search.FindAll(Doc, true);
                if (items.First != null)//不为空才添加
                {
                    itemsCol.Add(items.First);
                }
            }


            Doc.CurrentSelection.Clear();
            Doc.CurrentSelection.CopyFrom(itemsCol);
            if (itemsCol.Count > 0)
            {
                MessageBox.Show("已在视图中选中该元素!", "提示");
            }
        }