【发布时间】:2020-11-09 21:01:39
【问题描述】:
我从The Building Coder 复制了一些代码,以在已打开的 Revit 文件中创建 3D 透视图。但是,当我运行 Execute 方法时,绝对没有任何反应。输出日志中没有抛出异常或错误,所以我认为这只是我的代码副本的问题。
我需要怎样做才能让这段代码创建一个 3D 透视图和/或在 Revit 中打开它?
using (Transaction t = new Transaction(doc, "CameraTransaction"))
{
t.Start();
IEnumerable<ViewFamilyType> viewFamilyTypes = from elem in new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType))
let type = elem as ViewFamilyType
where type.ViewFamily == ViewFamily.ThreeDimensional
select type;
View3D issue3DCameraView = View3D.CreatePerspective(doc, viewFamilyTypes.First().Id);
issue3DCameraView.Name = "Issue_" + issue.Name;
PerspectiveCamera cam = issue.Viewpoints[i].PerspectiveCamera;
XYZ position = new XYZ(cam.CameraViewPoint.X, cam.CameraViewPoint.Y, cam.CameraViewPoint.Z);
XYZ up = new XYZ(cam.CameraUpVector.X, cam.CameraUpVector.Y, cam.CameraUpVector.Z);
XYZ sightDir = new XYZ(cam.CameraDirection.X, cam.CameraDirection.Y, cam.CameraDirection.Z);
var orientation = new ViewOrientation3D(position, up, sightDir);
issue3DCameraView.SetOrientation(orientation);
Parameter farClip = issue3DCameraView.LookupParameter("Far Clip Active");
farClip.Set(0);
Parameter cropRegionVisible = issue3DCameraView.LookupParameter("Crop Region Visible");
cropRegionVisible.Set(1);
Parameter cropView = issue3DCameraView.LookupParameter("Crop View");
cropView.Set(1);
/* Removed
//Added in an attempt to make the code work
RevitCommandId commandId = RevitCommandId.LookupPostableCommandId(PostableCommand.Default3DView);
if (app.CanPostCommand(commandId))
{
app.PostCommand(commandId);
}*/
t.Commit();
}
编辑:对这个问题的进一步研究表明,事务只是在“issue3DCameraView.SetOrientation(orientation);”处停止。行。
【问题讨论】: