Navisworks 2014 Api 简单的使用
初次接触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 简单的使用的更多相关文章
- Libvlc API 简单说明 [转]
Libvlc API 简单说明 原文来自http://www.xuebuyuan.com/1519616.html libvlc_instance_t* libvlc_new(int argc, co ...
- salesforce零基础学习(八十五)streaming api 简单使用(接近实时获取你需要跟踪的数据的更新消息状态)
Streaming API参考链接: https://trailhead.salesforce.com/en/modules/api_basics/units/api_basics_streaming ...
- 基于C语言libvirt API简单小程序
libvirt API简单小程序 1.程序代码如下 #include<stdio.h> #include<libvirt/libvirt.h> int getDomainInf ...
- 常用函数式接口与Stream API简单讲解
常用函数式接口与Stream API简单讲解 Stream简直不要太好使啊!!! 常用函数式接口 Supplier<T>,主要方法:T get(),这是一个生产者,可以提供一个T对象. C ...
- Navisworks API 简单二次开发 (自定义工具条)
在Navisworks软件运行的时候界面右侧有个工具条.比较方便.但是在二次开发的时候我不知道在Api那里调用.如果有网友知道请告诉我.谢谢. 我用就自己设置一个工具.界面比较丑!没有美工. 代码: ...
- NavisWorks Api 简单使用与Gantt
相信很多朋友在做BIM项目的时候.都有客户会提出项目计划,形象进度 等需求. 那么当前最主要的问题就是计划与BIM模型的关联问题.那么我在项目中是用户用Project软件编辑计划然后手动跟三维模型关联 ...
- 百度地图API简单应用
在做移动端应用时经常用到百度地图API,百度API有强大的示例和文档,开发之前去百度相关网站注册密钥,很块博主只花了几分钟 百度地图API范例 百度地图API文档说明 例子1:输入特定关键字绘制地图标 ...
- 百度地图api简单使用方法
百度地图API的使用方法 百度地图API 开始学习百度地图API最简单的方式是看一个简单的示例.以下代码创建了一个520x340大小的地图区域并以天安门作为地图的中心: 1. <html&g ...
- Web API 简单示例
一.RESTful和Web API Representational State Transfer (REST) is a software architecture style consisting ...
随机推荐
- C# 生成验证码图片时消除锯齿
引言 基于生成图片实现了一个手机号转图片的需求. 内容也很简单,直接用手机号生成一个png图片.就是为了背景透明以便其他地方调用. 有无锯齿主要依靠一句代码:g.TextRenderingHint= ...
- 基于Composer Player 模型加载和相关属性设置
主要是基于达索软件Composer Player.的基础上做些二次开发. public class ComposerToolBarSetting { public bool AntiAliasingO ...
- 子类继承父类时JVM报出Error:Implicit super constructor People() is undefined for default constructor. Must define an explicit constructor
当子类继承父类的时候,若父类没有定义带参的构造方法,则子类可以继承父类的默认构造方法 当父类中定义了带参的构造方法,子类必须显式的调用父类的构造方法 若此时,子类还想调用父类的默认构造方法,必须在父类 ...
- MVC还是MVVM?或许VMVC更适合WinForm客户端
最近开始重构一个稍嫌古老的C/S项目,原先采用的技术栈是『WinForm』+『WCF』+『EF』.相对于现在铺天盖地的B/S架构来说,看上去似乎和Win95一样古老,很多新入行的,可能就没有见过经典的 ...
- 分享一个php的启动关闭脚本(原)
自己简单写的一个php服务的启动脚本和大家分享 思路(实现的原理): 1:function模块+case语句多分支判断 2:通过添加# chkconfig: 2345 43 89注释实现开机自启动(前 ...
- eclipse,myeclipse 误删文件,回滚历史文件操作
昨天因为误操作把一个写了一上午的代码给删了,找到的这个,以前竟然还没发现有这个功能- -! 具体操作: 1.建立同路径同名的文件 2.文件上右键 --> Compare With --> ...
- Direct3D Draw函数 异步调用原理解析
概述 在D3D10中,一个基本的渲染流程可分为以下步骤: 清理帧缓存: 执行若干次的绘制: 通过Device API创建所需Buffer: 通过Map/Unmap填充数据到Buffer中: 将Buff ...
- Visual Studio 2015 移动跨平台开发初体验
微软换了新 CEO 后变化很大,对我们团队最有利的消息就是 Visual Studio 2015 支持移动应用跨平台开发. 还记不记得很早之前,Xamarin 宣布与微软成为合作伙伴的消息.显然,Xa ...
- java的继承练习
看程序写结果: A:一个类的静态代码块,构造代码块,构造方法的执行流程 静态代码块 > 构造代码块 > 构造方法 B:静态的内容是随着类的加载而加载 静态代码块的内 ...
- Linux命令:ps,netstat,top
ps ps用于查看当前运行的进程.如果想查看动态的进程信息,可以使用top命令.查看详细命令帮助使用man ps. ps最常用的选项组合就是ps aux: # ps aux USER PID %CPU ...