应用程序:ViewTemplateCreation
Revit平台:所有
Revit版本:2020.0
首次发行于:2020.0
编程语言:C#
技能水平:中等
类别:参数、视图
类型:ExternalCommand
主题:创建和配置新的视图模板
摘要:
本示例展示了从常规视图创建新视图模板和配置视图模板设置的过程。
相关类:
Autodesk.Revit.UI.IExternalCommand;
Autodesk.Revit.UI.Result;
Autodesk.Revit.DB.Transaction;
Autodesk.Revit.DB.Document;
Autodesk.Revit.DB.FilteredElementCollector;
Autodesk.Revit.DB.BuiltInCategory;
Autodesk.Revit.DB.View;
Autodesk.Revit.DB.ViewDetailLevel;
Autodesk.Revit.DB.ElementId;
Autodesk.Revit.DB.BuiltInParameter;
Autodesk.Revit.DB.Color;
Autodesk.Revit.DB.FillPatternElement;
Autodesk.Revit.DB.FillPatternTarget;
Autodesk.Revit.DB.OverrideGraphicSettings;
项目文件:
Command.cs
包含从接口IExternalCommand继承并实现执行方法的Command类。它创建并显示View Template Creation表单。
Utils.cs
包含用于显示消息框的几个函数和一个带有示例名称的常量字符串。
ViewTemplateCreationForm.cs
声明View Template Creation表单。在此表单中,用户可以选择要创建模板的视图,设置包括“部件可见性”参数的设置,设置“详细级别”参数的值。用户按“应用”按钮后,将基于所选视图创建新的视图模板,参数设置将应用于参数,V / G Overrides Model切割模式设置将更改以下类别:柱、门、墙壁、窗户。
以下是V / G模型切割模式的更改方式:“前景图案”设置为“实填充”,“背景颜色”设置为“黑色”。
最后,新创建的模板将分配给所选视图。
描述:
此示例提供以下功能:
-基于所选视图创建新的视图模板
-设置“部件可见性”参数的包括设置
-设置“详细级别”参数的值
-更改几个模型类别的可见性/图形覆盖
使用说明:
启动Revit应用程序,从Architecture模板创建新项目。
1.执行命令。
预期结果:View Template Creation表单出现。
2.选择要创建视图模板的视图。
3.选择“部件可见性”参数的包括设置。
4.选择“详细级别”参数的值。
5.按“应用”按钮。
预期结果:基于所选视图创建新的视图模板,参数设置将应用于参数,以下类别的V / G Overrides模型切割模式设置将更改:柱、门、墙壁、窗户。
以下是V / G模型切割模式的更改方式:“前景图案”设置为“实填充”,“背景颜色”设置为“黑色”。
新创建的视图模板将分配给所选视图。
源代码:
完整的源代码请加入QQ群649037449,在群文件中下载RevitSDK.exe,解压后在文件夹中搜索本文中应用程序名称即可获得完整源码
Command.cs
//
// (C) Copyright 2003-2018 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
namespace Revit.SDK.Samples.ViewTemplateCreation.CS
{
/// <summary>
/// Implements the Revit add-in interface IExternalCommand
/// </summary>
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
[Autodesk.Revit.Attributes.Journaling(Autodesk.Revit.Attributes.JournalingMode.NoCommandData)]
public class Command : IExternalCommand
{
/// <summary>
/// Implement this method as an external command for Revit.
/// </summary>
/// <param name="commandData">An object that is passed to the external application
/// which contains data related to the command,
/// such as the application object and active view.</param>
/// <param name="message">A message that can be set by the external application
/// which will be displayed if a failure or cancellation is returned by
/// the external command.</param>
/// <param name="elements">A set of elements to which the external application
/// can add elements that are to be highlighted in case of failure or cancellation.</param>
/// <returns>Return the status of the external command.
/// A result of Succeeded means that the API external method functioned as expected.
/// Cancelled can be used to signify that the user cancelled the external operation
/// at some point. Failure should be returned if the application is unable to proceed with
/// the operation.</returns>
public virtual Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
try
{
Document document = commandData.Application.ActiveUIDocument.Document;
ViewTemplateCreationForm form = new ViewTemplateCreationForm(document);
form.ShowDialog();
return Result.Succeeded;
}
catch (Exception ex)
{
Utils.ShowWarningMessageBox(ex.ToString());
return Result.Failed;
}
}
}
}
Utils.cs
//
// (C) Copyright 2003-2018 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
namespace Revit.SDK.Samples.ViewTemplateCreation.CS
{
/// <summary>
/// Utils class contains useful methods and members for using in whole project.
/// </summary>
public class Utils
{
/// <summary>
/// Shows regular message box with warning icon and OK button
/// </summary>
public static void ShowWarningMessageBox(string message)
{
System.Windows.Forms.MessageBox.Show(
message,
SampleName,
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Warning);
}
/// <summary>
/// Shows regular message box with information icon and OK button
/// </summary>
public static void ShowInformationMessageBox(string message)
{
System.Windows.Forms.MessageBox.Show(
message,
SampleName,
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Information);
}
/// <summary>
/// Contains a name of this sample
/// </summary>
public const string SampleName = "View Template Creation sample";
}
}