欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

【Revit API】创建相机视角

程序员文章站 2022-10-06 17:24:19
在Revit中有一个相机功能可以以相机视角产生一个视图。一开始我在2016中找关键词Camera,但是没什么收获。 其实这个相机功能的真正核心是创建透视视图:View3D.CreatePerspective(Document, ElementId) 简单的代码示例如下: 关于上方向: Autodes ......

在Revit中有一个相机功能可以以相机视角产生一个视图。一开始我在Revit2016的API文档中找关键词Camera,但是没什么收获。

其实这个相机功能的真正核心是创建透视视图:View3D.CreatePerspective(Document, ElementId)

简单的代码示例如下:

var uiDocument = commandData.Application.ActiveUIDocument;
var doc = uiDocument.Document;
IEnumerable<ViewFamilyType> viewFamilyTypes = from elem in new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType)) let type = elem as ViewFamilyType where type.ViewFamily == ViewFamily.ThreeDimensional select type; using (Transaction tran = new Transaction(doc, "[ToolSet] Camera")) {
tran.start(); View3D view3D = View3D.CreatePerspective(doc, viewFamilyTypes.First().Id); if (null != view3D) { var eye = new XYZ(0,0,100); //相机坐标 var up = new XYZ(0,0,1); //上方向 var forward = new XYZ(3,4,5); //相机到目标点的向量 view3D.SetOrientation(new ViewOrientation3D(eye, up, forward)); view3D.DisplayStyle = DisplayStyle.ShadingWithEdges; } tran.Commit(); UIDocument RevitUiDoc = new UIDocument(doc); RevitUiDoc.ActiveView = view3D; }

 

关于上方向

【Revit API】创建相机视角

 

Autodesk的View3D博客:

https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2017/ENU/Revit-API/files/GUID-A7FA8DBC-830E-482D-9B66-147399524442-htm.html?_ga=2.66804973.2137010315.1527470650-214555019.1525755704