68 lines
2.4 KiB
C#
68 lines
2.4 KiB
C#
|
using Autodesk.Revit.DB;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace GraphicsStudy
|
|||
|
{
|
|||
|
public static class ViewMethod
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 新建面积方案,事务在方法外开启
|
|||
|
/// </summary>
|
|||
|
/// <param name="doc"></param>
|
|||
|
/// <param name="name"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public static AreaScheme CreateAreaView(Document doc, string name)
|
|||
|
{
|
|||
|
AreaScheme areaScheme = new FilteredElementCollector(doc).OfClass(typeof(AreaScheme)).Cast<AreaScheme>().FirstOrDefault();
|
|||
|
|
|||
|
ICollection<ElementId> newElemIds = ElementTransformUtils.CopyElement(doc, areaScheme.Id, XYZ.Zero);
|
|||
|
AreaScheme newVft = doc.GetElement(newElemIds.First()) as AreaScheme;
|
|||
|
newVft.Name = name;
|
|||
|
return newVft;
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 视图浏览器设置,(事务在方法外面开启)
|
|||
|
/// </summary>
|
|||
|
/// <param name="v"></param>
|
|||
|
/// <param name="doc"></param>
|
|||
|
/// <param name="name1"></param>
|
|||
|
/// <param name="name2"></param>
|
|||
|
public static void SetView(this View v, Document doc, string name1, string name2)
|
|||
|
{
|
|||
|
BrowserOrganization hh = BrowserOrganization.GetCurrentBrowserOrganizationForViews(doc);
|
|||
|
var aa = hh.GetFolderItems(doc.ActiveView.Id);
|
|||
|
List<string> viewNameList = new List<string>();
|
|||
|
foreach (var item in aa)
|
|||
|
{
|
|||
|
if (item.ElementId.IntegerValue > 0)
|
|||
|
{
|
|||
|
viewNameList.Add((doc.GetElement(item.ElementId) as ParameterElement).GetDefinition().Name);
|
|||
|
}
|
|||
|
}
|
|||
|
if (viewNameList.Count != 0)
|
|||
|
{
|
|||
|
v.GetParameters(viewNameList[0]).First().Set(name1);
|
|||
|
if (viewNameList.Count > 1)
|
|||
|
{
|
|||
|
v.GetParameters(viewNameList[1]).First().Set(name2);
|
|||
|
if (viewNameList.Count > 2)
|
|||
|
{
|
|||
|
viewNameList.RemoveAt(0);
|
|||
|
viewNameList.RemoveAt(1);
|
|||
|
for (int i = 0; i < viewNameList.Count; i++)
|
|||
|
{
|
|||
|
v.GetParameters(viewNameList[i]).First().SetValueString(name2);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
}
|