1、添加引用dll
Autodesk.Navisworks.Api.Controls-----wpf中可能在UI上出现异常,可以忽略。编译是能通过的。
Autodesk.Navisworks.Api.dll
Autodesk.Navisworks.Controls.dll
2、实例化控件
DocumentControl documentControl = new DocumentControl();
public Window1()
{
ApplicationControl.ApplicationType = ApplicationType.SingleDocument;
ApplicationControl.Initialize();
InitializeComponent();
viewControl.DocumentControl = documentControl;
}
3、加载模型文件
documentControl.Document.TryOpenFile(dlg.FileName);
4、设置相机的位置
Document oDoc = Autodesk.Navisworks.Api.Application.ActiveDocument;
Viewpoint oCurrVCopy = oDoc.CurrentViewpoint.CreateCopy();
Point3D newPos = new Point3D(12,-27,21);
oCurrVCopy.Position = newPos;
Point3D newLookAtPos = new Point3D(5, -20, 13);
oCurrVCopy.PointAt(newLookAtPos);
//UnitVector3D unitVector3D = new UnitVector3D(0.74290605603104, 0.30772176397717, 0.59447279827355);
//Rotation3D rotation3D = new Rotation3D(unitVector3D, -39);
//oCurrVCopy.Rotation = rotation3D;
oDoc.CurrentViewpoint.CopyFrom(oCurrVCopy);