初次接触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. 【NLP】Python NLTK处理原始文本

    Python NLTK 处理原始文本 作者:白宁超 2016年11月8日22:45:44 摘要:NLTK是由宾夕法尼亚大学计算机和信息科学使用python语言实现的一种自然语言工具包,其收集的大量公开 ...

  2. 说说BPM数据表和日志表中几个状态字段的详细解释

    有个客户说需要根据这些字段的值作为判断条件做一些定制化需求,所以需要知道这些字段的名词解释,以及里面存储的值具体代表什么意思 我只好为你们整理奉上这些了! Open Work Sheet  0 Sav ...

  3. iOS:以前笔记,未整理版。太多了,先放着吧。。。。。。。

    1. -(void)timetick { _d = 0; NSTimer *newtime =[NSTimer scheduledTimerWithTimeInterval:1 target:self ...

  4. Ubuntu(Linux) + mono + jexus +asp.net MVC3 部署

    感谢  张善友 的建议,我把 微信订餐  由nginx 改成 jexus,目前运行状况来说,确实稳定了很多,再次感谢. 部署步骤参考 jexus官网:http://www.jexus.org/ htt ...

  5. AutoMapper(二)

    返回总目录 首先,先创建一个控制台项目,引用AutoMapper程序集,创建三个类User,UserDto,UserMappingProfile,下面的知识点的演示都以此项目为基础,代码分别如下: n ...

  6. Goodbye2014,Hello2015

    正如我在研发会议上说的,总结是为了更好的计划:而计划,则是让你做事有目标,有方向:有了目标和方向,你才能真正把事情做成! 总的来说2014年可以归纳为下图: 2014年总结 一年的活动,基本可以归纳为 ...

  7. Linux网络编程系列-常见疑惑

    1.并发TCP最大连接数 一个TCP连接有一个四元组唯一标识{local_ip, local_port, remote_ip, remote_port} client端建立连接请求时,通常让系统分配一 ...

  8. Android开发学习之路-3DTouch效果模仿

    3D Touch是什么效果的大家应该都知道了.什么?不知道,那也没办法呀,我也没有iPhone 6s演示给你看的. 本篇博客要做的效果图: 来个低质量动图: 这个动图效果不是很好,实际上模糊效果应该是 ...

  9. [转]Fiddler抓取Android真机上的HTTPS包

    此篇文章转载自:http://blog.csdn.net/roland_sun/article/details/30078353 工作中经常会需要对一些app进行抓包, 但是每次默认都是只抓http请 ...

  10. 如何权衡自己的angular水准

    angular是现在常用的一个前端MVVM框架,感受下下面的问题权衡下自己的水准吧. 1. angular的数据绑定采用什么机制?详述原理2. 两个平级界面块a和b,如果a中触发一个事件,有哪些方式能 ...