NavisWorks Api 简单使用与Gantt

相信很多朋友在做BIM项目的时候.都有客户会提出项目计划,形象进度 等需求。

那么当前最主要的问题就是计划与BIM模型的关联问题.那么我在项目中是用户用Project软件编辑计划然后手动跟三维模型关联。如果同行有更好的解决办法请告诉我,非常感谢

1界面布局

NavisWorks Api 简单使用与Gantt_第1张图片

2 代码部分

        //当前选中的模型的名称
        private string _currentSelectionName = string.Empty;
        //当前选中的模型的GUID
        private string _currentSelectionGuid = string.Empty;
        //当前选中的Item
        private GanttItem _currentGanttItem = null;、

 

       /// <summary>
        /// 选中计划 聚焦到对应的模型
        /// </summary>
        private void SetCurrentModel()
        {
            if (Autodesk.Navisworks.Api.Application.ActiveDocument != null)
            {
                if (_currentGanttItem != null)
                {
                    object modelid = _currentGanttItem.GetProperty("ModelId");
                    object modelName = _currentGanttItem.GetProperty("ModelName");

                    if (modelid != null)
                    {
                        if (!string.IsNullOrEmpty(modelid.ToString()))
                        {
                            Guid guid = Guid.Parse(modelid.ToString());
                            List<Autodesk.Navisworks.Api.ModelItem> seletedObjs = Autodesk.Navisworks.Api.Application.ActiveDocument.Models.RootItemDescendantsAndSelf.WhereInstanceGuid(guid).ToList();
                            if (seletedObjs.Any())
                            {
                                Document oDoc = Autodesk.Navisworks.Api.Application.ActiveDocument;
                                oDoc.CurrentSelection.CopyFrom(seletedObjs);
                                oDoc.ActiveView.FocusOnCurrentSelection();
                            }

                        }

                    }
                }

            }
        }
 /// <summary>
        /// 将当前选中的模型 附件到计划  与计划匹配
        /// </summary>
        void MT_AddCurrentModel_Click(object sender, EventArgs e)
        {
            //验证模型
            if (Autodesk.Navisworks.Api.Application.ActiveDocument != null &&
               !Autodesk.Navisworks.Api.Application.ActiveDocument.IsClear)
            {
                Autodesk.Navisworks.Api.Document doc = Autodesk.Navisworks.Api.Application.ActiveDocument;
                if (doc != null)
                {

                    if (doc.CurrentSelection.SelectedItems.Any())
                    {
                        //获取当前选中的模型信息
                        var selectItem = doc.CurrentSelection.SelectedItems[0];
                        if (selectItem != null)
                        {
                            _currentSelectionGuid = selectItem.InstanceGuid.ToString();
                            _currentSelectionName = selectItem.DisplayName;

                        }
                        //获取当前选中的Task
                        if (_currentGanttItem != null)
                        {
                            var exist = _taskList.Where(o => o.ModelId == _currentSelectionGuid);
                            if (exist.Any())
                            {
                                XtraMessageBox.Show("尊敬的用户您好!当前模型已经在计划中添加了!谢谢", "系统提示");
                            }
                            else
                            {
                                var modify = _taskList.FirstOrDefault(o => o.ProjectName == _currentGanttItem.Text);
                                if (modify != null)
                                {
                                    modify.ModelName = _currentSelectionName;
                                    modify.ModelItem = selectItem;
                                    modify.ModelId = _currentSelectionGuid;
                                    BindData();
                                }
                            }
                        }
                    }
                    else
                    {
                        XtraMessageBox.Show("尊敬的用户您好!当前没有选中模型!请先选中模型!", "系统提示");
                    }

                }
            }
        }

我用的是NavisWorks SDK 2015. 当然每个版本都不一样。如果有错误的地方请网友指出!

你可能感兴趣的:(NavisWorks Api 简单使用与Gantt)