2070 lines
95 KiB
C#
2070 lines
95 KiB
C#
using Autodesk.Revit.DB;
|
|
using Autodesk.Revit.DB.Mechanical;
|
|
using Autodesk.Revit.DB.Plumbing;
|
|
using Autodesk.Revit.UI;
|
|
using Autodesk.Revit.UI.Selection;
|
|
using KDCS.Utils;
|
|
using KMBIM.Revit.Tools.LogicClass;
|
|
using KMBIM.Revit.Tools.Utils;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
namespace KMBIM.Revit.Tools.Cmd.Sleeve
|
|
{
|
|
[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 SleeveCommand : IExternalCommand
|
|
{
|
|
TblDataStorage PipeData = new TblDataStorage();
|
|
List<PipeType> pipeCollection = null;
|
|
List<DuctType> ductCollection = null;
|
|
List<PipeInsulationType> PipeinsulationCollection = null;
|
|
List<DuctInsulationType> DuctinsulationCollection = null;
|
|
TblInsulationType PipeinsulList = new TblInsulationType();
|
|
TblInsulationType DuctinsulList = new TblInsulationType();
|
|
|
|
|
|
List<Wall> m_walls = new List<Wall>(); // 선택한 벽을 저장한다.
|
|
List<Floor> m_floors = new List<Floor>(); // 선택한 바닥을 저장한다.
|
|
Hashtable rliRefFace = new Hashtable();
|
|
Document doc = null;
|
|
bool bKeepInsulation = false;
|
|
bool bApplyPipe = false;
|
|
bool bApplyDuct = false;
|
|
|
|
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
|
|
{
|
|
if (!WorkMain.GetInstance().IsValid) return Autodesk.Revit.UI.Result.Succeeded;
|
|
// The location of this command assembly
|
|
string currentCommandAssemblyLocation = System.Reflection.Assembly.GetExecutingAssembly().Location;
|
|
|
|
UIApplication uiapp = commandData.Application;
|
|
UIDocument uidoc = uiapp.ActiveUIDocument;
|
|
Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
|
|
doc = uidoc.Document;
|
|
Autodesk.Revit.DB.View view = doc.ActiveView;
|
|
Autodesk.Revit.Creation.Application creApp = uiapp.Application.Create;
|
|
Autodesk.Revit.Creation.Document creDoc = doc.Create;
|
|
|
|
|
|
PipeinsulationCollection
|
|
= new FilteredElementCollector(doc)
|
|
.OfClass(typeof(PipeInsulationType))
|
|
.OfType<PipeInsulationType>()
|
|
.ToList();
|
|
|
|
DuctinsulationCollection
|
|
= new FilteredElementCollector(doc)
|
|
.OfClass(typeof(DuctInsulationType))
|
|
.OfType<DuctInsulationType>()
|
|
.ToList();
|
|
|
|
// Looking for the DuctType
|
|
ductCollection =
|
|
new FilteredElementCollector(doc)
|
|
.OfClass(typeof(DuctType))
|
|
.OfType<DuctType>()
|
|
.ToList();
|
|
|
|
|
|
// Looking for the PipeType
|
|
pipeCollection =
|
|
new FilteredElementCollector(doc)
|
|
.OfClass(typeof(PipeType))
|
|
.OfType<PipeType>()
|
|
.ToList();
|
|
|
|
if (PipeinsulationCollection.Count() <= 0)
|
|
{
|
|
System.Windows.Forms.MessageBox.Show("파이프 보온재 타입이 없습니다. 하나이상 추가후 시도 하시기 바랍니다.");
|
|
return Result.Failed; ;
|
|
}
|
|
|
|
if (DuctinsulationCollection.Count() <= 0)
|
|
{
|
|
System.Windows.Forms.MessageBox.Show("덕트 보온재 타입이 없습니다. 하나이상 추가후 시도 하시기 바랍니다.");
|
|
return Result.Failed; ;
|
|
}
|
|
|
|
foreach (var row in PipeinsulationCollection)
|
|
{
|
|
PipeinsulList.Add(row.Name);
|
|
}
|
|
string strPipeinsul = string.Empty;
|
|
if (PipeinsulationCollection.Count > 0)
|
|
strPipeinsul = PipeinsulationCollection.First().Name;
|
|
|
|
foreach (var row in DuctinsulationCollection)
|
|
{
|
|
DuctinsulList.Add(row.Name);
|
|
}
|
|
string strDuctinsul = string.Empty;
|
|
if (DuctinsulationCollection.Count > 0)
|
|
strDuctinsul = DuctinsulationCollection.First().Name;
|
|
|
|
|
|
// ***********************************
|
|
// 패밀리 파일 해당 위치에 복사
|
|
// ***********************************
|
|
|
|
m_walls.Clear();
|
|
|
|
|
|
FamilyInstanceCreator crePipeSleeve = null;
|
|
FamilyInstanceCreator creDuctSleeveRect = null;
|
|
FamilyInstanceCreator creDuctSleeveRound = null;
|
|
FamilyInstanceCreator creDuctSleeveOval = null;
|
|
// Generic Annotation 패밀리 삽입
|
|
using (Transaction tx = new Transaction(doc))
|
|
{
|
|
string versionNumber = doc.Application.VersionNumber.ToString();
|
|
|
|
string location = Util.GetKMBIMLibraryFolder("Libraries\\Sleeve");
|
|
FileInfo fiPipeSleeve = new FileInfo(location + "\\" + versionNumber + "\\KMBIM - Pipe Sleeve.rfa");
|
|
FileInfo fiDuctSleeveRect = new FileInfo(location + "\\" + versionNumber + "\\KMBIM - Rectangular Duct Sleeve.rfa");
|
|
FileInfo fiDuctSleeveRound = new FileInfo(location + "\\" + versionNumber + "\\KMBIM - Round Duct Sleeve.rfa");
|
|
FileInfo fiDuctSleeveOval = new FileInfo(location + "\\" + versionNumber + "\\KMBIM - Oval Duct Sleeve.rfa");
|
|
|
|
tx.Start("Insert Sleeve Family");
|
|
|
|
crePipeSleeve = new FamilyInstanceCreator(uiapp);
|
|
crePipeSleeve.CheckFamilySymbol(fiPipeSleeve, "파이프 슬리브");
|
|
|
|
creDuctSleeveRect = new FamilyInstanceCreator(uiapp);
|
|
creDuctSleeveRect.CheckFamilySymbol(fiDuctSleeveRect, "직사각형 덕트 슬리브");
|
|
|
|
creDuctSleeveRound = new FamilyInstanceCreator(uiapp);
|
|
creDuctSleeveRound.CheckFamilySymbol(fiDuctSleeveRound, "원형 덕트 슬리브");
|
|
|
|
creDuctSleeveOval = new FamilyInstanceCreator(uiapp);
|
|
creDuctSleeveOval.CheckFamilySymbol(fiDuctSleeveOval, "타원형 덕트 슬리브");
|
|
|
|
tx.Commit();
|
|
}
|
|
|
|
|
|
//
|
|
string
|
|
sWall = "Wall",
|
|
sFloor = "Floor",
|
|
|
|
sPipe = "Pipe",
|
|
sRectDuct = "RectDuct",
|
|
sRoundDuct = "RoundDuct",
|
|
sOvalDuct = "OvalDuct";
|
|
|
|
double dRatio = 0.5;
|
|
|
|
|
|
string strInstallType = string.Empty;
|
|
|
|
/*
|
|
FilteredElementCollector collector = new FilteredElementCollector(doc);
|
|
ICollection<Element> elementsToSelect = collector.WherePasses(new LogicalOrFilter(
|
|
new ElementCategoryFilter(BuiltInCategory.OST_DuctCurves),
|
|
new ElementCategoryFilter(BuiltInCategory.OST_PipeCurves))).ToElements();
|
|
// 선택
|
|
List<Element> selectedElements = new List<Element>();
|
|
|
|
|
|
// select the elements
|
|
foreach (Element elem in elementsToSelect)
|
|
{
|
|
Reference reference = new Reference(elem);
|
|
selectedElements.Add(elem);
|
|
}
|
|
uidoc.Selection.SetElementIds(selectedElements.Select(e => e.Id).ToList());
|
|
*/
|
|
|
|
//pick the objects
|
|
var refs = uidoc.Selection.PickObjects(ObjectType.Element, new PipeDuctSelectionFilter(), "슬리브를 삽입할 배관 또는 덕트를 선택:");
|
|
|
|
List<Element> ielement = new List<Element>();
|
|
|
|
// process the selected objects
|
|
foreach (Reference r in refs)
|
|
{
|
|
Element elem = doc.GetElement(r.ElementId);
|
|
ielement.Add(elem);
|
|
// do something with the selected element
|
|
}
|
|
// var ielement = uidoc.Selection.PickElementsByRectangle("슬리브를 삽입할 배관 또는 덕트를 선택:"); ;
|
|
if (ielement == null) return Result.Failed;
|
|
|
|
|
|
List<string> lstString1 = new List<string>();
|
|
List<string> lstString2 = new List<string>();
|
|
|
|
//------------------------------------------------------------------------------------
|
|
// Wall/Floor - Duct(Rect, Round, Oval) / Pipe
|
|
List<Pipe> lstPipe = new List<Pipe>();
|
|
List<Duct> lstRectDuct = new List<Duct>();
|
|
List<Duct> lstRoundDuct = new List<Duct>();
|
|
List<Duct> lstOvalDuct = new List<Duct>();
|
|
List<FamilyInstance> lstFamilyInstance = new List<FamilyInstance>();
|
|
|
|
|
|
|
|
bool bPipe = false;
|
|
|
|
GetAllLinkedWallsAndFloors(doc);
|
|
|
|
if (m_walls.Count > 0) if (lstString2.Contains(sWall) == false) lstString2.Add(sWall);
|
|
if (m_floors.Count > 0) if (lstString2.Contains(sFloor) == false) lstString2.Add(sFloor);
|
|
|
|
|
|
|
|
foreach (Element e in ielement.ToList())
|
|
{
|
|
Type et = e.GetType();
|
|
|
|
if (typeof(RevitLinkInstance) == et)
|
|
{
|
|
//linkInstance = e as RevitLinkInstance;
|
|
continue;
|
|
}
|
|
|
|
|
|
if (e is Pipe)
|
|
{
|
|
List<Face> lstFace = Util.GetFaces(e).ToList();
|
|
lstPipe.Add(e as Pipe); // 파이프
|
|
if (bPipe == false)
|
|
{
|
|
if (lstString1.Contains(sPipe) == false) lstString1.Add(sPipe);
|
|
bPipe = true;
|
|
}
|
|
|
|
}
|
|
else if (e is FamilyInstance)
|
|
{
|
|
FamilyInstance familyInstance = e as FamilyInstance;
|
|
lstFamilyInstance.Add(familyInstance); //조인트 부속 등등
|
|
}
|
|
else if (e is Duct)
|
|
{
|
|
|
|
Duct duct = e as Duct;
|
|
|
|
// 원형,각형,타원 구분
|
|
double dblDia = 0d;
|
|
double dblWidth = 0d;
|
|
double dblHeight = 0d;
|
|
ConnectorProfileType shape = Util.GetShape(duct);
|
|
if (shape == ConnectorProfileType.Round)
|
|
{
|
|
dblDia = duct.Diameter;
|
|
lstRoundDuct.Add(duct); // 원형덕트
|
|
if (lstString1.Contains(sRoundDuct) == false) lstString1.Add(sRoundDuct);
|
|
}
|
|
else if (shape == ConnectorProfileType.Rectangular)
|
|
{
|
|
|
|
dblWidth = duct.Width;
|
|
dblHeight = duct.Height;
|
|
lstRectDuct.Add(duct); // 사각덕트
|
|
if (lstString1.Contains(sRectDuct) == false) lstString1.Add(sRectDuct);
|
|
}
|
|
else if (shape == ConnectorProfileType.Oval)
|
|
{
|
|
lstOvalDuct.Add(duct); // 타원덕트
|
|
if (lstString1.Contains(sOvalDuct) == false) lstString1.Add(sOvalDuct);
|
|
}
|
|
}//end-if
|
|
|
|
}//end-foreach
|
|
|
|
|
|
open();
|
|
if (PipeData.m_table.Count > 0)
|
|
{
|
|
List<DataStorage> delPipeData = new List<DataStorage>();
|
|
List<DataStorage> delDuctData = new List<DataStorage>();
|
|
//현재 프로젝트에는 없는데 저장된 파일에는 있는것을 삭제 하자.
|
|
foreach (var categories in PipeData.GetTable())
|
|
{
|
|
foreach (var row in categories.Value["pipe"])
|
|
{
|
|
//subcategory.Key
|
|
if (pipeCollection.Find(x => x.Name == row.strType) == null)
|
|
{
|
|
if (delPipeData.Find(z => z.strType == row.strType) == null)
|
|
delPipeData.Add(row);
|
|
}
|
|
}
|
|
}
|
|
foreach (var categories in PipeData.GetTable())
|
|
{
|
|
foreach (var row in categories.Value["duct"])
|
|
{
|
|
//subcategory.Key
|
|
if (ductCollection.Find(x => x.Name == row.strType) == null)
|
|
{
|
|
if (delDuctData.Find(z => z.strType == row.strType) == null)
|
|
delDuctData.Add(row);
|
|
}
|
|
}
|
|
}
|
|
//삭제하기
|
|
|
|
foreach (var pipe in delPipeData)
|
|
{
|
|
foreach (var categories in PipeData.GetTable())
|
|
{
|
|
PipeData.Remove(categories.Key, true, pipe.strType);
|
|
}
|
|
}
|
|
foreach (var duct in delDuctData)
|
|
{
|
|
foreach (var categories in PipeData.GetTable())
|
|
{
|
|
PipeData.Remove(categories.Key, false, duct.strType);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
PipeData.AddCategory("기본");
|
|
|
|
}
|
|
//현재 프로젝트에는 있는데 저장된 파일에는 없는 경우 추가한다.
|
|
List<DataStorage> newPipeData = new List<DataStorage>();
|
|
List<DataStorage> newDuctData = new List<DataStorage>();
|
|
foreach (var pipe in pipeCollection)
|
|
{
|
|
if (PipeData.m_table.First().Value["pipe"].Find(x => x.strType == pipe.Name) == null)
|
|
{
|
|
var row = new DataStorage(pipe.Name, strPipeinsul, 25, true);
|
|
var sizes = Util.GetPipeSegmentSizes(doc, pipe.Name);
|
|
foreach (var r in sizes)
|
|
{
|
|
row.BoreList.Add(new PipeDiameterOfThickness((int)r, 25));
|
|
}
|
|
newPipeData.Add(row);
|
|
}
|
|
}
|
|
foreach (var duct in ductCollection)
|
|
{
|
|
if (PipeData.m_table.First().Value["duct"].Find(x => x.strType == duct.Name) == null)
|
|
{
|
|
newDuctData.Add(new DataStorage(duct.Name, strPipeinsul, 25, true));
|
|
}
|
|
}
|
|
//추가하기
|
|
foreach (var pipe in newPipeData)
|
|
{
|
|
foreach (var categories in PipeData.GetTable())
|
|
{
|
|
PipeData.Add(categories.Key, true, pipe.strType, pipe.strLaggingType, pipe.dblLaggingThickness, pipe.bisNew);
|
|
var sizes = Util.GetPipeSegmentSizes(doc, pipe.strType);
|
|
foreach (var r in sizes)
|
|
{
|
|
PipeData.Find(categories.Key, true, pipe.strType).BoreList.Add(new PipeDiameterOfThickness((int)r, (int)pipe.dblLaggingThickness));
|
|
}
|
|
}
|
|
}
|
|
foreach (var duct in newDuctData)
|
|
{
|
|
foreach (var categories in PipeData.GetTable())
|
|
{
|
|
PipeData.Add(categories.Key, false, duct.strType, duct.strLaggingType, duct.dblLaggingThickness, duct.bisNew);
|
|
}
|
|
}
|
|
|
|
FormSleeve frmSleeve = new FormSleeve(lstString1, lstString2, PipeData);
|
|
frmSleeve.label3.Text = "슬리브 대상";
|
|
|
|
frmSleeve.ShowDialog();
|
|
if (frmSleeve.mbRes == false) return Result.Succeeded;
|
|
|
|
|
|
if (frmSleeve.bPenetrate())
|
|
strInstallType = "관통형";
|
|
else
|
|
strInstallType = "성형";
|
|
|
|
bool bInsulation = frmSleeve.Insulation; // 단열재 적용 유무
|
|
this.bApplyPipe = frmSleeve.bApplyPipe;
|
|
this.bApplyDuct = frmSleeve.bApplyDuct;
|
|
bKeepInsulation = frmSleeve.bKeepInsulation; // 단열재 적용
|
|
double dblInsulationThickness = 0; // <<====== 파이프 유형별 또는 덕트 유형별 단열재 두께를 적용해야 하기 때문에 실제 삽입 후 해당 파이프 또는 덕트의 보온재 두께를 구해야 함.
|
|
double dblPipeGap = Unit.MMToFeet(frmSleeve.dPipeOffsetValue);
|
|
double dblDuctGap = Unit.MMToFeet(frmSleeve.dDuctOffsetValue);
|
|
//double dblPipeGap = Unit.CovertToAPI(frmSleeve.dPipeOffsetValue, DisplayUnitType.DUT_MILLIMETERS);
|
|
//double dblDuctGap = Unit.CovertToAPI(frmSleeve.dDuctOffsetValue, DisplayUnitType.DUT_MILLIMETERS);
|
|
lstString1 = frmSleeve.mlstString1;
|
|
lstString2 = frmSleeve.mlstString2;
|
|
|
|
string category = KDCS.Utils.Reg.getReg("kdcsInsulationDefaultType");
|
|
|
|
if (bInsulation)
|
|
{
|
|
using (Transaction t = new Transaction(doc))
|
|
{
|
|
t.Start("Insulation");
|
|
foreach (Element el in ielement.ToList())
|
|
{
|
|
Type et = el.GetType();
|
|
|
|
if (typeof(RevitLinkInstance) == et)
|
|
{
|
|
//linkInstance = e as RevitLinkInstance;
|
|
continue;
|
|
}
|
|
|
|
|
|
if (el is Pipe)
|
|
{
|
|
SetInsulation(el);
|
|
}
|
|
else if (el is Duct)
|
|
{
|
|
SetInsulation(el);
|
|
}//end-if
|
|
else if (el is FamilyInstance)
|
|
{
|
|
SetInsulation(el);
|
|
}
|
|
|
|
|
|
}//end-foreach
|
|
t.Commit();
|
|
}
|
|
}
|
|
|
|
//if (category.CompareTo("") == 0) { Reg.setReg("kdcsInsulationDefaultType", "기본"); category = "기본"; }
|
|
using (Transaction t = new Transaction(doc))
|
|
{
|
|
t.Start("Place a New Sleeve Instance");
|
|
#region 벽에 슬리브 배치
|
|
if (m_walls.Count > 0 && lstString2.Contains(sWall))
|
|
{
|
|
|
|
foreach (Wall curWall in m_walls)
|
|
{
|
|
|
|
List<Face> lstWallFace = new List<Face>();
|
|
Reference linkToExteriorFaceRef = null;
|
|
var lc = curWall.Location as LocationCurve;
|
|
|
|
|
|
|
|
RevitLinkInstance rliWall = rliRefFace[curWall.Id] as RevitLinkInstance;
|
|
Curve crvTransform = lc.Curve.CreateTransformed(rliWall.GetTransform());
|
|
XYZ ptS = crvTransform.GetEndPoint(0);
|
|
XYZ ptE = crvTransform.GetEndPoint(1);
|
|
|
|
XYZ vL = (ptE - ptS).Normalize();
|
|
XYZ vN = vL.CrossProduct(XYZ.BasisZ);
|
|
|
|
double dblThickness = 0;
|
|
|
|
|
|
|
|
|
|
XYZ startPoint = null;
|
|
XYZ endPoint = null;
|
|
#region 벽-파이프
|
|
try
|
|
{
|
|
foreach (Pipe curPipe in lstPipe)
|
|
{
|
|
|
|
if (Util.GetStartEndPoint(curPipe, ref startPoint, ref endPoint) == false) continue;
|
|
Line curve = Line.CreateBound(startPoint, endPoint);
|
|
XYZ vz = (endPoint - startPoint).Normalize(); // 벡터
|
|
|
|
|
|
PlanarFace pfWall = null;
|
|
GetLinkedWallReferenceFace(rliWall, curWall, curve, out linkToExteriorFaceRef, out pfWall, out dblThickness);
|
|
|
|
dblInsulationThickness = 0;
|
|
if (bInsulation)
|
|
{
|
|
dblInsulationThickness = GetInsulationThickness(curPipe);
|
|
if (dblInsulationThickness <= 0 || !bKeepInsulation)
|
|
{
|
|
DataStorage InsulationSettings = PipeData.Find(category, true, curPipe.PipeType.Name);
|
|
if (InsulationSettings != null)
|
|
dblInsulationThickness = Unit.MMToFeet(InsulationSettings.dblLaggingThickness);
|
|
}
|
|
}
|
|
if (!bApplyPipe)
|
|
dblInsulationThickness = 0;
|
|
|
|
double dOuterDiameter = curPipe.get_Parameter(BuiltInParameter.RBS_PIPE_OUTER_DIAMETER).AsDouble();
|
|
//double dDia = curPipe.Diameter;
|
|
//double dist = dOuterDiameter * dRatio + dblInsulationThickness + dblGap;
|
|
|
|
|
|
|
|
XYZ ptLoc = null;
|
|
|
|
if (pfWall == null) continue;
|
|
|
|
IntersectionResultArray results = new IntersectionResultArray();
|
|
pfWall.Intersect(curve, out results);
|
|
if (results != null)
|
|
{
|
|
if (results.Size > 0)
|
|
{
|
|
IntersectionResult ir = results.get_Item(0);
|
|
if (ir.XYZPoint != null) ptLoc = ir.XYZPoint;
|
|
}
|
|
}
|
|
|
|
|
|
if (ptLoc == null) continue;
|
|
|
|
|
|
|
|
FamilyInstance instance = crePipeSleeve.CreateOpening(linkToExteriorFaceRef, ptLoc, vL);
|
|
if (instance != null)
|
|
{
|
|
Autodesk.Revit.DB.Parameter paramND = instance.LookupParameter("Diameter");
|
|
Autodesk.Revit.DB.Parameter paramInsulationThick = instance.LookupParameter("InsulationThickness");
|
|
Autodesk.Revit.DB.Parameter paramGapDist = instance.LookupParameter("Gap");
|
|
Autodesk.Revit.DB.Parameter paramL = instance.LookupParameter("Thickness");
|
|
Autodesk.Revit.DB.Parameter paramRadius = instance.LookupParameter("Radius");
|
|
Autodesk.Revit.DB.Parameter paramType = instance.LookupParameter("Slv_Slv_Type");
|
|
Autodesk.Revit.DB.Parameter paramLength = instance.LookupParameter("Slv_Slv_Length");
|
|
Autodesk.Revit.DB.Parameter paramLevel = instance.LookupParameter("Slv_Slv_Level");
|
|
Autodesk.Revit.DB.Parameter paramInstallType = instance.LookupParameter("Slv_Slv_InstallType");
|
|
|
|
double pipeDia = curPipe.get_Parameter(BuiltInParameter.RBS_PIPE_DIAMETER_PARAM).AsDouble();
|
|
|
|
var lv = KDCS.Utils.Util.GetLevel(doc, ptLoc.Z);
|
|
|
|
|
|
paramND.Set(dOuterDiameter);
|
|
paramInsulationThick.Set(dblInsulationThickness);
|
|
paramGapDist.Set(dblPipeGap);
|
|
|
|
double dbltotalThick = Unit.FeetToMM((dblInsulationThickness * 2) + (dblPipeGap * 2) + pipeDia);
|
|
var sizes = Util.GetPipeSegmentSizes(doc, curPipe.PipeType.Name);
|
|
var lst = sizes.Where(n => n >= dbltotalThick);
|
|
List<double> arr = lst.ToList();
|
|
arr.Sort();
|
|
if (arr.Count() == 0)
|
|
{
|
|
//관경이 없을경우 50단위로 올린다.
|
|
arr.Add(dbltotalThick + 50);
|
|
|
|
}
|
|
paramRadius.Set(Unit.MMToFeet(arr.First()) * 0.5);
|
|
paramType.Set("Wall");
|
|
paramLength.Set(dbltotalThick);
|
|
paramLevel.Set(lv.Name);
|
|
paramInstallType.Set(strInstallType);
|
|
|
|
|
|
|
|
if (dblThickness > 0) paramL.Set(dblThickness);
|
|
else paramL.Set(curWall.WallType.Width);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
//Console.WriteLine(e.Message);
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region 1 벽-각형덕트
|
|
try
|
|
{
|
|
foreach (Duct curDuct in lstRectDuct)
|
|
{
|
|
if (Util.GetStartEndPoint(curDuct, ref startPoint, ref endPoint) == false) continue;
|
|
|
|
|
|
List<XYZ> lstOpPt = new List<XYZ>();
|
|
Line curve = Line.CreateBound(startPoint, endPoint);
|
|
XYZ vz = (endPoint - startPoint).Normalize();
|
|
|
|
PlanarFace pfWall = null;
|
|
GetLinkedWallReferenceFace(rliWall, curWall, curve, out linkToExteriorFaceRef, out pfWall, out dblThickness);
|
|
|
|
dblInsulationThickness = 0;
|
|
if (bInsulation)
|
|
{
|
|
dblInsulationThickness = GetInsulationThickness(curDuct);
|
|
if (dblInsulationThickness <= 0 || !bKeepInsulation)
|
|
{
|
|
DataStorage InsulationSettings = PipeData.Find(category, false, curDuct.DuctType.Name);
|
|
if (InsulationSettings != null)
|
|
dblInsulationThickness = Unit.MMToFeet(InsulationSettings.dblLaggingThickness);
|
|
}
|
|
}
|
|
if (!bApplyDuct)
|
|
dblInsulationThickness = 0;
|
|
|
|
XYZ ptLoc = null;
|
|
if (pfWall == null) continue;
|
|
|
|
IntersectionResultArray results = new IntersectionResultArray();
|
|
pfWall.Intersect(curve, out results);
|
|
if (results != null)
|
|
{
|
|
if (results.Size > 0)
|
|
{
|
|
IntersectionResult ir = results.get_Item(0);
|
|
if (ir.XYZPoint != null) ptLoc = ir.XYZPoint;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
double dWidth = curDuct.Width;
|
|
double dHeight = curDuct.Height;
|
|
|
|
|
|
double dblHalfWid = 0.5 * dWidth;
|
|
|
|
if (ptLoc == null) continue;
|
|
|
|
|
|
FamilyInstance instance = creDuctSleeveRect.CreateOpening(linkToExteriorFaceRef, ptLoc, vL);
|
|
if (instance != null)
|
|
{
|
|
Autodesk.Revit.DB.Parameter paramW = instance.LookupParameter("Width"); // 폭
|
|
Autodesk.Revit.DB.Parameter paramH = instance.LookupParameter("Height"); // 높이
|
|
Autodesk.Revit.DB.Parameter paramInsulationThick = instance.LookupParameter("InsulationThickness"); // 단열재 두께
|
|
Autodesk.Revit.DB.Parameter paramGapDist = instance.LookupParameter("Gap"); // 간격
|
|
Autodesk.Revit.DB.Parameter paramL = instance.LookupParameter("Thickness"); // 벽 두께
|
|
Autodesk.Revit.DB.Parameter paramType = instance.LookupParameter("Slv_Slv_Type");
|
|
Autodesk.Revit.DB.Parameter paramLength = instance.LookupParameter("Slv_Slv_Length");
|
|
Autodesk.Revit.DB.Parameter paramLevel = instance.LookupParameter("Slv_Slv_Level");
|
|
Autodesk.Revit.DB.Parameter paramInstallType = instance.LookupParameter("Slv_Slv_InstallType");
|
|
|
|
var lv = KDCS.Utils.Util.GetLevel(doc, ptLoc.Z);
|
|
|
|
paramType.Set("Wall");
|
|
paramLevel.Set(lv.Name);
|
|
paramInstallType.Set(strInstallType);
|
|
if (paramW != null && paramH != null && paramGapDist != null)
|
|
{
|
|
paramW.Set(dWidth);
|
|
paramH.Set(dHeight);
|
|
paramInsulationThick.Set(dblInsulationThickness);
|
|
paramGapDist.Set(dblDuctGap - dblInsulationThickness);
|
|
if (dblThickness > 0) paramL.Set(dblThickness);
|
|
else paramL.Set(curWall.WallType.Width);
|
|
|
|
paramLength.Set(dblThickness);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
lstOpPt.Clear();
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e.Message);
|
|
}
|
|
#endregion
|
|
|
|
#region 2 벽-원형덕트
|
|
try
|
|
{
|
|
foreach (Duct curDuct in lstRoundDuct)
|
|
{
|
|
if (Util.GetStartEndPoint(curDuct, ref startPoint, ref endPoint) == false)
|
|
{ t.Commit(); return Result.Succeeded; }
|
|
|
|
List<IntersectionResult> lstInters = new List<IntersectionResult>();
|
|
List<XYZ> lstOpPt = new List<XYZ>();
|
|
Line curve = Line.CreateBound(startPoint, endPoint);
|
|
XYZ vz = (endPoint - startPoint).Normalize();
|
|
|
|
|
|
|
|
PlanarFace pfWall = null;
|
|
GetLinkedWallReferenceFace(rliWall, curWall, curve, out linkToExteriorFaceRef, out pfWall, out dblThickness);
|
|
|
|
dblInsulationThickness = 0;
|
|
if (bInsulation)
|
|
{
|
|
dblInsulationThickness = GetInsulationThickness(curDuct);
|
|
if (dblInsulationThickness <= 0 || !bKeepInsulation)
|
|
{
|
|
DataStorage InsulationSettings = PipeData.Find(category, false, curDuct.DuctType.Name);
|
|
if (InsulationSettings != null)
|
|
dblInsulationThickness = Unit.MMToFeet(InsulationSettings.dblLaggingThickness);
|
|
}
|
|
}
|
|
|
|
if (!bApplyDuct)
|
|
dblInsulationThickness = 0;
|
|
XYZ ptLoc = null;
|
|
if (pfWall == null) continue;
|
|
|
|
IntersectionResultArray results = new IntersectionResultArray();
|
|
pfWall.Intersect(curve, out results);
|
|
if (results != null)
|
|
{
|
|
if (results.Size > 0)
|
|
{
|
|
IntersectionResult ir = results.get_Item(0);
|
|
if (ir.XYZPoint != null) ptLoc = ir.XYZPoint;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
double dDia = curDuct.Diameter;
|
|
double dist = dDia * dRatio + dblInsulationThickness + dblDuctGap;
|
|
|
|
|
|
if (ptLoc == null) continue;
|
|
|
|
|
|
FamilyInstance instance = creDuctSleeveRound.CreateOpening(linkToExteriorFaceRef, ptLoc, vL);
|
|
|
|
Autodesk.Revit.DB.Parameter paramR = instance.LookupParameter("Diameter");
|
|
Autodesk.Revit.DB.Parameter paramInsulationThick = instance.LookupParameter("InsulationThickness");
|
|
Autodesk.Revit.DB.Parameter paramGapDist = instance.LookupParameter("Gap");
|
|
Autodesk.Revit.DB.Parameter paramL = instance.LookupParameter("Thickness");
|
|
Autodesk.Revit.DB.Parameter paramType = instance.LookupParameter("Slv_Slv_Type");
|
|
Autodesk.Revit.DB.Parameter paramLength = instance.LookupParameter("Slv_Slv_Length");
|
|
Autodesk.Revit.DB.Parameter paramLevel = instance.LookupParameter("Slv_Slv_Level");
|
|
Autodesk.Revit.DB.Parameter paramInstallType = instance.LookupParameter("Slv_Slv_InstallType");
|
|
|
|
var lv = KDCS.Utils.Util.GetLevel(doc, ptLoc.Z);
|
|
|
|
|
|
|
|
paramR.Set(dDia);
|
|
paramInsulationThick.Set(dblInsulationThickness);
|
|
paramGapDist.Set(dblDuctGap - dblInsulationThickness);
|
|
if (dblThickness > 0) paramL.Set(dblThickness);
|
|
else paramL.Set(curWall.WallType.Width);
|
|
|
|
paramType.Set("Wall");
|
|
paramLength.Set(dblThickness);
|
|
paramLevel.Set(lv.Name);
|
|
paramInstallType.Set(strInstallType);
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e.Message);
|
|
}
|
|
#endregion
|
|
|
|
#region 3 벽 - 타원형 덕트
|
|
try
|
|
{
|
|
foreach (Duct curDuct in lstOvalDuct)
|
|
{
|
|
if (Util.GetStartEndPoint(curDuct, ref startPoint, ref endPoint) == false)
|
|
{ t.Commit(); return Result.Succeeded; }
|
|
|
|
List<XYZ> lstOpPt = new List<XYZ>();
|
|
Line curve = Line.CreateBound(startPoint, endPoint);
|
|
XYZ vz = (endPoint - startPoint).Normalize();
|
|
|
|
PlanarFace pfWall = null;
|
|
GetLinkedWallReferenceFace(rliWall, curWall, curve, out linkToExteriorFaceRef, out pfWall, out dblThickness);
|
|
|
|
dblInsulationThickness = 0;
|
|
if (bInsulation)
|
|
{
|
|
dblInsulationThickness = GetInsulationThickness(curDuct);
|
|
if (dblInsulationThickness <= 0 || !bKeepInsulation)
|
|
{
|
|
DataStorage InsulationSettings = PipeData.Find(category, false, curDuct.DuctType.Name);
|
|
if (InsulationSettings != null)
|
|
dblInsulationThickness = Unit.MMToFeet(InsulationSettings.dblLaggingThickness);
|
|
}
|
|
}
|
|
if (!bApplyDuct)
|
|
dblInsulationThickness = 0;
|
|
|
|
XYZ ptLoc = null;
|
|
if (pfWall == null) continue;
|
|
|
|
IntersectionResultArray results = new IntersectionResultArray();
|
|
pfWall.Intersect(curve, out results);
|
|
if (results != null)
|
|
{
|
|
if (results.Size > 0)
|
|
{
|
|
IntersectionResult ir = results.get_Item(0);
|
|
if (ir.XYZPoint != null) ptLoc = ir.XYZPoint;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (ptLoc == null) continue;
|
|
|
|
double dWidth = curDuct.Width;
|
|
double dHeight = curDuct.Height;
|
|
|
|
FamilyInstance instance = creDuctSleeveOval.CreateOpening(linkToExteriorFaceRef, ptLoc, vL);
|
|
Autodesk.Revit.DB.Parameter paramW = instance.LookupParameter("Width");
|
|
Autodesk.Revit.DB.Parameter paramH = instance.LookupParameter("Height");
|
|
Autodesk.Revit.DB.Parameter paramInsulationThick = instance.LookupParameter("InsulationThickness");
|
|
Autodesk.Revit.DB.Parameter paramGap = instance.LookupParameter("Gap");
|
|
Autodesk.Revit.DB.Parameter paramL = instance.LookupParameter("Thickness");
|
|
Autodesk.Revit.DB.Parameter paramType = instance.LookupParameter("Slv_Slv_Type");
|
|
Autodesk.Revit.DB.Parameter paramLength = instance.LookupParameter("Slv_Slv_Length");
|
|
Autodesk.Revit.DB.Parameter paramLevel = instance.LookupParameter("Slv_Slv_Level");
|
|
Autodesk.Revit.DB.Parameter paramInstallType = instance.LookupParameter("Slv_Slv_InstallType");
|
|
|
|
var lv = KDCS.Utils.Util.GetLevel(doc, ptLoc.Z);
|
|
|
|
|
|
paramW.Set(dWidth);
|
|
paramH.Set(dHeight);
|
|
paramInsulationThick.Set(dblInsulationThickness);
|
|
paramGap.Set(dblDuctGap - dblInsulationThickness);
|
|
if (dblThickness > 0) paramL.Set(dblThickness);
|
|
else paramL.Set(curWall.WallType.Width);
|
|
|
|
paramType.Set("Wall");
|
|
paramLength.Set(dblThickness);
|
|
paramLevel.Set(lv.Name);
|
|
paramInstallType.Set(strInstallType);
|
|
|
|
}//end-foreach
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e.Message);
|
|
}
|
|
#endregion
|
|
|
|
}//foreach
|
|
|
|
|
|
|
|
}//if
|
|
#endregion
|
|
|
|
#region 바닥에 슬리브 배치
|
|
|
|
if (m_floors.Count > 0 && lstString2.Contains(sFloor))
|
|
{
|
|
|
|
foreach (Floor curFloor in m_floors)
|
|
{
|
|
Reference linkToExteriorFaceRef = null;
|
|
|
|
|
|
RevitLinkInstance rliFloor = rliRefFace[curFloor.Id] as RevitLinkInstance;
|
|
if (rliFloor == null) continue;
|
|
|
|
|
|
double dblThickness = 0;
|
|
|
|
PlanarFace pfFloor = null;
|
|
GetLinkedFloorReferenceFace(rliFloor, curFloor, out linkToExteriorFaceRef, out pfFloor, out dblThickness);
|
|
|
|
XYZ startPoint = null;
|
|
XYZ endPoint = null;
|
|
|
|
|
|
|
|
if (pfFloor == null) continue;
|
|
|
|
try
|
|
{
|
|
|
|
#region 바닥-파이프
|
|
foreach (Pipe curPipe in lstPipe)
|
|
{
|
|
if (Util.GetStartEndPoint(curPipe, ref startPoint, ref endPoint) == false) // 파이프 시작점 끝점 구하기
|
|
{ t.Commit(); return Result.Succeeded; }
|
|
|
|
dblInsulationThickness = 0;
|
|
if (bInsulation)
|
|
{
|
|
dblInsulationThickness = GetInsulationThickness(curPipe);
|
|
if (dblInsulationThickness <= 0 || !bKeepInsulation)
|
|
{
|
|
DataStorage InsulationSettings = PipeData.Find(category, true, curPipe.PipeType.Name);
|
|
if (InsulationSettings != null)
|
|
dblInsulationThickness = Unit.MMToFeet(InsulationSettings.dblLaggingThickness);
|
|
}
|
|
}
|
|
|
|
if (!bApplyPipe)
|
|
dblInsulationThickness = 0;
|
|
|
|
Line curve = Line.CreateBound(startPoint, endPoint); // 라인 생성
|
|
XYZ ptLoc = null;
|
|
|
|
|
|
|
|
IntersectionResultArray results = new IntersectionResultArray();
|
|
pfFloor.Intersect(curve, out results);
|
|
if (results != null)
|
|
{
|
|
if (results.Size > 0)
|
|
{
|
|
IntersectionResult ir = results.get_Item(0);
|
|
if (ir.XYZPoint != null) ptLoc = ir.XYZPoint;
|
|
}
|
|
}
|
|
if (ptLoc == null) continue;
|
|
|
|
|
|
double dblDia = curPipe.Diameter;
|
|
double dOuterDiameter = curPipe.get_Parameter(BuiltInParameter.RBS_PIPE_OUTER_DIAMETER).AsDouble();
|
|
FamilyInstance instance = crePipeSleeve.CreateOpening(linkToExteriorFaceRef, ptLoc, XYZ.BasisX);
|
|
Autodesk.Revit.DB.Parameter paramND = instance.LookupParameter("Diameter");
|
|
Autodesk.Revit.DB.Parameter paramInsulationThick = instance.LookupParameter("InsulationThickness");
|
|
Autodesk.Revit.DB.Parameter paramGapDist = instance.LookupParameter("Gap");
|
|
Autodesk.Revit.DB.Parameter paramL = instance.LookupParameter("Thickness");
|
|
Autodesk.Revit.DB.Parameter paramRadius = instance.LookupParameter("Radius");
|
|
Autodesk.Revit.DB.Parameter paramType = instance.LookupParameter("Slv_Slv_Type");
|
|
Autodesk.Revit.DB.Parameter paramLength = instance.LookupParameter("Slv_Slv_Length");
|
|
Autodesk.Revit.DB.Parameter paramLevel = instance.LookupParameter("Slv_Slv_Level");
|
|
Autodesk.Revit.DB.Parameter paramInstallType = instance.LookupParameter("Slv_Slv_InstallType");
|
|
|
|
var lv = KDCS.Utils.Util.GetLevel(doc, ptLoc.Z);
|
|
|
|
|
|
paramType.SetValueString("Floor");
|
|
paramLevel.Set(lv.Name);
|
|
paramInstallType.Set(strInstallType);
|
|
paramND.Set(dOuterDiameter);
|
|
paramInsulationThick.Set(dblInsulationThickness);
|
|
paramGapDist.Set(dblPipeGap);
|
|
|
|
if (dblThickness != 0)
|
|
{
|
|
paramL.Set(dblThickness);
|
|
}
|
|
else
|
|
{
|
|
Autodesk.Revit.DB.Parameter parameter = curFloor.FloorType.get_Parameter(BuiltInParameter.FLOOR_ATTR_DEFAULT_THICKNESS_PARAM);
|
|
paramL.Set(parameter.AsDouble());
|
|
}
|
|
|
|
double dbltotalThick = Unit.FeetToMM((dblInsulationThickness * 2) + (dblPipeGap * 2) + dblDia);
|
|
var sizes = Util.GetPipeSegmentSizes(doc, curPipe.PipeType.Name);
|
|
var lst = sizes.Where(n => n >= dbltotalThick);
|
|
List<double> arr = lst.ToList();
|
|
arr.Sort();
|
|
if (arr.Count() == 0)
|
|
{
|
|
//관경이 없을경우 50단위로 올린다.
|
|
arr.Add(dbltotalThick + 50);
|
|
|
|
}
|
|
paramRadius.Set(Unit.MMToFeet(arr.First()) * 0.5);
|
|
paramLength.Set(dbltotalThick);
|
|
|
|
|
|
|
|
|
|
|
|
}//end-foreach
|
|
#endregion //바닥-파이프
|
|
|
|
#region 1 바닥-각형덕트
|
|
foreach (Duct curDuct in lstRectDuct)
|
|
{
|
|
if (Util.GetStartEndPoint(curDuct, ref startPoint, ref endPoint) == false) continue;
|
|
|
|
dblInsulationThickness = 0;
|
|
if (bInsulation)
|
|
{
|
|
dblInsulationThickness = GetInsulationThickness(curDuct);
|
|
if (dblInsulationThickness <= 0 || !bKeepInsulation)
|
|
{
|
|
DataStorage InsulationSettings = PipeData.Find(category, false, curDuct.DuctType.Name);
|
|
if (InsulationSettings != null)
|
|
dblInsulationThickness = Unit.MMToFeet(InsulationSettings.dblLaggingThickness);
|
|
}
|
|
}
|
|
if (!bApplyDuct)
|
|
dblInsulationThickness = 0;
|
|
|
|
List<XYZ> lstOpPt = new List<XYZ>();
|
|
Line curve = Line.CreateBound(startPoint, endPoint);
|
|
XYZ vz = (endPoint - startPoint).Normalize();
|
|
|
|
|
|
XYZ ptLoc = null;
|
|
|
|
IntersectionResultArray results = new IntersectionResultArray();
|
|
pfFloor.Intersect(curve, out results);
|
|
if (results != null)
|
|
{
|
|
if (results.Size > 0)
|
|
{
|
|
IntersectionResult ir = results.get_Item(0);
|
|
if (ir.XYZPoint != null) ptLoc = ir.XYZPoint;
|
|
}
|
|
}
|
|
|
|
|
|
double dWidth = curDuct.Width;
|
|
double dHeight = curDuct.Height;
|
|
|
|
|
|
double dblHalfWid = 0.5 * dWidth;
|
|
if (ptLoc == null) continue;
|
|
|
|
var con_man = Util.GetConnectorManager(curDuct);
|
|
XYZ baseX = XYZ.BasisX;
|
|
if (con_man != null)
|
|
{
|
|
foreach (Connector connector2 in con_man.Connectors)
|
|
{ // 기준 파이프에 연결될 파이프
|
|
baseX = connector2.CoordinateSystem.BasisX;
|
|
break;
|
|
}
|
|
}
|
|
|
|
FamilyInstance instance = creDuctSleeveRect.CreateOpening(linkToExteriorFaceRef, ptLoc, baseX);
|
|
if (instance != null)
|
|
{
|
|
Autodesk.Revit.DB.Parameter paramW = instance.LookupParameter("Width"); // 폭
|
|
Autodesk.Revit.DB.Parameter paramH = instance.LookupParameter("Height"); // 높이
|
|
Autodesk.Revit.DB.Parameter paramInsulationThick = instance.LookupParameter("InsulationThickness");
|
|
Autodesk.Revit.DB.Parameter paramGapDist = instance.LookupParameter("Gap"); // 간격
|
|
Autodesk.Revit.DB.Parameter paramL = instance.LookupParameter("Thickness");
|
|
Autodesk.Revit.DB.Parameter paramType = instance.LookupParameter("Slv_Slv_Type");
|
|
Autodesk.Revit.DB.Parameter paramLength = instance.LookupParameter("Slv_Slv_Length");
|
|
Autodesk.Revit.DB.Parameter paramLevel = instance.LookupParameter("Slv_Slv_Level");
|
|
Autodesk.Revit.DB.Parameter paramInstallType = instance.LookupParameter("Slv_Slv_InstallType");
|
|
|
|
var lv = KDCS.Utils.Util.GetLevel(doc, ptLoc.Z);
|
|
|
|
paramType.Set("Floor");
|
|
paramLevel.Set(lv.Name);
|
|
paramInstallType.Set(strInstallType);
|
|
if (paramW != null && paramH != null && paramGapDist != null)
|
|
{
|
|
paramW.Set(dWidth);
|
|
paramH.Set(dHeight);
|
|
paramInsulationThick.Set(dblInsulationThickness);
|
|
paramGapDist.Set(dblPipeGap - dblInsulationThickness);
|
|
|
|
if (dblThickness != 0)
|
|
{
|
|
paramL.Set(dblThickness);
|
|
paramLength.Set(dblThickness);
|
|
}
|
|
else
|
|
{
|
|
Autodesk.Revit.DB.Parameter parameter = curFloor.FloorType.get_Parameter(BuiltInParameter.FLOOR_ATTR_DEFAULT_THICKNESS_PARAM);
|
|
paramL.Set(parameter.AsDouble());
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
lstOpPt.Clear();
|
|
}
|
|
#endregion
|
|
|
|
#region 2 바닥-원형덕트
|
|
foreach (Duct curDuct in lstRoundDuct)
|
|
{
|
|
if (Util.GetStartEndPoint(curDuct, ref startPoint, ref endPoint) == false)
|
|
{ t.Commit(); return Result.Succeeded; }
|
|
|
|
dblInsulationThickness = 0;
|
|
if (bInsulation)
|
|
{
|
|
dblInsulationThickness = GetInsulationThickness(curDuct);
|
|
if (dblInsulationThickness <= 0 || !bKeepInsulation)
|
|
{
|
|
DataStorage InsulationSettings = PipeData.Find(category, false, curDuct.DuctType.Name);
|
|
if (InsulationSettings != null)
|
|
dblInsulationThickness = Unit.MMToFeet(InsulationSettings.dblLaggingThickness);
|
|
}
|
|
}
|
|
|
|
if (!bApplyDuct)
|
|
dblInsulationThickness = 0;
|
|
|
|
List<IntersectionResult> lstInters = new List<IntersectionResult>();
|
|
List<XYZ> lstOpPt = new List<XYZ>();
|
|
Line curve = Line.CreateBound(startPoint, endPoint);
|
|
XYZ vz = (endPoint - startPoint).Normalize();
|
|
|
|
|
|
XYZ ptLoc = null;
|
|
|
|
IntersectionResultArray results = new IntersectionResultArray();
|
|
pfFloor.Intersect(curve, out results);
|
|
if (results != null)
|
|
{
|
|
if (results.Size > 0)
|
|
{
|
|
IntersectionResult ir = results.get_Item(0);
|
|
if (ir.XYZPoint != null) ptLoc = ir.XYZPoint;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
double dDia = curDuct.Diameter;
|
|
double dist = dDia * dRatio + dblInsulationThickness + dblDuctGap;
|
|
|
|
|
|
if (ptLoc == null) continue;
|
|
|
|
|
|
FamilyInstance instance = creDuctSleeveRound.CreateOpening(linkToExteriorFaceRef, ptLoc, XYZ.BasisX);
|
|
|
|
Autodesk.Revit.DB.Parameter paramR = instance.LookupParameter("Diameter");
|
|
Autodesk.Revit.DB.Parameter paramInsulationThick = instance.LookupParameter("InsulationThickness");
|
|
Autodesk.Revit.DB.Parameter paramGapDist = instance.LookupParameter("Gap");
|
|
Autodesk.Revit.DB.Parameter paramL = instance.LookupParameter("Thickness");
|
|
Autodesk.Revit.DB.Parameter paramType = instance.LookupParameter("Slv_Slv_Type");
|
|
Autodesk.Revit.DB.Parameter paramLength = instance.LookupParameter("Slv_Slv_Length");
|
|
Autodesk.Revit.DB.Parameter paramLevel = instance.LookupParameter("Slv_Slv_Level");
|
|
Autodesk.Revit.DB.Parameter paramInstallType = instance.LookupParameter("Slv_Slv_InstallType");
|
|
|
|
var lv = KDCS.Utils.Util.GetLevel(doc, ptLoc.Z);
|
|
paramType.Set("Floor");
|
|
paramLevel.Set(lv.Name);
|
|
paramInstallType.Set(strInstallType);
|
|
paramR.Set(dDia);
|
|
paramInsulationThick.Set(dblInsulationThickness);
|
|
paramGapDist.Set(dblDuctGap - dblInsulationThickness);
|
|
if (dblThickness != 0)
|
|
{
|
|
paramL.Set(dblThickness);
|
|
paramLength.Set(dblThickness);
|
|
|
|
}
|
|
else
|
|
{
|
|
Autodesk.Revit.DB.Parameter parameter = curFloor.FloorType.get_Parameter(BuiltInParameter.FLOOR_ATTR_DEFAULT_THICKNESS_PARAM);
|
|
paramL.Set(parameter.AsDouble());
|
|
}
|
|
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region 3 바닥 - 타원형 덕트
|
|
foreach (Duct curDuct in lstOvalDuct)
|
|
{
|
|
if (Util.GetStartEndPoint(curDuct, ref startPoint, ref endPoint) == false)
|
|
{ t.Commit(); return Result.Succeeded; }
|
|
|
|
|
|
dblInsulationThickness = 0;
|
|
if (bInsulation)
|
|
{
|
|
dblInsulationThickness = GetInsulationThickness(curDuct);
|
|
if (dblInsulationThickness <= 0 || !bKeepInsulation)
|
|
{
|
|
DataStorage InsulationSettings = PipeData.Find(category, false, curDuct.DuctType.Name);
|
|
if (InsulationSettings != null)
|
|
dblInsulationThickness = Unit.MMToFeet(InsulationSettings.dblLaggingThickness);
|
|
}
|
|
}
|
|
|
|
if (!bApplyDuct)
|
|
dblInsulationThickness = 0;
|
|
|
|
List<XYZ> lstOpPt = new List<XYZ>();
|
|
Line curve = Line.CreateBound(startPoint, endPoint);
|
|
XYZ vz = (endPoint - startPoint).Normalize();
|
|
|
|
|
|
|
|
XYZ ptLoc = null;
|
|
|
|
IntersectionResultArray results = new IntersectionResultArray();
|
|
pfFloor.Intersect(curve, out results);
|
|
if (results != null)
|
|
{
|
|
if (results.Size > 0)
|
|
{
|
|
IntersectionResult ir = results.get_Item(0);
|
|
if (ir.XYZPoint != null) ptLoc = ir.XYZPoint;
|
|
}
|
|
}
|
|
|
|
|
|
if (ptLoc == null) continue;
|
|
|
|
|
|
var con_man = Util.GetConnectorManager(curDuct);
|
|
XYZ baseX = XYZ.BasisX;
|
|
if (con_man != null)
|
|
{
|
|
foreach (Connector connector2 in con_man.Connectors)
|
|
{ // 기준 파이프에 연결될 파이프
|
|
baseX = connector2.CoordinateSystem.BasisX;
|
|
break;
|
|
}
|
|
}
|
|
|
|
double dWidth = curDuct.Width;
|
|
double dHeight = curDuct.Height;
|
|
|
|
FamilyInstance instance = creDuctSleeveOval.CreateOpening(linkToExteriorFaceRef, ptLoc, baseX);
|
|
Autodesk.Revit.DB.Parameter paramW = instance.LookupParameter("Width");
|
|
Autodesk.Revit.DB.Parameter paramH = instance.LookupParameter("Height");
|
|
Autodesk.Revit.DB.Parameter paramInsulationThick = instance.LookupParameter("InsulationThickness");
|
|
Autodesk.Revit.DB.Parameter paramGap = instance.LookupParameter("Gap");
|
|
Autodesk.Revit.DB.Parameter paramL = instance.LookupParameter("Thickness");
|
|
Autodesk.Revit.DB.Parameter paramType = instance.LookupParameter("Slv_Slv_Type");
|
|
Autodesk.Revit.DB.Parameter paramLength = instance.LookupParameter("Slv_Slv_Length");
|
|
Autodesk.Revit.DB.Parameter paramLevel = instance.LookupParameter("Slv_Slv_Level");
|
|
Autodesk.Revit.DB.Parameter paramInstallType = instance.LookupParameter("Slv_Slv_InstallType");
|
|
|
|
var lv = KDCS.Utils.Util.GetLevel(doc, ptLoc.Z);
|
|
|
|
paramType.Set("Floor");
|
|
paramLevel.Set(lv.Name);
|
|
paramInstallType.Set(strInstallType);
|
|
paramW.Set(dWidth);
|
|
paramH.Set(dHeight);
|
|
paramInsulationThick.Set(dblInsulationThickness);
|
|
paramGap.Set(dblDuctGap - dblInsulationThickness);
|
|
if (dblThickness != 0)
|
|
{
|
|
paramL.Set(dblThickness);
|
|
paramLength.Set(dblThickness);
|
|
|
|
}
|
|
else
|
|
{
|
|
Autodesk.Revit.DB.Parameter parameter = curFloor.FloorType.get_Parameter(BuiltInParameter.FLOOR_ATTR_DEFAULT_THICKNESS_PARAM);
|
|
paramL.Set(parameter.AsDouble());
|
|
}
|
|
|
|
|
|
}//end-foreach
|
|
#endregion
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e.Message);
|
|
}
|
|
}//end-foreach
|
|
}
|
|
t.Commit();
|
|
}//end-transaction
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
return Result.Succeeded;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GetLinkedWallReferenceFace(RevitLinkInstance rli, Wall wall, Line curve, out Reference linkToExteriorFaceRef, out PlanarFace pfSide, out double dblThickness)
|
|
{
|
|
|
|
|
|
linkToExteriorFaceRef = null;
|
|
pfSide = null;
|
|
dblThickness = 0;
|
|
|
|
|
|
if (wall == null && curve == null)
|
|
{
|
|
Console.WriteLine("벽 또는 커브가 널입니다.");
|
|
return;
|
|
}
|
|
|
|
|
|
|
|
// 중심점 구하기
|
|
/*
|
|
BoundingBoxXYZ bb = wall.get_BoundingBox(null);
|
|
Transform xform = rli.GetTransform();
|
|
XYZ p0 = null;
|
|
if (bb != null)
|
|
{
|
|
XYZ ptMin = bb.Transform.OfPoint(bb.Min);
|
|
XYZ ptMax = bb.Transform.OfPoint(bb.Max);
|
|
ptMin = xform.OfPoint(ptMin);
|
|
ptMax = xform.OfPoint(ptMax);
|
|
p0 = Util.Midpoint(ptMin, ptMax);
|
|
}//end-if
|
|
if (p0 == null) return;
|
|
*/
|
|
|
|
XYZ vWallOrientation = null;
|
|
Face fUp = null;
|
|
Face fDn = null;
|
|
XYZ pu = null;
|
|
XYZ farthestUpPtOn = null;
|
|
XYZ farthestDnPtOn = null;
|
|
|
|
if (wall.Orientation == null) return;
|
|
|
|
try
|
|
{
|
|
|
|
vWallOrientation = wall.Orientation;
|
|
|
|
//XYZ pu = p0 + vWallOrientation * 32.8; // 약 10m 두께
|
|
//XYZ pd = p0 - vWallOrientation * 32.8; // 약 10m 두께
|
|
|
|
//Util.CreateModelLine(doc, pu, pd);
|
|
|
|
pu = curve.GetEndPoint(0);
|
|
|
|
|
|
var lstAllFace = Util.GetFaces(wall).ToList();
|
|
if (lstAllFace.Count < 1) return;
|
|
List<Face> lstFace = new List<Face>();
|
|
foreach (Face f in lstAllFace)
|
|
{
|
|
PlanarFace pf = f as PlanarFace;
|
|
if (Util.IsParallel(vWallOrientation, pf.FaceNormal))
|
|
{
|
|
lstFace.Add(f);
|
|
}
|
|
}
|
|
if (lstFace.Count < 1) return;
|
|
|
|
fUp = Util.GetNearestFace(lstFace, pu);
|
|
fDn = Util.GetFarthestFace(lstFace, pu);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine("Error1: " + ex.Message);
|
|
}
|
|
|
|
if (fUp == null || fDn == null) return;
|
|
|
|
Line line = Line.CreateUnbound(pu, vWallOrientation);
|
|
IntersectionResultArray irUp = new IntersectionResultArray();
|
|
IntersectionResultArray irDn = new IntersectionResultArray();
|
|
|
|
|
|
PlanarFace pfUp = fUp as PlanarFace;
|
|
PlanarFace pfDn = fDn as PlanarFace;
|
|
|
|
pfUp.Intersect(line, out irUp);
|
|
pfDn.Intersect(line, out irDn);
|
|
|
|
try
|
|
{
|
|
// 외벽쪽 면
|
|
if (irUp != null)
|
|
{
|
|
if (irUp.Size > 0)
|
|
{
|
|
IntersectionResult ir = irUp.get_Item(0);
|
|
if (ir.XYZPoint != null)
|
|
{
|
|
linkToExteriorFaceRef = pfUp.Reference.CreateLinkReference(rli); // 외벽쪽에 있는 면에 패밀리 부착
|
|
pfSide = pfUp;
|
|
farthestUpPtOn = ir.XYZPoint;
|
|
}
|
|
}
|
|
}
|
|
else return;
|
|
|
|
// 내벽쪽 면
|
|
if (irDn != null)
|
|
{
|
|
if (irDn.Size > 0)
|
|
{
|
|
IntersectionResult ir = irDn.get_Item(0);
|
|
if (ir.XYZPoint != null)
|
|
{
|
|
farthestDnPtOn = ir.XYZPoint;
|
|
|
|
}
|
|
}
|
|
}
|
|
else return;
|
|
|
|
|
|
|
|
if (farthestUpPtOn != null && farthestDnPtOn != null)
|
|
{
|
|
dblThickness = farthestUpPtOn.DistanceTo(farthestDnPtOn);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine("Error2: " + ex.Message);
|
|
}
|
|
|
|
}
|
|
|
|
// 참조 바닥 및 바닥 두께를 구합니다.
|
|
void GetLinkedFloorReferenceFace(RevitLinkInstance rli, Floor floor, out Reference linkToExteriorFaceRef, out PlanarFace pfSide, out double dblThickness)
|
|
{
|
|
linkToExteriorFaceRef = null;
|
|
pfSide = null;
|
|
dblThickness = 0;
|
|
|
|
// 박닥 중심점 구하기
|
|
BoundingBoxXYZ bb = floor.get_BoundingBox(null);
|
|
XYZ p0 = bb != null ? Util.Midpoint(bb.Min, bb.Max) : null;
|
|
//Transform xform = rli.GetTransform();
|
|
//p0 = xform.OfPoint(p0);
|
|
|
|
XYZ pu = p0 + XYZ.BasisZ * 32.8; // 약 10m 두께
|
|
XYZ pd = p0 - XYZ.BasisZ * 32.8; // 약 10m 두께
|
|
Line lu = Line.CreateBound(p0, pu);
|
|
Line ld = Line.CreateBound(p0, pd);
|
|
double farthestUpFaceDst = 0d;
|
|
double farthestDnFaceDst = 0d;
|
|
XYZ farthestUpPtOn = null;
|
|
XYZ farthestDnPtOn = null;
|
|
|
|
var lstFace = Util.GetFaces(floor).ToList();
|
|
IntersectionResultArray irUp = new IntersectionResultArray();
|
|
IntersectionResultArray irDn = new IntersectionResultArray();
|
|
try
|
|
{
|
|
foreach (Face f in lstFace)
|
|
{
|
|
PlanarFace pf = f as PlanarFace;
|
|
if (pf == null) continue;
|
|
|
|
if (Util.IsParallel(XYZ.BasisZ, pf.FaceNormal))
|
|
{
|
|
pf.Intersect(lu, out irUp);
|
|
pf.Intersect(ld, out irDn);
|
|
// 위쪽 면
|
|
if (irUp == null && irDn == null) continue;
|
|
|
|
if (irUp != null)
|
|
{
|
|
if (irUp.Size > 0)
|
|
{
|
|
IntersectionResult ir = irUp.get_Item(0);
|
|
if (ir.XYZPoint != null)
|
|
{
|
|
if (p0.DistanceTo(ir.XYZPoint) > farthestUpFaceDst)
|
|
{
|
|
linkToExteriorFaceRef = pf.Reference.CreateLinkReference(rli); // 위쪽에 있는 면에 패밀리 부착
|
|
farthestUpFaceDst = p0.DistanceTo(ir.XYZPoint);
|
|
pfSide = pf;
|
|
pd = ir.XYZPoint - XYZ.BasisZ * 32.8;
|
|
ld = Line.CreateBound(ir.XYZPoint, pd);
|
|
farthestUpPtOn = ir.XYZPoint;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
if (irDn != null)
|
|
{
|
|
// 아래쪽 면
|
|
if (irDn.Size > 0)
|
|
{
|
|
IntersectionResult ir = irDn.get_Item(0);
|
|
if (ir.XYZPoint != null)
|
|
{
|
|
if (p0.DistanceTo(ir.XYZPoint) > farthestDnFaceDst)
|
|
{
|
|
farthestDnFaceDst = p0.DistanceTo(ir.XYZPoint);
|
|
farthestDnPtOn = ir.XYZPoint;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine("Error: " + ex.Message);
|
|
}
|
|
if (farthestUpPtOn != null && farthestDnPtOn != null)
|
|
{
|
|
dblThickness = farthestUpPtOn.DistanceTo(farthestDnPtOn);
|
|
}
|
|
}
|
|
|
|
void GetAllLinkedWallsAndFloors(Document doc)
|
|
{
|
|
// At first need to find our links
|
|
FilteredElementCollector collector
|
|
= new FilteredElementCollector(doc)
|
|
.OfClass(typeof(RevitLinkInstance));
|
|
|
|
foreach (Element elem in collector)
|
|
{
|
|
// Get linkInstance
|
|
RevitLinkInstance instance = elem as RevitLinkInstance;
|
|
|
|
// Get linkDocument
|
|
Document linkDoc = instance.GetLinkDocument();
|
|
|
|
// Get linkType
|
|
RevitLinkType type = doc.GetElement(
|
|
instance.GetTypeId()) as RevitLinkType;
|
|
|
|
// Check if link is loaded
|
|
if (RevitLinkType.IsLoaded(doc, type.Id))
|
|
{
|
|
// 링크된 벽
|
|
FilteredElementCollector walls
|
|
= new FilteredElementCollector(linkDoc)
|
|
.OfCategory(BuiltInCategory.OST_Walls)
|
|
.OfClass(typeof(Wall));
|
|
// Create reference
|
|
foreach (Wall wall in walls)
|
|
{
|
|
Reference newRef = new Reference(wall).CreateLinkReference(instance);
|
|
m_walls.Add(wall);
|
|
if (rliRefFace.Contains(wall.Id) == false)
|
|
{
|
|
rliRefFace.Add(wall.Id, instance);
|
|
}
|
|
}
|
|
// 링크된 바닥
|
|
FilteredElementCollector floors
|
|
= new FilteredElementCollector(linkDoc)
|
|
.OfCategory(BuiltInCategory.OST_Floors)
|
|
.OfClass(typeof(Floor));
|
|
// Create reference
|
|
foreach (Floor floor in floors)
|
|
{
|
|
Reference newRef = new Reference(floor).CreateLinkReference(instance);
|
|
m_floors.Add(floor);
|
|
if (rliRefFace.Contains(floor.Id) == false)
|
|
{
|
|
rliRefFace.Add(floor.Id, instance);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
public void open()
|
|
{
|
|
string location = Util.GetKMBIMLibraryFolder("\\Libraries\\Insulation");
|
|
string jsonPath = Path.Combine(location, "settings.kins");
|
|
//DirectoryInfo 생성
|
|
DirectoryInfo di = new DirectoryInfo(location);
|
|
//DirectoryInfo.Exists로 폴더 존재유무 확인
|
|
if (!di.Exists) { di.Create(); }
|
|
|
|
|
|
|
|
if (File.Exists(jsonPath))
|
|
{
|
|
using (StreamReader r = new StreamReader(jsonPath))
|
|
{
|
|
|
|
using (JsonTextReader reader1 = new JsonTextReader(r))
|
|
{
|
|
JValue o2 = (JValue)JToken.ReadFrom(reader1);
|
|
string strJson = o2.ToString();
|
|
PipeData.LoadJson(strJson);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
public double GetInsulationThickness(Element el)
|
|
{
|
|
double dblThickness = 0;
|
|
ICollection<ElementId> insulationIds = InsulationLiningBase.GetInsulationIds(doc, el.Id);
|
|
Pipe pipe = el as Pipe;
|
|
Duct duct = el as Duct;
|
|
if (pipe != null)
|
|
{
|
|
if (insulationIds.Count > 0)
|
|
{
|
|
foreach (ElementId insulationId in insulationIds)
|
|
{
|
|
Element insEl = doc.GetElement(insulationId);
|
|
Autodesk.Revit.DB.Plumbing.PipeInsulation insulation = insEl as Autodesk.Revit.DB.Plumbing.PipeInsulation;
|
|
|
|
if (insulation != null)
|
|
{
|
|
//using (Transaction tr = new Transaction(doc))
|
|
//{
|
|
// tr.Start("InsulationPipe");
|
|
dblThickness = insulation.Thickness;
|
|
// tr.Commit();
|
|
break;
|
|
// }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (duct != null)
|
|
{
|
|
if (insulationIds.Count > 0)
|
|
{
|
|
foreach (ElementId insulationId in insulationIds)
|
|
{
|
|
Element insEl = doc.GetElement(insulationId);
|
|
Autodesk.Revit.DB.Mechanical.DuctInsulation insulation = insEl as Autodesk.Revit.DB.Mechanical.DuctInsulation;
|
|
|
|
if (insulation != null)
|
|
{
|
|
//using (Transaction tr = new Transaction(doc))
|
|
//{
|
|
// tr.Start("InsulationPipe");
|
|
// dblThickness = insulation.Thickness;
|
|
// tr.Commit();
|
|
break;
|
|
// }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return dblThickness;
|
|
}
|
|
public void SetInsulation(Element el)
|
|
{
|
|
string category = KDCS.Utils.Reg.getReg("kdcsInsulationDefaultType");
|
|
if (category.CompareTo("") == 0) { return; }
|
|
if (el is Pipe)
|
|
{
|
|
if (!bApplyPipe) return;
|
|
ICollection<ElementId> insulationIds = InsulationLiningBase.GetInsulationIds(doc, el.Id);
|
|
Pipe pipe = el as Pipe;
|
|
if (insulationIds.Count > 0)
|
|
{
|
|
foreach (ElementId insulationId in insulationIds)
|
|
{
|
|
Element insEl = doc.GetElement(insulationId);
|
|
Autodesk.Revit.DB.Plumbing.PipeInsulation insulation = insEl as Autodesk.Revit.DB.Plumbing.PipeInsulation;
|
|
|
|
if (insulation != null)
|
|
{
|
|
if (GetPipeInsulationType(PipeData.Find(category, true, pipe.PipeType.Name).strLaggingType).Id != null)
|
|
{
|
|
if (!bKeepInsulation)
|
|
{
|
|
Autodesk.Revit.DB.Parameter pram = pipe.get_Parameter(BuiltInParameter.RBS_PIPE_DIAMETER_PARAM);
|
|
double dia = Unit.FeetToMM(pram.AsDouble());
|
|
var tmp = PipeData.Find(category, true, pipe.PipeType.Name).BoreList.Find(i => i.nDiameter == dia);
|
|
if (tmp != null)
|
|
{
|
|
if (tmp.dblThickness > 0)
|
|
{
|
|
insulation.ChangeTypeId(GetPipeInsulationType(PipeData.Find(category, true, pipe.PipeType.Name).strLaggingType).Id);
|
|
insulation.Thickness = Unit.MMToFeet(tmp.dblThickness);
|
|
}
|
|
else
|
|
{
|
|
doc.Delete(insulationId);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (GetPipeInsulationType(PipeData.Find(category, true, pipe.PipeType.Name).strLaggingType).Id != null)
|
|
{
|
|
|
|
Autodesk.Revit.DB.Parameter pram = pipe.get_Parameter(BuiltInParameter.RBS_PIPE_DIAMETER_PARAM);
|
|
double dia = Unit.FeetToMM(pram.AsDouble());
|
|
var tmp = PipeData.Find(category, true, pipe.PipeType.Name).BoreList.Find(i => i.nDiameter == dia);
|
|
if (tmp != null)
|
|
{
|
|
if (tmp.dblThickness > 0)
|
|
{
|
|
PipeInsulation.Create(doc,
|
|
el.Id,
|
|
GetPipeInsulationType(PipeData.Find(category, true, pipe.PipeType.Name).strLaggingType).Id,
|
|
Unit.MMToFeet(tmp.dblThickness));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else if (el is Duct)
|
|
{
|
|
if (!bApplyDuct) return;
|
|
ICollection<ElementId> insulationIds = InsulationLiningBase.GetInsulationIds(doc, el.Id);
|
|
Duct duct = el as Duct;
|
|
if (insulationIds.Count > 0)
|
|
{
|
|
foreach (ElementId insulationId in insulationIds)
|
|
{
|
|
Element insEl = doc.GetElement(insulationId);
|
|
Autodesk.Revit.DB.Mechanical.DuctInsulation insulation = insEl as Autodesk.Revit.DB.Mechanical.DuctInsulation;
|
|
|
|
|
|
if (insulation != null)
|
|
{
|
|
if (GetDuctInsulationType(PipeData.Find(category, false, duct.DuctType.Name).strLaggingType).Id != null)
|
|
{
|
|
if (!bKeepInsulation)
|
|
{
|
|
double dblThickness = PipeData.Find(category, false, duct.DuctType.Name).dblLaggingThickness;
|
|
if (dblThickness > 0)
|
|
{
|
|
insulation.ChangeTypeId(GetDuctInsulationType(PipeData.Find(category, false, duct.DuctType.Name).strLaggingType).Id);
|
|
insulation.Thickness = Unit.MMToFeet(PipeData.Find(category, false, duct.DuctType.Name).dblLaggingThickness);
|
|
}
|
|
else
|
|
{
|
|
doc.Delete(insulationId);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
string strLaggingType = PipeData.Find(category, false, duct.DuctType.Name).strLaggingType;
|
|
Element InsulType = GetDuctInsulationType(strLaggingType);
|
|
if (InsulType.Id != null)
|
|
{
|
|
|
|
double dblThickness = PipeData.Find(category, false, duct.DuctType.Name).dblLaggingThickness;
|
|
if (dblThickness > 0)
|
|
{
|
|
DuctInsulation.Create(doc, el.Id, InsulType.Id, Unit.MMToFeet(dblThickness));
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
}//end-if
|
|
else if (el is FamilyInstance)
|
|
{
|
|
Duct duct = null;
|
|
Pipe pipe = null;
|
|
|
|
FamilyInstance familyInstance = el as FamilyInstance;
|
|
|
|
if (familyInstance.Category.Id.IntegerValue == (int)BuiltInCategory.OST_DuctFitting ||
|
|
familyInstance.Category.Id.IntegerValue == (int)BuiltInCategory.OST_PipeAccessory ||
|
|
familyInstance.Category.Id.IntegerValue == (int)BuiltInCategory.OST_PipeFitting ||
|
|
familyInstance.Category.Id.IntegerValue == (int)BuiltInCategory.OST_DuctAccessory)
|
|
{
|
|
ICollection<ElementId> insulationIds = InsulationLiningBase.GetInsulationIds(doc, el.Id);
|
|
var ConnectorList = Util.GetElementConnectors(el);
|
|
foreach (var item in ConnectorList)
|
|
{
|
|
Connector connect = Util.GetNextElementConnector(item);
|
|
if (connect == null) continue;
|
|
if (connect.Owner != null)
|
|
{
|
|
if (connect.Owner is Duct)
|
|
{
|
|
duct = connect.Owner as Duct;
|
|
break;
|
|
}
|
|
if (connect.Owner is Pipe)
|
|
{
|
|
pipe = connect.Owner as Pipe;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (duct == null && pipe == null) return;
|
|
if (familyInstance.Category.Id.IntegerValue == (int)BuiltInCategory.OST_DuctFitting)
|
|
{
|
|
if (!bApplyDuct) return;
|
|
if (duct == null) return;
|
|
ICollection<ElementId> insulationIds = InsulationLiningBase.GetInsulationIds(doc, el.Id);
|
|
if (insulationIds.Count > 0)
|
|
{
|
|
if (bKeepInsulation) return;
|
|
foreach (ElementId insulationId in insulationIds)
|
|
{
|
|
Element insEl = doc.GetElement(insulationId);
|
|
Autodesk.Revit.DB.Mechanical.DuctInsulation insulation = insEl as Autodesk.Revit.DB.Mechanical.DuctInsulation;
|
|
|
|
|
|
if (insulation != null)
|
|
{
|
|
if (GetDuctInsulationType(PipeData.Find(category, false, duct.DuctType.Name).strLaggingType).Id != null)
|
|
{
|
|
if (!bKeepInsulation)
|
|
{
|
|
double dblThickness = PipeData.Find(category, false, duct.DuctType.Name).dblLaggingThickness;
|
|
if (dblThickness > 0)
|
|
{
|
|
insulation.ChangeTypeId(GetDuctInsulationType(PipeData.Find(category, false, duct.DuctType.Name).strLaggingType).Id);
|
|
insulation.Thickness = Unit.MMToFeet(dblThickness);
|
|
}
|
|
else
|
|
{
|
|
doc.Delete(insulationId);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
|
|
string strLaggingType = PipeData.Find(category, false, duct.DuctType.Name).strLaggingType;
|
|
Element InsulType = GetDuctInsulationType(strLaggingType);
|
|
if (InsulType.Id != null)
|
|
{
|
|
double dblThickness = PipeData.Find(category, false, duct.DuctType.Name).dblLaggingThickness;
|
|
if (dblThickness > 0)
|
|
{
|
|
DuctInsulation.Create(doc, el.Id, InsulType.Id, Unit.MMToFeet(dblThickness));
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
else if (familyInstance.Category.Id.IntegerValue == (int)BuiltInCategory.OST_PipeAccessory)
|
|
{
|
|
if (!bApplyPipe) return;
|
|
if (pipe == null) return;
|
|
ICollection<ElementId> insulationIds = InsulationLiningBase.GetInsulationIds(doc, el.Id);
|
|
if (insulationIds.Count > 0)
|
|
{
|
|
if (bKeepInsulation) return;
|
|
foreach (ElementId insulationId in insulationIds)
|
|
{
|
|
Element insEl = doc.GetElement(insulationId);
|
|
Autodesk.Revit.DB.Plumbing.PipeInsulation insulation = insEl as Autodesk.Revit.DB.Plumbing.PipeInsulation;
|
|
|
|
|
|
if (insulation != null)
|
|
{
|
|
if (GetPipeInsulationType(PipeData.Find(category, true, pipe.PipeType.Name).strLaggingType).Id != null)
|
|
{
|
|
if (!bKeepInsulation)
|
|
{
|
|
Autodesk.Revit.DB.Parameter pram = pipe.get_Parameter(BuiltInParameter.RBS_PIPE_DIAMETER_PARAM);
|
|
double dia = Unit.FeetToMM(pram.AsDouble());
|
|
var tmp = PipeData.Find(category, true, pipe.PipeType.Name).BoreList.Find(i => i.nDiameter == dia);
|
|
if (tmp != null)
|
|
{
|
|
if (tmp.dblThickness > 0)
|
|
{
|
|
insulation.ChangeTypeId(GetPipeInsulationType(PipeData.Find(category, true, pipe.PipeType.Name).strLaggingType).Id);
|
|
insulation.Thickness = Unit.MMToFeet(tmp.dblThickness);
|
|
}
|
|
else
|
|
{
|
|
doc.Delete(insulationId);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
|
|
string strLaggingType = PipeData.Find(category, true, pipe.PipeType.Name).strLaggingType;
|
|
Element InsulType = GetPipeInsulationType(strLaggingType);
|
|
if (InsulType.Id != null)
|
|
{
|
|
Autodesk.Revit.DB.Parameter pram = pipe.get_Parameter(BuiltInParameter.RBS_PIPE_DIAMETER_PARAM);
|
|
double dia = Unit.FeetToMM(pram.AsDouble());
|
|
var tmp = PipeData.Find(category, true, pipe.PipeType.Name).BoreList.Find(i => i.nDiameter == dia);
|
|
if (tmp != null)
|
|
{
|
|
if (tmp.dblThickness > 0)
|
|
{
|
|
PipeInsulation.Create(doc, el.Id, InsulType.Id, Unit.MMToFeet(tmp.dblThickness));
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
else if (familyInstance.Category.Id.IntegerValue == (int)BuiltInCategory.OST_PipeFitting)
|
|
{
|
|
if (!bApplyPipe) return;
|
|
if (pipe == null) return;
|
|
ICollection<ElementId> insulationIds = InsulationLiningBase.GetInsulationIds(doc, el.Id);
|
|
if (insulationIds.Count > 0)
|
|
{
|
|
if (bKeepInsulation) return;
|
|
foreach (ElementId insulationId in insulationIds)
|
|
{
|
|
Element insEl = doc.GetElement(insulationId);
|
|
Autodesk.Revit.DB.Plumbing.PipeInsulation insulation = insEl as Autodesk.Revit.DB.Plumbing.PipeInsulation;
|
|
|
|
|
|
if (insulation != null)
|
|
{
|
|
if (GetPipeInsulationType(PipeData.Find(category, true, pipe.PipeType.Name).strLaggingType).Id != null)
|
|
{
|
|
if (!bKeepInsulation)
|
|
{
|
|
Autodesk.Revit.DB.Parameter pram = pipe.get_Parameter(BuiltInParameter.RBS_PIPE_DIAMETER_PARAM);
|
|
double dia = Unit.FeetToMM(pram.AsDouble());
|
|
var tmp = PipeData.Find(category, true, pipe.PipeType.Name).BoreList.Find(i => i.nDiameter == dia);
|
|
if (tmp != null)
|
|
{
|
|
if (tmp.dblThickness > 0)
|
|
{
|
|
insulation.ChangeTypeId(GetPipeInsulationType(PipeData.Find(category, true, pipe.PipeType.Name).strLaggingType).Id);
|
|
insulation.Thickness = Unit.MMToFeet(tmp.dblThickness);
|
|
}
|
|
else
|
|
{
|
|
doc.Delete(insulationId);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
|
|
string strLaggingType = PipeData.Find(category, true, pipe.PipeType.Name).strLaggingType;
|
|
Element InsulType = GetPipeInsulationType(strLaggingType);
|
|
if (InsulType.Id != null)
|
|
{
|
|
Autodesk.Revit.DB.Parameter pram = pipe.get_Parameter(BuiltInParameter.RBS_PIPE_DIAMETER_PARAM);
|
|
double dia = Unit.FeetToMM(pram.AsDouble());
|
|
var tmp = PipeData.Find(category, true, pipe.PipeType.Name).BoreList.Find(i => i.nDiameter == dia);
|
|
if (tmp != null)
|
|
{
|
|
if (tmp.dblThickness > 0)
|
|
{
|
|
PipeInsulation.Create(doc, el.Id, InsulType.Id, Unit.MMToFeet(tmp.dblThickness));
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
else if (familyInstance.Category.Id.IntegerValue == (int)BuiltInCategory.OST_DuctAccessory)
|
|
{
|
|
if (!bApplyDuct) return;
|
|
if (duct == null) return;
|
|
ICollection<ElementId> insulationIds = InsulationLiningBase.GetInsulationIds(doc, el.Id);
|
|
if (insulationIds.Count > 0)
|
|
{
|
|
if (bKeepInsulation) return;
|
|
foreach (ElementId insulationId in insulationIds)
|
|
{
|
|
Element insEl = doc.GetElement(insulationId);
|
|
Autodesk.Revit.DB.Mechanical.DuctInsulation insulation = insEl as Autodesk.Revit.DB.Mechanical.DuctInsulation;
|
|
|
|
|
|
if (insulation != null)
|
|
{
|
|
if (GetDuctInsulationType(PipeData.Find(category, false, duct.DuctType.Name).strLaggingType).Id != null)
|
|
{
|
|
if (!bKeepInsulation)
|
|
{
|
|
double dblThickness = PipeData.Find(category, false, duct.DuctType.Name).dblLaggingThickness;
|
|
if (dblThickness > 0)
|
|
{
|
|
insulation.ChangeTypeId(GetDuctInsulationType(PipeData.Find(category, false, duct.DuctType.Name).strLaggingType).Id);
|
|
insulation.Thickness = Unit.MMToFeet(dblThickness);
|
|
}
|
|
else
|
|
{
|
|
doc.Delete(insulationId);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
else
|
|
{
|
|
|
|
string strLaggingType = PipeData.Find(category, false, duct.DuctType.Name).strLaggingType;
|
|
Element InsulType = GetDuctInsulationType(strLaggingType);
|
|
if (InsulType.Id != null)
|
|
{
|
|
double dblThickness = PipeData.Find(category, false, duct.DuctType.Name).dblLaggingThickness;
|
|
if (dblThickness > 0)
|
|
{
|
|
DuctInsulation.Create(doc, el.Id, InsulType.Id, Unit.MMToFeet(dblThickness));
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
public Element GetPipeInsulationType(string strInsulationType)
|
|
{
|
|
foreach (var item in PipeinsulationCollection)
|
|
{
|
|
if (item.Name.CompareTo(strInsulationType) == 0)
|
|
{
|
|
return item;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
public Element GetDuctInsulationType(string strInsulationType)
|
|
{
|
|
foreach (var item in DuctinsulationCollection)
|
|
{
|
|
if (item.Name.CompareTo(strInsulationType) == 0)
|
|
{
|
|
return item;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
}
|
|
|
|
public class PipeDuctSelectionFilter : ISelectionFilter
|
|
{
|
|
public bool AllowElement(Element element)
|
|
{
|
|
if (element.Category == null) return false;
|
|
if (element.Category.Id.IntegerValue == (int)BuiltInCategory.OST_DuctCurves)
|
|
{
|
|
return true;
|
|
}
|
|
else if (element.Category.Id.IntegerValue == (int)BuiltInCategory.OST_PipeCurves)
|
|
{
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
public bool AllowReference(Reference refer, XYZ point)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|