using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.UI.Selection;
namespace ClassLibrary1
{
[Autodesk.Revit.Attributes.Transaction(TransactionMode.Manual)]
[Autodesk.Revit.Attributes.Regeneration(RegenerationOption.Manual)]
public class GetElement : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
Selection selection = uidoc.Selection;
#region 如何获取元素
#region 阵列
线性阵列 数量是2-200个
Reference reff = selection.PickObject(ObjectType.Element, "请选择你要阵列的元素");
Element el = doc.GetElement(reff);
using (Transaction ts = new Transaction(doc))
{
ts.Start("线性阵列");
XYZ translation = new XYZ(0, 10, 0);
int count = 10;
LinearArray.Create(doc, doc.ActiveView, el.Id, count, translation, ArrayAnchorMember.Second);
ts.Commit();
}
//弧度阵列
Reference reff = selection.PickObject(ObjectType.Element, "请选择你要阵列的元素");
Element el = doc.GetElement(reff);
using (Transaction ts = new Transaction(doc))
{
ts.Start("弧度阵列");
XYZ translation = new XYZ(0, 10, 0);
int count = 25;
RadialArray.Create(doc, doc.ActiveView, el.Id,count,Line.CreateBound(new XYZ(0, 0, 1),XYZ.Zero), Math.PI / 12, ArrayAnchorMember.Second);
ts.Commit();
}
#endregion
return Result.Succeeded;
}
}
}