初次接触Navisworks Api  .NET 的二次开发.主要是研究了一下。关于NavisWorks 结构树的加载.

     void LoadModel()
{
//清空当前的结构树信息
treeView1.Nodes.Clear();
//当前加载的模型
Document doc = Autodesk.Navisworks.Api.Application.ActiveDocument; //循环现有模型
foreach (var documentModel in doc.Models)
{ var modelItemList = documentModel.RootItem.Descendants;
Model model = documentModel;
var modelItems = modelItemList.Where(o => o.Parent == model.RootItem); if (modelItems.Any())
{
TreeNode cNode;
foreach (var quItem in modelItems)
{
cNode = new TreeNode(quItem.DisplayName);
cNode.Tag = quItem;
// cNode.Text = quItem.DisplayName;//判断名称
treeView1.Nodes.Add(cNode);
if (quItem.Children.Any())
{
LoadChild(quItem.Children, quItem, cNode);
} }
} } } /// <summary>
/// 递归判断结构树信息
/// </summary>
/// <param name="modelItemEnumerableCollection">数据源信息</param>
/// <param name="parentItem">父级节点信息</param>
/// <param name="pNode">子节点信息</param>
private void LoadChild(IEnumerable<ModelItem> modelItemEnumerableCollection, ModelItem parentItem, TreeNode pNode)
{
var query = modelItemEnumerableCollection.Where(o => o.Parent == parentItem);
if (query.Count()>)
{
foreach (var quItem in query)
{
TreeNode chNode = new TreeNode(quItem.DisplayName);
chNode.Tag = quItem;
pNode.Nodes.Add(chNode);
if (quItem.Children.Any())
{
LoadChild(quItem.Children, quItem, chNode);
} }
}
}

TreeView Node 选中事件

       void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
TreeNode node = e.Node;
if (node != null)
{
ModelItem oCurrentNode = (ModelItem)node.Tag;
propertyGrid1.SelectedObject = oCurrentNode;
if (oCurrentNode != null)
{ //设置选择集合
ModelItemCollection oMC = new ModelItemCollection();
oMC.Add(oCurrentNode);
Document oDoc = view.ViewControl.DocumentControl.Document;
//设置选中
oDoc.CurrentSelection.CopyFrom(oMC);
}
}
}

模型加载窗口:

    public partial class FrmModelView : DevExpress.XtraEditors.XtraForm
{
public ViewControl ViewControl;
public FrmModelView()
{
InitializeComponent();
if (this.components == null)
this.components = new Container();
//初始化Document控件
DocumentControl document = new DocumentControl(this.components);
document.Document.SetGraduatedBackground(Autodesk.Navisworks.Api.Color.FromByteRGB(,,),Autodesk.Navisworks.Api.Color.FromByteRGB(,,));
//初始化View控件 并添加Document控件
ViewControl = new ViewControl();
ViewControl.DocumentControl = document;
ViewControl.BackColor = System.Drawing.Color.LightSteelBlue;
ViewControl.Dock = DockStyle.Fill;
ViewControl.Name = "viewControl";
this.Controls.Add(ViewControl);
}
}

模型选择事件:

        #region 模型选择事件

        private void CurrentSelection_Changed(object sender, EventArgs e)
{
try
{
Document doc = (Document)sender;
if (doc != null)
{
var item = doc.CurrentSelection.SelectedItems[];
if (item != null)
{ TreeNode tnRet = null;
foreach (TreeNode tn in treeView1.Nodes)
{
tnRet = FindNode(tn, item.DisplayName);
if (tnRet != null)
break;
}
if (tnRet != null)
{
if (oldNode != null)
oldNode.BackColor = Color.White;
tnRet.BackColor = Color.YellowGreen;
treeView1.SelectedNode = tnRet;
oldNode = tnRet;
GetProperty();
}
}
}
}
catch (Exception exception)
{
Console.WriteLine(exception);
}
} #endregion

模型的属性加载:

  #region 属性信息加载

        void GetProperty()
{
//验证模型
if (Autodesk.Navisworks.Api.Application.ActiveDocument != null &&
!Autodesk.Navisworks.Api.Application.ActiveDocument.IsClear)
{ this.vGridControl1.Rows.Clear();
// 获取选中的相关的模型信息
foreach (ModelItem item in Autodesk.Navisworks.Api.Application.ActiveDocument.CurrentSelection.SelectedItems)
{ //获取想的模型属性信息
foreach (PropertyCategory category in item.PropertyCategories)
{
CategoryRow categoryRow=new CategoryRow(category.DisplayName);
foreach (var control in category.Properties)
{
EditorRow row1 = new EditorRow();
row1.Properties.FieldName = "Value";
row1.Properties.Caption = control.DisplayName;
var itemValue = control.Value;
string valueInfo;
switch (itemValue.DataType)
{
case VariantDataType.Boolean:
valueInfo = itemValue.ToBoolean().ToString();
break;
case VariantDataType.DateTime:
valueInfo = itemValue.ToDateTime().ToString(CultureInfo.InvariantCulture);
break;
case VariantDataType.DisplayString:
valueInfo = itemValue.ToDisplayString();
break;
case VariantDataType.Double:
valueInfo = itemValue.ToDouble().ToString();
break;
case VariantDataType.DoubleAngle:
valueInfo = itemValue.ToDoubleAngle().ToString();
break;
case VariantDataType.DoubleArea:
valueInfo = itemValue.ToDoubleArea().ToString();
break;
case VariantDataType.DoubleLength:
valueInfo = itemValue.ToDoubleLength().ToString();
break;
case VariantDataType.DoubleVolume:
valueInfo = itemValue.ToDoubleVolume().ToString();
break;
case VariantDataType.IdentifierString:
valueInfo = itemValue.ToIdentifierString();
break;
case VariantDataType.Int32:
valueInfo = itemValue.ToInt32().ToString();
break;
default:
valueInfo = itemValue.ToString();
break;
}
row1.Properties.Value = valueInfo; categoryRow.ChildRows.Add(row1);
}
this.vGridControl1.Rows.Add(categoryRow);
}
}
}
}
#endregion

最终效果:

主要是刚接触这个.不懂 只是自己在这写的。如果那位网友有更好的解决方案。请告诉我.谢谢哈。

源代码 下载。

Navisworks 2014 Api 简单的使用的更多相关文章

  1. Libvlc API 简单说明 [转]

    Libvlc API 简单说明 原文来自http://www.xuebuyuan.com/1519616.html libvlc_instance_t* libvlc_new(int argc, co ...

  2. salesforce零基础学习(八十五)streaming api 简单使用(接近实时获取你需要跟踪的数据的更新消息状态)

    Streaming API参考链接: https://trailhead.salesforce.com/en/modules/api_basics/units/api_basics_streaming ...

  3. 基于C语言libvirt API简单小程序

    libvirt API简单小程序 1.程序代码如下 #include<stdio.h> #include<libvirt/libvirt.h> int getDomainInf ...

  4. 常用函数式接口与Stream API简单讲解

    常用函数式接口与Stream API简单讲解 Stream简直不要太好使啊!!! 常用函数式接口 Supplier<T>,主要方法:T get(),这是一个生产者,可以提供一个T对象. C ...

  5. Navisworks API 简单二次开发 (自定义工具条)

    在Navisworks软件运行的时候界面右侧有个工具条.比较方便.但是在二次开发的时候我不知道在Api那里调用.如果有网友知道请告诉我.谢谢. 我用就自己设置一个工具.界面比较丑!没有美工. 代码: ...

  6. NavisWorks Api 简单使用与Gantt

    相信很多朋友在做BIM项目的时候.都有客户会提出项目计划,形象进度 等需求. 那么当前最主要的问题就是计划与BIM模型的关联问题.那么我在项目中是用户用Project软件编辑计划然后手动跟三维模型关联 ...

  7. 百度地图API简单应用

    在做移动端应用时经常用到百度地图API,百度API有强大的示例和文档,开发之前去百度相关网站注册密钥,很块博主只花了几分钟 百度地图API范例 百度地图API文档说明 例子1:输入特定关键字绘制地图标 ...

  8. 百度地图api简单使用方法

    百度地图API的使用方法   百度地图API 开始学习百度地图API最简单的方式是看一个简单的示例.以下代码创建了一个520x340大小的地图区域并以天安门作为地图的中心: 1. <html&g ...

  9. Web API 简单示例

    一.RESTful和Web API Representational State Transfer (REST) is a software architecture style consisting ...

随机推荐

  1. ASP.NET MVC开发日常一:SessionID合理清除

    在MVC Web开发中临时存储数据一般会用到Session,Cookie,ViewBag,ViewData,TempData.每个的使用场景是不同,具体区别有空再补上. Session数据最敏感,最需 ...

  2. UWP开发之Mvvmlight实践八:为什么事件注销处理要写在OnNavigatingFrom中

    前一段开发UWP应用的时候因为系统返回按钮事件(SystemNavigationManager.GetForCurrentView().BackRequested)浪费了不少时间.现象就是在手机版的详 ...

  3. OpenGL超级宝典笔记----渲染管线

    在OpenGL中任何事物都在3D空间中,但是屏幕和窗口是一个2D像素阵列,所以OpenGL的大部分工作都是关于如何把3D坐标转变为适应你屏幕的2D像素.3D坐标转为2D坐标的处理过程是由OpenGL的 ...

  4. AFNetworking 3.0 源码解读(八)之 AFImageDownloader

    AFImageDownloader 这个类对写DownloadManager有很大的借鉴意义.在平时的开发中,当我们使用UIImageView加载一个网络上的图片时,其原理就是把图片下载下来,然后再赋 ...

  5. git克隆项目到本地&&全局安装依赖项目&&安装依赖包&&启动服务

     一.安装本地开发环境 1.安装本项目 在需要保存到本地的项目的文件夹,进入到文件夹里点击右键,bash here,出现下图: 2.安装依赖项目  3.安装依赖包(进入到命令行) # 安装依赖包 $ ...

  6. 破解SQLServer for Linux预览版的3.5GB内存限制 (RHEL篇)

    微软发布了SQLServer for Linux,但是安装竟然需要3.5GB内存,这让大部分云主机用户都没办法尝试这个新东西 这篇我将讲解如何破解这个内存限制 要看关键的可以直接跳到第6步,只需要替换 ...

  7. pt-heartbeat

    pt-heartbeat是用来监测主从延迟的情况的,众所周知,传统的通过show slave status\G命令中的Seconds_Behind_Master值来判断主从延迟并不靠谱. pt-hea ...

  8. bootstrap

    访问Bootstrap中文网,下载bootstrap中文文档,选择用于生产环境的bootstrap. 在官网使用ctrl+f查找想要的内容. 这里记一下Visual Studio Code软件的用法: ...

  9. Vue.js——60分钟组件快速入门(上篇)

    组件简介 组件系统是Vue.js其中一个重要的概念,它提供了一种抽象,让我们可以使用独立可复用的小组件来构建大型应用,任意类型的应用界面都可以抽象为一个组件树: 那么什么是组件呢?组件可以扩展HTML ...

  10. GO 基础(一)

    Go语言基础工程目录如下(采用LiteIDE): 备注:需要提前设置GOPATH,即工作目录,bin.pkg.src为默认的GO工程目录结构.GOPATH可以支持多个,在windows下配置在环境变量 ...