添加项目文件。
This commit is contained in:
157
CDMUtil/Utility/BeamUtil.cs
Normal file
157
CDMUtil/Utility/BeamUtil.cs
Normal file
@@ -0,0 +1,157 @@
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.DB.Structure;
|
||||
using Autodesk.Revit.UI;
|
||||
using CDM.Interop.Revit.CDMComponent;
|
||||
using CDM.Interop.Revit.RevitCompoent;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CDM.Interop.Revit.Utility
|
||||
{
|
||||
class BeamUtil : Utility
|
||||
{
|
||||
public static List<CDMBeam> GetBeamsCDM(Document doc, IList<Element> levels)
|
||||
{
|
||||
List<CDMBeam> cdmBeams = new List<CDMBeam>();
|
||||
var beams = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_StructuralFraming).OfClass(typeof(FamilyInstance)).ToElements();
|
||||
//得到标高+编码
|
||||
Dictionary<ElementId, string> dictLevelId_LevelCodes = GetDictLevelId_LevelCodes(doc);
|
||||
//梁类型与编码
|
||||
Dictionary<ElementId, string> dicBeams = new Dictionary<ElementId, string>();
|
||||
int num = 1;
|
||||
for (int i = 0; i < beams.Count; i++)
|
||||
{
|
||||
ElementId beamtypeId = beams[i].GetTypeId();
|
||||
try
|
||||
{
|
||||
|
||||
if (num > 9 && num <= 99)
|
||||
{
|
||||
dicBeams.Add(beamtypeId, string.Format("0{0}", num));
|
||||
}
|
||||
else if (num > 99)
|
||||
{
|
||||
dicBeams.Add(beamtypeId, string.Format("{0}", num));
|
||||
}
|
||||
else
|
||||
{
|
||||
dicBeams.Add(beamtypeId, string.Format("00{0}", num));
|
||||
}
|
||||
num += 1;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (FamilyInstance beam in beams)
|
||||
{
|
||||
//View3D v = (View3D)uidoc.ActiveView;
|
||||
//if (v == null)
|
||||
//{
|
||||
// var vi = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Views).OfClass(typeof(View3D)).ToElements();
|
||||
// uidoc.ActiveView = (View3D)vi.FirstOrDefault();
|
||||
//}
|
||||
//直线梁
|
||||
XYZ s = ((LocationCurve)beam.Location).Curve.GetEndPoint(0);
|
||||
XYZ e = ((LocationCurve)beam.Location).Curve.GetEndPoint(1);
|
||||
//XYZ s = beam.GetSweptProfile().GetDrivingCurve().GetEndPoint(0);
|
||||
//XYZ e = beam.GetSweptProfile().GetDrivingCurve().GetEndPoint(1);
|
||||
if (beam.HasSweptProfile() == true)
|
||||
{
|
||||
CDMBeam cdmbeam = new CDMBeam(beam);
|
||||
//通过out,将获取到的值复制给cdm的类型id,out参数必须在函数内初始化值
|
||||
dicBeams.TryGetValue(cdmbeam.SymbolId, out cdmbeam.CategoryCode);
|
||||
dictLevelId_LevelCodes.TryGetValue(cdmbeam.LevelId, out cdmbeam.LevelCode);
|
||||
cdmBeams.Add(cdmbeam);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < levels.Count(); i++)
|
||||
{
|
||||
for (int j = 0; j < dicBeams.Count; j++)
|
||||
{
|
||||
ElementId id = dicBeams.ElementAt(j).Key;
|
||||
//归类cdm中同标高同类型
|
||||
IEnumerable<CDMBeam> targetcdm = from b in cdmBeams
|
||||
where b.LevelId.Equals(levels[i].Id) && b.SymbolId.Equals(id)
|
||||
select b;
|
||||
List<CDMBeam> CdmBeamsordered = targetcdm.OrderByDescending(p => p.Yw).ThenBy(p => p.Xl).ToList();
|
||||
//排序
|
||||
//var li = targetcdm.ToList();
|
||||
//List<CDMBeam> li = targetcdm.OrderByDescending(p => p.BasePoint.Y).ThenBy(p => p.BasePoint.X).ToList();
|
||||
|
||||
for (int k = 0; k < CdmBeamsordered.Count; k++)
|
||||
{
|
||||
if (k > 8)
|
||||
{
|
||||
if (k > 98)
|
||||
{
|
||||
CdmBeamsordered[k].LevelComponentCode = string.Format("{0}", k + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
CdmBeamsordered[k].LevelComponentCode = string.Format("0{0}", k + 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CdmBeamsordered[k].LevelComponentCode = string.Format("00{0}", k + 1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return cdmBeams;
|
||||
}
|
||||
public static void PlaceBeams(Document doc, Family family, List<RevitBeam> rbeams, Level level)
|
||||
{
|
||||
if (rbeams == null || level == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FamilySymbol defaultfamilysymbol = doc.GetElement(family.GetFamilySymbolIds().FirstOrDefault()) as FamilySymbol;
|
||||
FamilySymbol targetBeamSymbol = null;
|
||||
|
||||
using (Transaction trans = new Transaction(doc))
|
||||
{
|
||||
trans.Start("布置梁");
|
||||
foreach (var beam in rbeams)
|
||||
{
|
||||
//var targetSymbolName = beam.Name.Substring(beam.Name.IndexOf('@') + 1);
|
||||
var targetSymbolName = beam.SectionB + " x " + beam.SectionH + "mm";
|
||||
var symbolIds = family.GetFamilySymbolIds();
|
||||
var symbols = from symbolid in symbolIds
|
||||
where doc.GetElement(symbolid).Name == targetSymbolName
|
||||
select doc.GetElement(symbolid) as FamilySymbol;
|
||||
//string symbolname = String.Format("{0}{1}{2}mm", beam.SectionB, "x", beam.SectionH);
|
||||
if (symbols.Count() == 0)
|
||||
{
|
||||
targetBeamSymbol = defaultfamilysymbol.Duplicate(targetSymbolName) as FamilySymbol;
|
||||
targetBeamSymbol.GetParameters("b").FirstOrDefault().SetValueString(beam.SectionB.ToString());
|
||||
targetBeamSymbol.GetParameters("h").FirstOrDefault().SetValueString(beam.SectionH.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
targetBeamSymbol = symbols.FirstOrDefault();
|
||||
}
|
||||
|
||||
Autodesk.Revit.DB.Line line = Autodesk.Revit.DB.Line.CreateBound(beam.rOrigin, beam.rEndPoint);
|
||||
|
||||
if (!targetBeamSymbol.IsActive)
|
||||
targetBeamSymbol.Activate();
|
||||
FamilyInstance fi = doc.Create.NewFamilyInstance(line, targetBeamSymbol, level, StructuralType.Beam);
|
||||
//原点=2,左=0,中心=1,右=3
|
||||
fi.get_Parameter(BuiltInParameter.Y_JUSTIFICATION).Set(2);
|
||||
fi.get_Parameter(BuiltInParameter.Z_JUSTIFICATION).Set(2);
|
||||
}
|
||||
trans.Commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
140
CDMUtil/Utility/ColumnUtil.cs
Normal file
140
CDMUtil/Utility/ColumnUtil.cs
Normal file
@@ -0,0 +1,140 @@
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.UI;
|
||||
using CDM.Interop.Revit.CDMComponent;
|
||||
using CDM.Interop.Revit.RevitCompoent;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CDM.Interop.Revit.Utility
|
||||
{
|
||||
class ColumnUtil : Utility
|
||||
{
|
||||
|
||||
public static List<CDMColumn> GetColumnCDM(Document doc, IList<Element> levels)
|
||||
{
|
||||
List<CDMColumn> cdmColumns = new List<CDMColumn>();
|
||||
var columns = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_StructuralColumns).OfClass(typeof(FamilyInstance)).ToElements();
|
||||
//得到标高+编码
|
||||
Dictionary<ElementId, string> dictLevelId_LevelCodes = GetDictLevelId_LevelCodes(doc);
|
||||
//柱子类型ID+赋予序号
|
||||
Dictionary<ElementId, string> dictColumnTypeId_TypeCodes = new Dictionary<ElementId, string>();
|
||||
int num = 1;
|
||||
for (int i = 0; i < columns.Count; i++)
|
||||
{
|
||||
ElementId columntypeId = columns[i].GetTypeId();
|
||||
try
|
||||
{
|
||||
dictColumnTypeId_TypeCodes.Add(columntypeId, string.Format("00{0}", num));
|
||||
num += 1;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (FamilyInstance column in columns)
|
||||
{
|
||||
//View3D v = (View3D)uidoc.ActiveView;
|
||||
//if (v == null)
|
||||
//{
|
||||
// var vi = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Views).OfClass(typeof(View3D)).FirstOrDefault() as View3D;
|
||||
// uidoc.ActiveView = vi;
|
||||
//}
|
||||
CDMColumn cdmcolumn = new CDMColumn(column);
|
||||
////通过out,将获取到的值复制给cdm的类型id,out参数必须在函数内初始化值
|
||||
dictColumnTypeId_TypeCodes.TryGetValue(cdmcolumn.SymbolId, out cdmcolumn.CategoryCode);
|
||||
dictLevelId_LevelCodes.TryGetValue(cdmcolumn.LevelId, out cdmcolumn.LevelCode);
|
||||
cdmColumns.Add(cdmcolumn);
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < levels.Count(); i++)
|
||||
{
|
||||
for (int j = 0; j < dictColumnTypeId_TypeCodes.Count; j++)
|
||||
{
|
||||
ElementId id = dictColumnTypeId_TypeCodes.ElementAt(j).Key;
|
||||
//归类cdm中同标高同类型
|
||||
IEnumerable<CDMColumn> targetcdm = from c in cdmColumns
|
||||
where c.LevelId.Equals(levels[i].Id) && c.SymbolId.Equals(id)
|
||||
select c;
|
||||
List<CDMColumn> CdmColumnsordered = targetcdm.OrderByDescending(p => p.Yw).ThenBy(p => p.Xl).ToList();
|
||||
//排序
|
||||
for (int k = 0; k < CdmColumnsordered.Count; k++)
|
||||
{
|
||||
if (k > 8)
|
||||
{
|
||||
if (k > 98)
|
||||
{
|
||||
CdmColumnsordered[k].LevelComponentCode = string.Format("{0}", k + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
CdmColumnsordered[k].LevelComponentCode = string.Format("0{0}", k + 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CdmColumnsordered[k].LevelComponentCode = string.Format("00{0}", k + 1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return cdmColumns;
|
||||
}
|
||||
public static void PlaceColumns(Document doc, Family family, List<RevitColumn> columns, Level level)
|
||||
{
|
||||
|
||||
using (Transaction trans = new Transaction(doc, "布置柱"))
|
||||
{
|
||||
|
||||
trans.Start();
|
||||
|
||||
//用于复制创建新类型
|
||||
FamilySymbol defaultfamilysymbol = doc.GetElement(family.GetFamilySymbolIds().FirstOrDefault()) as FamilySymbol;
|
||||
FamilySymbol targetColumnSymbol = null;
|
||||
foreach (var column in columns)
|
||||
{
|
||||
//var targetSymbolName = column.Name.Substring(column.Name.IndexOf('@') + 1);
|
||||
var targetSymbolName = column.SectionB + "x" + column.SectionH + " mm";
|
||||
var symbolIds = family.GetFamilySymbolIds();
|
||||
var symbols = from symbolid in symbolIds
|
||||
where doc.GetElement(symbolid).Name == targetSymbolName
|
||||
select doc.GetElement(symbolid) as FamilySymbol;
|
||||
|
||||
//不存在则创建并布置,存在则激活布置
|
||||
if (symbols.Count() == 0)
|
||||
{
|
||||
targetColumnSymbol = defaultfamilysymbol.Duplicate(targetSymbolName) as FamilySymbol;
|
||||
targetColumnSymbol.GetParameters("b").FirstOrDefault().SetValueString(column.SectionB.ToString());
|
||||
targetColumnSymbol.GetParameters("h").FirstOrDefault().SetValueString(column.SectionH.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
targetColumnSymbol = symbols.FirstOrDefault();
|
||||
}
|
||||
|
||||
|
||||
if (!targetColumnSymbol.IsActive)
|
||||
targetColumnSymbol.Activate();//设为Activate状态
|
||||
|
||||
FamilyInstance fi = doc.Create.NewFamilyInstance(column.rOrigin, targetColumnSymbol, level, Autodesk.Revit.DB.Structure.StructuralType.Column);
|
||||
//Parameter p = fi.get_Parameter(BuiltInParameter.FAMILY_BASE_LEVEL_PARAM);
|
||||
//Parameter p1 = fi.get_Parameter(BuiltInParameter.FAMILY_TOP_LEVEL_PARAM);
|
||||
//Parameter p2 = fi.get_Parameter(BuiltInParameter.FAMILY_BASE_LEVEL_OFFSET_PARAM);
|
||||
//Parameter p3 = fi.get_Parameter(BuiltInParameter.FAMILY_TOP_LEVEL_OFFSET_PARAM);
|
||||
fi.get_Parameter(BuiltInParameter.FAMILY_BASE_LEVEL_PARAM).Set(level.Id);
|
||||
fi.get_Parameter(BuiltInParameter.FAMILY_TOP_LEVEL_PARAM).Set(level.Id);
|
||||
fi.get_Parameter(BuiltInParameter.FAMILY_BASE_LEVEL_OFFSET_PARAM).Set(column.BaseOffest / 304.8);
|
||||
fi.get_Parameter(BuiltInParameter.FAMILY_TOP_LEVEL_OFFSET_PARAM).Set(column.TopOffest / 304.8);
|
||||
}
|
||||
trans.Commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
175
CDMUtil/Utility/FloorUtil.cs
Normal file
175
CDMUtil/Utility/FloorUtil.cs
Normal file
@@ -0,0 +1,175 @@
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.UI;
|
||||
using CDM.Interop.Revit.CDMComponent;
|
||||
using CDM.Interop.Revit.RevitCompoent;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace CDM.Interop.Revit.Utility
|
||||
{
|
||||
class FloorUtil : Utility
|
||||
{
|
||||
public static List<CDMFloor> GetFloorsCDM(Document doc, IList<Element> levels, View3D v3d)
|
||||
{
|
||||
List<CDMFloor> cdmFloors = new List<CDMFloor>();
|
||||
var floors = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Floors).OfClass(typeof(Floor)).ToElements();
|
||||
//楼板类型及编号
|
||||
Dictionary<ElementId, string> dicFloors = new Dictionary<ElementId, string>();
|
||||
Dictionary<ElementId, string> dictLevelId_LevelCodes = GetDictLevelId_LevelCodes(doc);
|
||||
int num = 1;
|
||||
for (int i = 0; i < floors.Count; i++)
|
||||
{
|
||||
ElementId floortypeId = floors[i].GetTypeId();
|
||||
try
|
||||
{
|
||||
dicFloors.Add(floortypeId, string.Format("00{0}", num));
|
||||
num += 1;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (Floor floor in floors)
|
||||
{
|
||||
CDMFloor cdmfloor = new CDMFloor(doc, floor, v3d);
|
||||
|
||||
////通过out,将获取到的值复制给cdm的类型id,out参数必须在函数内初始化值
|
||||
dicFloors.TryGetValue(floor.FloorType.Id, out cdmfloor.CategoryCode);
|
||||
dictLevelId_LevelCodes.TryGetValue(cdmfloor.LevelId, out cdmfloor.LevelCode);
|
||||
cdmFloors.Add(cdmfloor);
|
||||
}
|
||||
|
||||
for (int i = 0; i < levels.Count(); i++)
|
||||
{
|
||||
for (int j = 0; j < dicFloors.Count; j++)
|
||||
{
|
||||
ElementId id = dicFloors.ElementAt(j).Key;
|
||||
//归类cdm中同标高同类型
|
||||
IEnumerable<CDMFloor> targetcdm = from d in cdmFloors
|
||||
where d.LevelId.Equals(levels[i].Id) && d.SymbolId.Equals(id)
|
||||
select d;
|
||||
//排序
|
||||
//var li = targetcdm.ToList();
|
||||
List<CDMFloor> li = targetcdm.OrderByDescending(p => p.Yw).ThenBy(p => p.Xl).ToList();
|
||||
for (int k = 0; k < li.Count; k++)
|
||||
{
|
||||
if (k > 8)
|
||||
{
|
||||
if (k > 98)
|
||||
{
|
||||
li[k].LevelComponentCode = string.Format("{0}", k + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
li[k].LevelComponentCode = string.Format("0{0}", k + 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
li[k].LevelComponentCode = string.Format("00{0}", k + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return cdmFloors;
|
||||
}
|
||||
private static CurveArray SetBoundary(XYZ rOrigin, double length, double width)
|
||||
{
|
||||
XYZ p1 = new XYZ(rOrigin.X, rOrigin.Y - width / 2, 0);
|
||||
XYZ p2 = new XYZ(rOrigin.X, rOrigin.Y + width / 2, 0);
|
||||
XYZ p3 = new XYZ(rOrigin.X + length, rOrigin.Y + width / 2, 0);
|
||||
XYZ p4 = new XYZ(rOrigin.X + length, rOrigin.Y - width / 2, 0);
|
||||
Autodesk.Revit.DB.Line line1 = Autodesk.Revit.DB.Line.CreateBound(p1, p2);
|
||||
Autodesk.Revit.DB.Line line2 = Autodesk.Revit.DB.Line.CreateBound(p2, p3);
|
||||
Autodesk.Revit.DB.Line line3 = Autodesk.Revit.DB.Line.CreateBound(p3, p4);
|
||||
Autodesk.Revit.DB.Line line4 = Autodesk.Revit.DB.Line.CreateBound(p4, p1);
|
||||
CurveArray lines = new CurveArray();
|
||||
lines.Append(line1);
|
||||
lines.Append(line2);
|
||||
lines.Append(line3);
|
||||
lines.Append(line4);
|
||||
return lines;
|
||||
}
|
||||
public static void PlaceFloors(Document doc, List<RevitFloor> rfloors, Level level)
|
||||
{
|
||||
if (rfloors == null || level == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var fts = new FilteredElementCollector(doc).OfClass(typeof(FloorType));
|
||||
|
||||
FloorType defft = new FilteredElementCollector(doc).OfClass(typeof(FloorType)).FirstOrDefault() as FloorType;
|
||||
var floorTypesCol = new FilteredElementCollector(doc).OfClass(typeof(FloorType));
|
||||
FloorType targetFloorType = null;
|
||||
using (Transaction trans = new Transaction(doc, "布置板"))
|
||||
{
|
||||
trans.Start();
|
||||
foreach (RevitFloor rfloor in rfloors)
|
||||
{
|
||||
Floor fl = null;
|
||||
|
||||
//var targetFloorName = rfloor.Name.Substring(rfloor.Name.IndexOf('@') + 1);
|
||||
var targetFloorName = rfloor.Thickness + "mm";
|
||||
var floorTypes = from f in floorTypesCol
|
||||
where f.Name == targetFloorName
|
||||
select f as FloorType;
|
||||
if (floorTypes.Count() == 0)
|
||||
{
|
||||
targetFloorType = defft.Duplicate(targetFloorName) as FloorType;
|
||||
CompoundStructure compound = targetFloorType.GetCompoundStructure();
|
||||
compound.SetLayerWidth(0, rfloor.Thickness / 304.8);
|
||||
targetFloorType.SetCompoundStructure(compound);
|
||||
}
|
||||
else
|
||||
{
|
||||
targetFloorType = floorTypes.FirstOrDefault();
|
||||
}
|
||||
|
||||
var arr = SetBoundary(rfloor.rOrigin, rfloor.Length / 304.8, rfloor.Width / 304.8);
|
||||
|
||||
fl = doc.Create.NewFloor(arr, targetFloorType, level, true);
|
||||
fl.get_Parameter(BuiltInParameter.FLOOR_HEIGHTABOVELEVEL_PARAM).Set(rfloor.Offest / 304.8);
|
||||
|
||||
doc.Regenerate();//设置完偏移量参数刷新
|
||||
|
||||
CreateOpenings(doc, fl, rfloor.Openings);
|
||||
}
|
||||
trans.Commit();
|
||||
}
|
||||
}
|
||||
public static void CreateOpenings(Document doc, Floor floor, List<RevitOpening> ropenings)
|
||||
{
|
||||
foreach (var opening in ropenings)
|
||||
{
|
||||
try
|
||||
{
|
||||
XYZ p1 = new XYZ(opening.rOrigin.X, opening.rOrigin.Y - opening.Width / 304.8 / 2, opening.rOrigin.Z);
|
||||
XYZ p2 = new XYZ(opening.rOrigin.X, opening.rOrigin.Y + opening.Width / 304.8 / 2, opening.rOrigin.Z);
|
||||
XYZ p3 = new XYZ(opening.rOrigin.X + opening.Length / 304.8, opening.rOrigin.Y + opening.Width / 304.8 / 2, opening.rOrigin.Z);
|
||||
XYZ p4 = new XYZ(opening.rOrigin.X + opening.Length / 304.8, opening.rOrigin.Y - opening.Width / 304.8 / 2, opening.rOrigin.Z);
|
||||
CurveArray curves = new CurveArray();
|
||||
|
||||
Line l1 = Line.CreateBound(p1, p2);
|
||||
Line l2 = Line.CreateBound(p2, p3);
|
||||
Line l3 = Line.CreateBound(p3, p4);
|
||||
Line l4 = Line.CreateBound(p4, p1);
|
||||
|
||||
curves.Append(l1);
|
||||
curves.Append(l2);
|
||||
curves.Append(l3);
|
||||
curves.Append(l4);
|
||||
|
||||
doc.Create.NewOpening(floor, curves, true);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
319
CDMUtil/Utility/StairsUtil.cs
Normal file
319
CDMUtil/Utility/StairsUtil.cs
Normal file
@@ -0,0 +1,319 @@
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.DB.Architecture;
|
||||
using CDM.Interop.Revit.CDMComponent;
|
||||
using CDM.Interop.Revit.RevitCompoent;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace CDM.Interop.Revit.Utility
|
||||
{
|
||||
class StairsUtil : Utility
|
||||
{
|
||||
public static List<CDMStairs> GetStairsCDM(Document doc, IList<Element> levels, View3D v3d)
|
||||
{
|
||||
List<CDMStairs> cdmStairs = new List<CDMStairs>();
|
||||
var stairsLi = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Stairs).OfClass(typeof(Stairs)).ToElements();
|
||||
//楼板类型及编号
|
||||
Dictionary<ElementId, string> dicStairs = new Dictionary<ElementId, string>();
|
||||
Dictionary<ElementId, string> dictLevelId_LevelCodes = GetDictLevelId_LevelCodes(doc);
|
||||
int num = 1;
|
||||
for (int i = 0; i < stairsLi.Count; i++)
|
||||
{
|
||||
ElementId stairstypeId = stairsLi[i].GetTypeId();
|
||||
try
|
||||
{
|
||||
dicStairs.Add(stairstypeId, string.Format("00{0}", num));
|
||||
num += 1;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (Stairs stair in stairsLi)
|
||||
{
|
||||
CDMStairs cdmStair = new CDMStairs(doc, v3d, stair);
|
||||
|
||||
////通过out,将获取到的值复制给cdm的类型id,out参数必须在函数内初始化值
|
||||
dicStairs.TryGetValue(stair.GetTypeId(), out cdmStair.CategoryCode);
|
||||
dictLevelId_LevelCodes.TryGetValue(cdmStair.LevelId, out cdmStair.LevelCode);
|
||||
cdmStairs.Add(cdmStair);
|
||||
}
|
||||
|
||||
for (int i = 0; i < levels.Count(); i++)
|
||||
{
|
||||
for (int j = 0; j < dicStairs.Count; j++)
|
||||
{
|
||||
ElementId id = dicStairs.ElementAt(j).Key;
|
||||
//归类cdm中同标高同类型
|
||||
IEnumerable<CDMStairs> targetcdm = from d in cdmStairs
|
||||
where d.LevelId.Equals(levels[i].Id) && d.SymbolId.Equals(id)
|
||||
select d;
|
||||
//排序
|
||||
//var li = targetcdm.ToList();
|
||||
List<CDMStairs> li = targetcdm.OrderByDescending(p => p.Yw).ThenBy(p => p.Xl).ToList();
|
||||
for (int k = 0; k < li.Count; k++)
|
||||
{
|
||||
if (k > 8)
|
||||
{
|
||||
if (k > 98)
|
||||
{
|
||||
li[k].LevelComponentCode = string.Format("{0}", k + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
li[k].LevelComponentCode = string.Format("0{0}", k + 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
li[k].LevelComponentCode = string.Format("00{0}", k + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return cdmStairs;
|
||||
}
|
||||
|
||||
public static void PlaceStairs(Document doc, List<RevitStairs> rstairs, Level level)
|
||||
{
|
||||
FilteredElementCollector levelcol = new FilteredElementCollector(doc).OfClass(typeof(Level));
|
||||
Level leveltop = null;
|
||||
foreach (Level l in levelcol.Cast<Level>().Where<Level>(l => l.ProjectElevation > 0))
|
||||
{
|
||||
if (l.ProjectElevation > 0)
|
||||
{
|
||||
leveltop = l;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (rstairs == null || level == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
//CreateSampleStairs(doc, level, leveltop);
|
||||
|
||||
CreateStairs(doc, rstairs, level, leveltop);
|
||||
}
|
||||
private static void CreateStairs(Document doc, List<RevitStairs> rstairses, Level levelBottom, Level levelTop)
|
||||
{
|
||||
using (TransactionGroup transG = new TransactionGroup(doc, "创建楼梯"))
|
||||
{
|
||||
transG.Start();
|
||||
foreach (var rstairs in rstairses)
|
||||
{
|
||||
using (StairsEditScope newStairsScope = new StairsEditScope(doc, "新建楼梯"))
|
||||
{
|
||||
ElementId stairsId = newStairsScope.Start(levelBottom.Id, levelTop.Id);
|
||||
var stairs = doc.GetElement(stairsId) as Stairs;
|
||||
var typeid = doc.GetElement(stairsId).GetTypeId();
|
||||
var stairsType = doc.GetElement(typeid) as StairsType;
|
||||
using (Transaction stairsTrans = new Transaction(doc, "添加梯段和平台到楼梯"))
|
||||
{
|
||||
stairsTrans.Start();
|
||||
stairs.get_Parameter(BuiltInParameter.STAIRS_BASE_LEVEL_PARAM).Set(levelBottom.Id);
|
||||
stairs.get_Parameter(BuiltInParameter.STAIRS_TOP_LEVEL_PARAM).Set(levelBottom.Id);
|
||||
stairs.get_Parameter(BuiltInParameter.STAIRS_BASE_OFFSET).Set(rstairs.BaseElevation);
|
||||
stairs.get_Parameter(BuiltInParameter.STAIRS_TOP_OFFSET).Set(rstairs.TopElevation);
|
||||
if (stairsType.get_Parameter(BuiltInParameter.STAIRS_ATTR_MINIMUM_TREAD_DEPTH).AsDouble() > rstairs.ThreadDepth)
|
||||
{
|
||||
stairsType.get_Parameter(BuiltInParameter.STAIRS_ATTR_MINIMUM_TREAD_DEPTH).Set(rstairs.ThreadDepth);
|
||||
}
|
||||
|
||||
stairs.get_Parameter(BuiltInParameter.STAIRS_ACTUAL_TREAD_DEPTH).Set(rstairs.ThreadDepth);
|
||||
stairs.get_Parameter(BuiltInParameter.STAIRS_DESIRED_NUMBER_OF_RISERS).Set(rstairs.GetNumberOfRisers(rstairs.Runs));
|
||||
doc.GetElement(stairsType.RunType).get_Parameter(BuiltInParameter.STAIRS_RUNTYPE_STRUCTURAL_DEPTH).Set(rstairs.Runs[0].Thickness / 304.8);
|
||||
doc.GetElement(stairsType.LandingType).get_Parameter(BuiltInParameter.STAIRS_LANDINGTYPE_THICKNESS).Set(rstairs.Landing.Thickness / 304.8);
|
||||
#region 草图楼梯
|
||||
StairsRun run1 = CreateStairsSketchedRun(doc, rstairs.Runs[0], rstairs.Runs[0].RelativeBaseElevation / 304.8, stairsId);
|
||||
//run1.BaseElevation = rstairs.Runs[0].BaseElevation;
|
||||
//run1.TopElevation = rstairs.Runs[0].TopELevation;
|
||||
|
||||
|
||||
StairsRun run2 = CreateStairsSketchedRun(doc, rstairs.Runs[1], rstairs.Runs[1].RelativeBaseElevation / 304.8, stairsId);
|
||||
//run2.BaseElevation = rstairs.Runs[1].BaseElevation;
|
||||
//run2.TopElevation = rstairs.Runs[1].TopELevation;
|
||||
StairsLanding newLanding = StairsLanding.CreateSketchedLanding(doc, stairsId, rstairs.Landing.GetCurves(), rstairs.Landing.RelativeElevation / 304.8);
|
||||
|
||||
//newLanding.BaseElevation = rstairs.Landing.Elevation / 304.8;
|
||||
#endregion
|
||||
|
||||
#region 备用
|
||||
//StairsRun newRun1 = StairsRun.CreateStraightRun(doc, stairsId, rstairs.Runs[0].LocationLine, StairsRunJustification.Center);
|
||||
//newRun1.ActualRunWidth = rstairs.Runs[0].Width / 304.8;
|
||||
//newRun1.TopElevation = rstairs.Runs[0].RelativeTopELevation / 304.8;
|
||||
//newRun1.BaseElevation = rstairs.Runs[0].RelativeBaseElevation / 304.8;
|
||||
|
||||
|
||||
//StairsRun newRun2 = StairsRun.CreateStraightRun(doc, stairsId, rstairs.Runs[1].LocationLine, StairsRunJustification.Center);
|
||||
//newRun2.ActualRunWidth = rstairs.Runs[1].Width / 304.8;
|
||||
//newRun2.TopElevation = rstairs.Runs[1].RelativeTopELevation / 304.8;
|
||||
//newRun2.BaseElevation = rstairs.Runs[1].RelativeBaseElevation / 304.8;
|
||||
|
||||
//添加休息平台
|
||||
|
||||
//LinkElementId stairsLinkId = new LinkElementId(stairsId);
|
||||
//ICollection<ElementId> stairsPathIds =new FilteredElementCollector(doc).OfClass(typeof(StairsPathType)).ToElementIds();
|
||||
//var plan = new FilteredElementCollector(doc).OfClass(typeof(ViewPlan)).Cast<ViewPlan>().Where<ViewPlan>(v => v.GenLevel.ProjectElevation == 0).FirstOrDefault();
|
||||
//StairsPath.Create(doc, stairsLinkId, typeid, plan.Id);
|
||||
#endregion
|
||||
|
||||
stairsTrans.Commit();
|
||||
|
||||
}
|
||||
// 编辑模式提交的时产生的错误处理
|
||||
newStairsScope.Commit(new StairsFailurePreprocessor());
|
||||
}
|
||||
}
|
||||
using(Transaction trans=new Transaction(doc, "删除栏杆"))
|
||||
{
|
||||
trans.Start();
|
||||
var ids = new FilteredElementCollector(doc).OfClass(typeof(Railing)).ToElementIds();
|
||||
foreach (var id in ids)
|
||||
{
|
||||
doc.Delete(id);
|
||||
}
|
||||
trans.Commit();
|
||||
}
|
||||
transG.Assimilate();
|
||||
}
|
||||
}
|
||||
private static StairsRun CreateStairsSketchedRun(Document doc, RevitStairsRun rstairsrun, double levelBottom, ElementId stairsId)
|
||||
{
|
||||
IList<Curve> bdryCurves = new List<Curve>();
|
||||
IList<Curve> riserCurves = new List<Curve>();
|
||||
|
||||
IList<Curve> pathCurves = new List<Curve>();
|
||||
|
||||
Line locationline = rstairsrun.LocationLine;
|
||||
Line l1 = locationline.CreateOffset(rstairsrun.Width / 2 / 304.8, new XYZ(0, 0, 1)) as Line;
|
||||
Line l2 = locationline.CreateOffset(-rstairsrun.Width / 2 / 304.8, new XYZ(0, 0, 1)) as Line;
|
||||
// boundaries
|
||||
bdryCurves.Add(l1);
|
||||
bdryCurves.Add(l2);
|
||||
|
||||
// riser curves
|
||||
int riserNum = rstairsrun.NumberOfRisers - 1;
|
||||
for (int ii = 0; ii <= riserNum; ii++)
|
||||
{
|
||||
XYZ end0 = l1.Evaluate(ii / (double)riserNum, true);
|
||||
XYZ end1 = l2.Evaluate(ii / (double)riserNum, true);
|
||||
//XYZ end0 = (l1.GetEndPoint(0) + l1.GetEndPoint(1)) * ii / (double)riserNum;
|
||||
//XYZ end1 = (l2.GetEndPoint(0) + l2.GetEndPoint(1)) * ii / (double)riserNum;
|
||||
//XYZ end2 = new XYZ(end1.X, 10, 0);
|
||||
riserCurves.Add(Line.CreateBound(end0, end1));
|
||||
}
|
||||
|
||||
//stairs path curves
|
||||
pathCurves.Add(locationline);
|
||||
|
||||
StairsRun newRun = StairsRun.CreateSketchedRun(doc, stairsId, levelBottom, bdryCurves, riserCurves, pathCurves);
|
||||
|
||||
return newRun;
|
||||
}
|
||||
private static ElementId CreateSampleStairs(Document document, Level levelBottom, Level levelTop)
|
||||
{
|
||||
ElementId newStairsId = null;
|
||||
|
||||
using (StairsEditScope newStairsScope = new StairsEditScope(document, "New Stairs"))
|
||||
{
|
||||
newStairsId = newStairsScope.Start(levelBottom.Id, levelTop.Id);
|
||||
|
||||
using (Transaction stairsTrans = new Transaction(document, "Add Runs and Landings to Stairs"))
|
||||
{
|
||||
stairsTrans.Start();
|
||||
|
||||
// Create a sketched run for the stairs
|
||||
IList<Curve> bdryCurves = new List<Curve>();
|
||||
IList<Curve> riserCurves = new List<Curve>();
|
||||
IList<Curve> pathCurves = new List<Curve>();
|
||||
XYZ pnt1 = new XYZ(0, 0, 0);
|
||||
XYZ pnt2 = new XYZ(15, 0, 0);
|
||||
XYZ pnt3 = new XYZ(0, 10, 0);
|
||||
XYZ pnt4 = new XYZ(15, 10, 0);
|
||||
|
||||
// boundaries
|
||||
bdryCurves.Add(Line.CreateBound(pnt1, pnt2));
|
||||
bdryCurves.Add(Line.CreateBound(pnt3, pnt4));
|
||||
|
||||
// riser curves
|
||||
const int riserNum = 20;
|
||||
for (int ii = 0; ii <= riserNum; ii++)
|
||||
{
|
||||
XYZ end0 = (pnt1 + pnt2) * ii / (double)riserNum;
|
||||
XYZ end1 = (pnt3 + pnt4) * ii / (double)riserNum;
|
||||
XYZ end2 = new XYZ(end1.X, 10, 0);
|
||||
riserCurves.Add(Line.CreateBound(end0, end2));
|
||||
}
|
||||
|
||||
//stairs path curves
|
||||
XYZ pathEnd0 = (pnt1 + pnt3) / 2.0;
|
||||
XYZ pathEnd1 = (pnt2 + pnt4) / 2.0;
|
||||
pathCurves.Add(Line.CreateBound(pathEnd0, pathEnd1));
|
||||
|
||||
StairsRun newRun1 = StairsRun.CreateSketchedRun(document, newStairsId, levelBottom.Elevation, bdryCurves, riserCurves, pathCurves);
|
||||
|
||||
// Add a straight run
|
||||
Line locationLine = Line.CreateBound(new XYZ(20, -5, newRun1.TopElevation), new XYZ(35, -5, newRun1.TopElevation));
|
||||
StairsRun newRun2 = StairsRun.CreateStraightRun(document, newStairsId, locationLine, StairsRunJustification.Center);
|
||||
newRun2.ActualRunWidth = 10;
|
||||
|
||||
// Add a landing between the runs
|
||||
CurveLoop landingLoop = new CurveLoop();
|
||||
XYZ p1 = new XYZ(15, 10, 0);
|
||||
XYZ p2 = new XYZ(20, 10, 0);
|
||||
XYZ p3 = new XYZ(20, -10, 0);
|
||||
XYZ p4 = new XYZ(15, -10, 0);
|
||||
Line curve_1 = Line.CreateBound(p1, p2);
|
||||
Line curve_2 = Line.CreateBound(p2, p3);
|
||||
Line curve_3 = Line.CreateBound(p3, p4);
|
||||
Line curve_4 = Line.CreateBound(p4, p1);
|
||||
|
||||
landingLoop.Append(curve_1);
|
||||
landingLoop.Append(curve_2);
|
||||
landingLoop.Append(curve_3);
|
||||
landingLoop.Append(curve_4);
|
||||
StairsLanding newLanding = StairsLanding.CreateSketchedLanding(document, newStairsId, landingLoop, newRun1.TopElevation);
|
||||
|
||||
stairsTrans.Commit();
|
||||
}
|
||||
// A failure preprocessor is to handle possible failures during the edit mode commitment process.
|
||||
newStairsScope.Commit(new StairsFailurePreprocessor());
|
||||
}
|
||||
|
||||
return newStairsId;
|
||||
}
|
||||
}
|
||||
|
||||
class StairsFailurePreprocessor : IFailuresPreprocessor
|
||||
{
|
||||
public FailureProcessingResult PreprocessFailures(FailuresAccessor failuresAccessor)
|
||||
{
|
||||
IList<FailureMessageAccessor> listFma = failuresAccessor.GetFailureMessages();
|
||||
if (listFma.Count == 0)
|
||||
return FailureProcessingResult.Continue;
|
||||
foreach (FailureMessageAccessor fma in listFma)
|
||||
{
|
||||
// 如果是错误,则尝试解决
|
||||
if (fma.GetSeverity() == FailureSeverity.Error)
|
||||
{
|
||||
// 模拟手动单击"删除连接"按钮
|
||||
if (fma.HasResolutions())
|
||||
failuresAccessor.ResolveFailure(fma);
|
||||
}
|
||||
// 如果是警告,则禁止弹框
|
||||
if (fma.GetSeverity() == FailureSeverity.Warning)
|
||||
{
|
||||
//failuresAccessor.DeleteAllWarnings();
|
||||
failuresAccessor.DeleteWarning(fma);
|
||||
}
|
||||
}
|
||||
return FailureProcessingResult.ProceedWithCommit;
|
||||
// Use default failure processing
|
||||
//return FailureProcessingResult.Continue;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
59
CDMUtil/Utility/Utility.cs
Normal file
59
CDMUtil/Utility/Utility.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using Autodesk.Revit.DB;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CDM.Interop.Revit.Utility
|
||||
{
|
||||
class Utility
|
||||
{
|
||||
public static Dictionary<ElementId, string> GetDictLevelId_LevelCodes(Document doc)
|
||||
{
|
||||
var levelCol = new FilteredElementCollector(doc).OfClass(typeof(Level)).Cast<Level>();
|
||||
var groundLevel = from l in levelCol
|
||||
where l.get_Parameter(BuiltInParameter.LEVEL_ELEV).AsDouble() >= 0
|
||||
select l;
|
||||
var undergroundLevel = from l in levelCol
|
||||
where l.get_Parameter(BuiltInParameter.LEVEL_ELEV).AsDouble() < 0
|
||||
select l;
|
||||
|
||||
var groundLevelOrdered = levelCol.OrderBy(l => l.ProjectElevation).ToList();
|
||||
var undergroundLevelOrdered = undergroundLevel.OrderByDescending(l => l.ProjectElevation).ToList();
|
||||
Dictionary<ElementId, string> LevelId_LevelCodes = new Dictionary<ElementId, string>();
|
||||
int groundLevelCode = 1;
|
||||
int undergroundLevelCode = 901;
|
||||
for (int i = 0; i < groundLevelOrdered.Count; i++)
|
||||
{
|
||||
ElementId levelid = groundLevelOrdered[i].Id;
|
||||
string str;
|
||||
if (groundLevelCode > 9)
|
||||
{
|
||||
if (groundLevelCode > 99)
|
||||
{
|
||||
str = string.Format("{0}", groundLevelCode);
|
||||
}
|
||||
else
|
||||
{
|
||||
str = string.Format("0{0}", groundLevelCode);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
str = string.Format("00{0}", groundLevelCode);
|
||||
}
|
||||
LevelId_LevelCodes.Add(levelid, str);
|
||||
groundLevelCode += 1;
|
||||
}
|
||||
for (int i = 0; i < undergroundLevelOrdered.Count; i++)
|
||||
{
|
||||
ElementId levelid = undergroundLevelOrdered[i].Id;
|
||||
|
||||
LevelId_LevelCodes.Add(levelid, string.Format("{0}", undergroundLevelCode));
|
||||
undergroundLevelCode += 1;
|
||||
}
|
||||
return LevelId_LevelCodes;
|
||||
}
|
||||
}
|
||||
}
|
||||
143
CDMUtil/Utility/WallUtil.cs
Normal file
143
CDMUtil/Utility/WallUtil.cs
Normal file
@@ -0,0 +1,143 @@
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.UI;
|
||||
using CDM.Interop.Revit.CDMComponent;
|
||||
using CDM.Interop.Revit.RevitCompoent;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CDM.Interop.Revit.Utility
|
||||
{
|
||||
class WallUtil : Utility
|
||||
{
|
||||
public static List<CDMWall> GetWallsCDM(UIDocument uidoc, IList<Element> levels)
|
||||
{
|
||||
List<CDMWall> cdmWalls = new List<CDMWall>();
|
||||
Document doc = uidoc.Document;
|
||||
var walls = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).OfClass(typeof(Wall)).ToElements();
|
||||
//楼板类型及编号
|
||||
Dictionary<ElementId, string> dicWalls = new Dictionary<ElementId, string>();
|
||||
int num1 = 1;
|
||||
for (int i = 0; i < walls.Count; i++)
|
||||
{
|
||||
ElementId flId = walls[i].GetTypeId();
|
||||
try
|
||||
{
|
||||
dicWalls.Add(flId, string.Format("0{0}", num1));
|
||||
num1 += 1;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (Wall wall in walls)
|
||||
{
|
||||
View3D v = (View3D)uidoc.ActiveView;
|
||||
if (v == null)
|
||||
{
|
||||
var vi = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Views).OfClass(typeof(View3D)).ToElements();
|
||||
uidoc.ActiveView = (View3D)vi.FirstOrDefault();
|
||||
}
|
||||
|
||||
//XYZ p = beam.GetTransform().Origin;
|
||||
XYZ s = ((LocationCurve)wall.Location).Curve.GetEndPoint(0);
|
||||
XYZ e = ((LocationCurve)wall.Location).Curve.GetEndPoint(1);
|
||||
|
||||
Level level = (Level)doc.GetElement(wall.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT).AsElementId());
|
||||
|
||||
CDMWall cdmwall = new CDMWall
|
||||
{
|
||||
self = wall,
|
||||
//AbsLevel= floor.get_Parameter(BuiltInParameter.STRUCTURAL_ELEVATION_AT_TOP).AsValueString()
|
||||
BaseLevel = (Level)doc.GetElement(wall.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT).AsElementId()),
|
||||
LevelCode = doc.GetElement(wall.LevelId).Name,
|
||||
SymbolId = wall.GetTypeId(),
|
||||
//CDMTypeId = HcdmType.CDMWall,
|
||||
Thickness = wall.WallType.get_Parameter(BuiltInParameter.WALL_ATTR_WIDTH_PARAM).AsValueString(),
|
||||
//Thickness=wall.Width.ToString(),
|
||||
BasePoint = s,
|
||||
ExtendPoint = e
|
||||
};
|
||||
////通过out,将获取到的值复制给cdm的类型id,out参数必须在函数内初始化值
|
||||
dicWalls.TryGetValue(cdmwall.SymbolId, out cdmwall.CategoryCode);
|
||||
cdmWalls.Add(cdmwall);
|
||||
}
|
||||
|
||||
for (int i = 0; i < levels.Count(); i++)
|
||||
{
|
||||
for (int j = 0; j < dicWalls.Count; j++)
|
||||
{
|
||||
ElementId id = dicWalls.ElementAt(j).Key;
|
||||
//归类cdm中同标高同类型
|
||||
IEnumerable<CDMWall> targetcdm = from b in cdmWalls
|
||||
where b.BaseLevel.Id.Equals(levels[i].Id) && b.SymbolId.Equals(id)
|
||||
select b;
|
||||
List<CDMWall> li = targetcdm.OrderByDescending(p => p.BasePoint.Y).ThenBy(p => p.BasePoint.X).ToList();
|
||||
//排序
|
||||
//var li = targetcdm.ToList();
|
||||
//List<CDMBeam> li = targetcdm.OrderByDescending(p => p.BasePoint.Y).ThenBy(p => p.BasePoint.X).ToList();
|
||||
|
||||
for (int k = 0; k < li.Count; k++)
|
||||
{
|
||||
if (k > 8)
|
||||
{
|
||||
if (k > 98)
|
||||
{
|
||||
li[k].LevelComponentCode = string.Format("{0}", k + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
li[k].LevelComponentCode = string.Format("0{0}", k + 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
li[k].LevelComponentCode = string.Format("00{0}", k + 1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return cdmWalls;
|
||||
}
|
||||
public static void PlaceWalls(Document doc, List<RevitWall> rwalls, Level level)
|
||||
{
|
||||
if (rwalls == null || level == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var wallTypes = new FilteredElementCollector(doc).OfClass(typeof(WallType)).ToElements();
|
||||
|
||||
using (Transaction trans = new Transaction(doc))
|
||||
{
|
||||
trans.Start("创建墙");
|
||||
foreach (var wall in rwalls)
|
||||
{
|
||||
foreach (WallType t in wallTypes)
|
||||
{
|
||||
if (t.Kind == WallKind.Basic)
|
||||
{
|
||||
string x = t.get_Parameter(BuiltInParameter.WALL_ATTR_WIDTH_PARAM).AsValueString();
|
||||
if (x == wall.Thickness)
|
||||
{
|
||||
//var l = wall.BasePoint - wall.ExtendPoint;
|
||||
Autodesk.Revit.DB.Line line = Autodesk.Revit.DB.Line.CreateBound(wall.BasePoint, wall.ExtendPoint);
|
||||
var levelelev = level.get_Parameter(BuiltInParameter.LEVEL_ELEV).AsValueString();
|
||||
Wall.Create(doc, line, t.Id, level.Id, wall.Height / 304.8, (Convert.ToDouble(wall.StrBaseElev) - Convert.ToDouble(levelelev)) / 304.8, false, false);
|
||||
//Wall.Create(doc, line, t.Id, level.Id, wall.Height / 304.8, Convert.ToDouble(wall.StrTopElev) / 304.8, false, false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
trans.Commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user