【Revit API】建立相機視角

在Revit中有一個相機功能能夠以相機視角產生一個視圖。一開始我在Revit2016的API文檔中找關鍵詞Camera,可是沒什麼收穫。html

其實這個相機功能的真正核心是建立透視視圖:View3D.CreatePerspective(Document, ElementId)ui

簡單的代碼示例以下:spa

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; }

 

關於上方向code

 

Autodesk的View3D博客:htm

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.1525755704blog

相關文章
相關標籤/搜索