应用程序:PlacementOptions
Revit平台:所有
Revit版本:2017.0
首次发布于:2017.0
编程语言:C#
技能水平:中等
类别:基础知识,族
类型:ExternalCommand
主题:通过选项交互放置族实例
摘要:
该示例演示如何通过选项放置族实例。
类:
Autodesk.Revit.UI.IExternalCommand
Autodesk.Revit.UI.UIDocument
Autodesk.Revit.UI.PromptForFamilyInstancePlacementOptions
Autodesk.Revit.UI.FaceBasedPlacementType
Autodesk.Revit.UI.SketchGalleryOptions
Autodesk.Revit.DB.FamilySymbol
Autodesk.Revit.DB.FamilyInstance
项目文件:
Command.cs
它包含继承自接口IExternalCommand并实现Execute方法的类Command。在执行方法中,它显示选项对话框,供用户选择放置族实例的选项。
OptionsForm.cs
这是用于选择基于面或基于草图的族实例的对话框。
FacebasedForm.cs
这是用于设置基于面的族实例的FaceBasedPlacementType选项的对话框。
SketchbasedForm.cs
这是用于设置基于草图的族实例的SketchGalleryOptions选项的对话框。
描述:
该示例提供以下功能。
- 让用户通过面、垂直面或工作平面选项放置基于面的族实例。
- 让用户通过线、弧和其他草图选项放置基于草图的族实例。
说明:
打开Revit应用程序,打开PlacementOptionsSample.rvt,然后执行命令。
1. 放置基于面的族实例。
a. 将显示“选择基于面或基于草图的选项”对话框以设置类型。
b. 选择“放置基于面的族实例的FaceBasedPlacementType选项”,然后单击“确定”按钮。
c. 它将显示“放置基于面的族实例”对话框以放置基于面的族实例。选择选项,然后单击“确定”按钮。
预期结果:根据选项设置,在光标位置放置基于面的族实例。
2. 放置基于草图的族实例。
d. 将显示“选择基于面或基于草图的选项”对话框以设置类型。
e. 选择“放置基于草图的族实例的SketchGalleryOptions选项”,然后单击“确定”按钮。
f. 它将显示“放置基于草图的族实例”对话框以放置基于草图的族实例。选择选项,然后单击“确定”按钮。
预期结果:根据选项设置,在光标位置放置基于草图的族实例。
源代码
完整的源代码请加入QQ群649037449,在群文件中下载RevitSDK.exe,解压后在文件夹中搜索本文中应用程序名称即可获得完整源码
OptionsForm.cs
namespace Revit.SDK.Samples.PlacementOptions.CS
{
partial class OptionsForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.buttonOK = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.radioButton1 = new System.Windows.Forms.RadioButton();
this.radioButton2 = new System.Windows.Forms.RadioButton();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// buttonOK
//
this.buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonOK.DialogResult = System.Windows.Forms.DialogResult.OK;
this.buttonOK.Location = new System.Drawing.Point(230, 145);
this.buttonOK.Name = "buttonOK";
this.buttonOK.Size = new System.Drawing.Size(75, 23);
this.buttonOK.TabIndex = 0;
this.buttonOK.Text = "&OK";
this.buttonOK.UseVisualStyleBackColor = true;
//
// buttonCancel
//
this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.buttonCancel.Location = new System.Drawing.Point(311, 145);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
this.buttonCancel.TabIndex = 1;
this.buttonCancel.Text = "&Cancel";
this.buttonCancel.UseVisualStyleBackColor = true;
//
// radioButton1
//
this.radioButton1.AutoSize = true;
this.radioButton1.Location = new System.Drawing.Point(15, 51);
this.radioButton1.Name = "radioButton1";
this.radioButton1.Size = new System.Drawing.Size(351, 17);
this.radioButton1.TabIndex = 2;
this.radioButton1.TabStop = true;
this.radioButton1.Text = "FaceBasedPlacementType for face based family instance placement.";
this.radioButton1.UseVisualStyleBackColor = true;
this.radioButton1.CheckedChanged += new System.EventHandler(this.radioButton1_CheckedChanged);
//
// radioButton2
//
this.radioButton2.AutoSize = true;
this.radioButton2.Location = new System.Drawing.Point(15, 86);
this.radioButton2.Name = "radioButton2";
this.radioButton2.Size = new System.Drawing.Size(304, 17);
this.radioButton2.TabIndex = 3;
this.radioButton2.TabStop = true;
this.radioButton2.Text = "SketchGalleryOptions for sketch family instance placement.";
this.radioButton2.UseVisualStyleBackColor = true;
this.radioButton2.CheckedChanged += new System.EventHandler(this.radioButton2_CheckedChanged);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label1.Location = new System.Drawing.Point(12, 9);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(296, 15);
this.label1.TabIndex = 4;
this.label1.Text = "Please select the options to place the family instance:";
//
// OptionsForm
//
this.AcceptButton = this.buttonOK;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.buttonCancel;
this.ClientSize = new System.Drawing.Size(398, 180);
this.Controls.Add(this.label1);
this.Controls.Add(this.radioButton2);
this.Controls.Add(this.radioButton1);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonOK);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "OptionsForm";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Select facebased or sketchbase options";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button buttonOK;
private System.Windows.Forms.Button buttonCancel;
private System.Windows.Forms.RadioButton radioButton1;
private System.Windows.Forms.RadioButton radioButton2;
private System.Windows.Forms.Label label1;
}
}
FacebasedForm.cs
namespace Revit.SDK.Samples.PlacementOptions.CS
{
partial class FacebasedForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.buttonOK = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.radioButtonDefault = new System.Windows.Forms.RadioButton();
this.radioButtonFace = new System.Windows.Forms.RadioButton();
this.radioButtonVF = new System.Windows.Forms.RadioButton();
this.radioButtonWP = new System.Windows.Forms.RadioButton();
this.label1 = new System.Windows.Forms.Label();
this.comboBoxFamilySymbol = new System.Windows.Forms.ComboBox();
this.SuspendLayout();
//
// buttonOK
//
this.buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonOK.DialogResult = System.Windows.Forms.DialogResult.OK;
this.buttonOK.Location = new System.Drawing.Point(265, 153);
this.buttonOK.Name = "buttonOK";
this.buttonOK.Size = new System.Drawing.Size(75, 23);
this.buttonOK.TabIndex = 0;
this.buttonOK.Text = "&OK";
this.buttonOK.UseVisualStyleBackColor = true;
//
// buttonCancel
//
this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.buttonCancel.Location = new System.Drawing.Point(346, 153);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
this.buttonCancel.TabIndex = 1;
this.buttonCancel.Text = "&Cancel";
this.buttonCancel.UseVisualStyleBackColor = true;
//
// radioButtonDefault
//
this.radioButtonDefault.AutoSize = true;
this.radioButtonDefault.Location = new System.Drawing.Point(51, 58);
this.radioButtonDefault.Name = "radioButtonDefault";
this.radioButtonDefault.Size = new System.Drawing.Size(59, 17);
this.radioButtonDefault.TabIndex = 2;
this.radioButtonDefault.Text = "Default";
this.radioButtonDefault.UseVisualStyleBackColor = true;
this.radioButtonDefault.CheckedChanged += new System.EventHandler(this.radioButtonDefault_CheckedChanged);
//
// radioButtonFace
//
this.radioButtonFace.AutoSize = true;
this.radioButtonFace.Checked = true;
this.radioButtonFace.Location = new System.Drawing.Point(51, 94);
this.radioButtonFace.Name = "radioButtonFace";
this.radioButtonFace.Size = new System.Drawing.Size(90, 17);
this.radioButtonFace.TabIndex = 3;
this.radioButtonFace.TabStop = true;
this.radioButtonFace.Text = "PlaceOnFace";
this.radioButtonFace.UseVisualStyleBackColor = true;
this.radioButtonFace.CheckedChanged += new System.EventHandler(this.radioButtonFace_CheckedChanged);
//
// radioButtonVF
//
this.radioButtonVF.AutoSize = true;
this.radioButtonVF.Location = new System.Drawing.Point(180, 60);
this.radioButtonVF.Name = "radioButtonVF";
this.radioButtonVF.Size = new System.Drawing.Size(208, 17);
this.radioButtonVF.TabIndex = 4;
this.radioButtonVF.Text = "PlaceOnVerticalFace (Plan View Only) ";
this.radioButtonVF.UseVisualStyleBackColor = true;
this.radioButtonVF.CheckedChanged += new System.EventHandler(this.radioButtonVF_CheckedChanged);
//
// radioButtonWP
//
this.radioButtonWP.AutoSize = true;
this.radioButtonWP.Location = new System.Drawing.Point(180, 94);
this.radioButtonWP.Name = "radioButtonWP";
this.radioButtonWP.Size = new System.Drawing.Size(119, 17);
this.radioButtonWP.TabIndex = 5;
this.radioButtonWP.Text = "PlaceOnWorkPlane";
this.radioButtonWP.UseVisualStyleBackColor = true;
this.radioButtonWP.CheckedChanged += new System.EventHandler(this.radioButtonWP_CheckedChanged);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(17, 21);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(122, 13);
this.label1.TabIndex = 6;
this.label1.Text = "Available Family Symbol:";
//
// comboBoxFamilySymbol
//
this.comboBoxFamilySymbol.FormattingEnabled = true;
this.comboBoxFamilySymbol.Location = new System.Drawing.Point(151, 19);
this.comboBoxFamilySymbol.Name = "comboBoxFamilySymbol";
this.comboBoxFamilySymbol.Size = new System.Drawing.Size(193, 21);
this.comboBoxFamilySymbol.TabIndex = 7;
this.comboBoxFamilySymbol.SelectedIndexChanged += new System.EventHandler(this.comboBoxFamilySymbol_SelectedIndexChanged);
//
// FacebasedForm
//
this.AcceptButton = this.buttonOK;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.buttonCancel;
this.ClientSize = new System.Drawing.Size(433, 188);
this.Controls.Add(this.comboBoxFamilySymbol);
this.Controls.Add(this.label1);
this.Controls.Add(this.radioButtonWP);
this.Controls.Add(this.radioButtonVF);
this.Controls.Add(this.radioButtonFace);
this.Controls.Add(this.radioButtonDefault);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonOK);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "FacebasedForm";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Place facebased family instance";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button buttonOK;
private System.Windows.Forms.Button buttonCancel;
private System.Windows.Forms.RadioButton radioButtonDefault;
private System.Windows.Forms.RadioButton radioButtonFace;
private System.Windows.Forms.RadioButton radioButtonVF;
private System.Windows.Forms.RadioButton radioButtonWP;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.ComboBox comboBoxFamilySymbol;
}
}
SketchbasedForm.cs
namespace Revit.SDK.Samples.PlacementOptions.CS
{
partial class SketchbasedForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.buttonOK = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.comboBoxFamilySymbol = new System.Windows.Forms.ComboBox();
this.radioButtonPEllipse = new System.Windows.Forms.RadioButton();
this.radioButtonSpline = new System.Windows.Forms.RadioButton();
this.radioButtonArc3P = new System.Windows.Forms.RadioButton();
this.radioButtonLine = new System.Windows.Forms.RadioButton();
this.radioButtonPickLine = new System.Windows.Forms.RadioButton();
this.radioButtonArcC = new System.Windows.Forms.RadioButton();
this.SuspendLayout();
//
// buttonOK
//
this.buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonOK.DialogResult = System.Windows.Forms.DialogResult.OK;
this.buttonOK.Location = new System.Drawing.Point(232, 168);
this.buttonOK.Name = "buttonOK";
this.buttonOK.Size = new System.Drawing.Size(75, 23);
this.buttonOK.TabIndex = 0;
this.buttonOK.Text = "&OK";
this.buttonOK.UseVisualStyleBackColor = true;
//
// buttonCancel
//
this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.buttonCancel.Location = new System.Drawing.Point(313, 168);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
this.buttonCancel.TabIndex = 1;
this.buttonCancel.Text = "&Cancel";
this.buttonCancel.UseVisualStyleBackColor = true;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(24, 17);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(122, 13);
this.label1.TabIndex = 2;
this.label1.Text = "Available Family Symbol:";
//
// comboBoxFamilySymbol
//
this.comboBoxFamilySymbol.FormattingEnabled = true;
this.comboBoxFamilySymbol.Location = new System.Drawing.Point(152, 14);
this.comboBoxFamilySymbol.Name = "comboBoxFamilySymbol";
this.comboBoxFamilySymbol.Size = new System.Drawing.Size(193, 21);
this.comboBoxFamilySymbol.TabIndex = 12;
this.comboBoxFamilySymbol.SelectedIndexChanged += new System.EventHandler(this.comboBoxFamilySymbol_SelectedIndexChanged);
//
// radioButtonPEllipse
//
this.radioButtonPEllipse.AutoSize = true;
this.radioButtonPEllipse.Location = new System.Drawing.Point(195, 89);
this.radioButtonPEllipse.Name = "radioButtonPEllipse";
this.radioButtonPEllipse.Size = new System.Drawing.Size(113, 17);
this.radioButtonPEllipse.TabIndex = 11;
this.radioButtonPEllipse.Text = "SGO_PartialEllipse";
this.radioButtonPEllipse.UseVisualStyleBackColor = true;
this.radioButtonPEllipse.CheckedChanged += new System.EventHandler(this.radioButtonPEllipse_CheckedChanged);
//
// radioButtonSpline
//
this.radioButtonSpline.AutoSize = true;
this.radioButtonSpline.Location = new System.Drawing.Point(195, 55);
this.radioButtonSpline.Name = "radioButtonSpline";
this.radioButtonSpline.Size = new System.Drawing.Size(86, 17);
this.radioButtonSpline.TabIndex = 10;
this.radioButtonSpline.Text = "SGO_Spline ";
this.radioButtonSpline.UseVisualStyleBackColor = true;
this.radioButtonSpline.CheckedChanged += new System.EventHandler(this.radioButtonSpline_CheckedChanged);
//
// radioButtonArc3P
//
this.radioButtonArc3P.AutoSize = true;
this.radioButtonArc3P.Location = new System.Drawing.Point(52, 89);
this.radioButtonArc3P.Name = "radioButtonArc3P";
this.radioButtonArc3P.Size = new System.Drawing.Size(100, 17);
this.radioButtonArc3P.TabIndex = 9;
this.radioButtonArc3P.Text = "SGO_Arc3Point";
this.radioButtonArc3P.UseVisualStyleBackColor = true;
this.radioButtonArc3P.CheckedChanged += new System.EventHandler(this.radioButtonArc3P_CheckedChanged);
//
// radioButtonLine
//
this.radioButtonLine.AutoSize = true;
this.radioButtonLine.Checked = true;
this.radioButtonLine.Location = new System.Drawing.Point(52, 53);
this.radioButtonLine.Name = "radioButtonLine";
this.radioButtonLine.Size = new System.Drawing.Size(74, 17);
this.radioButtonLine.TabIndex = 8;
this.radioButtonLine.TabStop = true;
this.radioButtonLine.Text = "SGO_Line";
this.radioButtonLine.UseVisualStyleBackColor = true;
this.radioButtonLine.CheckedChanged += new System.EventHandler(this.radioButtonLine_CheckedChanged);
//
// radioButtonPickLine
//
this.radioButtonPickLine.AutoSize = true;
this.radioButtonPickLine.Location = new System.Drawing.Point(195, 124);
this.radioButtonPickLine.Name = "radioButtonPickLine";
this.radioButtonPickLine.Size = new System.Drawing.Size(100, 17);
this.radioButtonPickLine.TabIndex = 14;
this.radioButtonPickLine.Text = "SGO_PickLines";
this.radioButtonPickLine.UseVisualStyleBackColor = true;
this.radioButtonPickLine.CheckedChanged += new System.EventHandler(this.radioButtonPickLine_CheckedChanged);
//
// radioButtonArcC
//
this.radioButtonArcC.AutoSize = true;
this.radioButtonArcC.Location = new System.Drawing.Point(52, 122);
this.radioButtonArcC.Name = "radioButtonArcC";
this.radioButtonArcC.Size = new System.Drawing.Size(125, 17);
this.radioButtonArcC.TabIndex = 13;
this.radioButtonArcC.Text = "SGO_ArcCenterEnds";
this.radioButtonArcC.UseVisualStyleBackColor = true;
this.radioButtonArcC.CheckedChanged += new System.EventHandler(this.radioButtonArcC_CheckedChanged);
//
// SketchbasedForm
//
this.AcceptButton = this.buttonOK;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.buttonCancel;
this.ClientSize = new System.Drawing.Size(400, 203);
this.Controls.Add(this.radioButtonPickLine);
this.Controls.Add(this.radioButtonArcC);
this.Controls.Add(this.comboBoxFamilySymbol);
this.Controls.Add(this.radioButtonPEllipse);
this.Controls.Add(this.radioButtonSpline);
this.Controls.Add(this.radioButtonArc3P);
this.Controls.Add(this.radioButtonLine);
this.Controls.Add(this.label1);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonOK);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "SketchbasedForm";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Place sketchbased family instance";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button buttonOK;
private System.Windows.Forms.Button buttonCancel;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.ComboBox comboBoxFamilySymbol;
private System.Windows.Forms.RadioButton radioButtonPEllipse;
private System.Windows.Forms.RadioButton radioButtonSpline;
private System.Windows.Forms.RadioButton radioButtonArc3P;
private System.Windows.Forms.RadioButton radioButtonLine;
private System.Windows.Forms.RadioButton radioButtonPickLine;
private System.Windows.Forms.RadioButton radioButtonArcC;
}
}
版权所有 :无锡模信建筑科技有限公司 苏ICP备2021028830号-1 BIM建模|BIM技术应用|BIM软件开发
联系地址:江苏省无锡市新吴区龙山路4号B座705 手机:18761516598