需要对我的代码进行哪些更改才能在 Revit 中创建新的 3D 透视图?
What changes need to be made to my code to create a new 3D perspective view in Revit?
我从 The Building Coder 复制了一些代码以在已打开的 Revit 文件中创建 3D 透视图。但是,当我 运行 Execute 方法绝对没有任何反应。输出日志中没有抛出异常或错误,所以我认为这只是我的代码副本的问题。
我需要做什么才能使此代码创建 3D 透视图and/or在 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(方向);”线.
我无法通过查看您的代码来判断可能有什么问题...当然,除了您添加的 PostCommand
调用。那肯定没用,反而是。
我建议您先研究 Creating and Setting Up a 3D View 上的建筑编码器主题组中列出的其他一些文章,而不是尝试为您修复代码。
此代码的问题在于 issue.Viewpoints[i].PerspectiveCamera 的源代码。代码本身工作正常。
我在这里留下这个答案是为了那些追随我的人。
我从 The Building Coder 复制了一些代码以在已打开的 Revit 文件中创建 3D 透视图。但是,当我 运行 Execute 方法绝对没有任何反应。输出日志中没有抛出异常或错误,所以我认为这只是我的代码副本的问题。
我需要做什么才能使此代码创建 3D 透视图and/or在 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(方向);”线.
我无法通过查看您的代码来判断可能有什么问题...当然,除了您添加的 PostCommand
调用。那肯定没用,反而是。
我建议您先研究 Creating and Setting Up a 3D View 上的建筑编码器主题组中列出的其他一些文章,而不是尝试为您修复代码。
此代码的问题在于 issue.Viewpoints[i].PerspectiveCamera 的源代码。代码本身工作正常。
我在这里留下这个答案是为了那些追随我的人。