155 lines
5.8 KiB
C#
155 lines
5.8 KiB
C#
using Autodesk.Revit.DB;
|
|
using Autodesk.Revit.DB.ExtensibleStorage;
|
|
using KDCS.Utils;
|
|
using KMBIM.Revit.Tools.Cmd.Hanger;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace KMBIM.Revit.Tools.Utils
|
|
{
|
|
public class HangerFamilySymbol
|
|
{
|
|
public static HashSet<Autodesk.Revit.DB.ElementId> a(Document A_0)
|
|
{
|
|
if (A_0 == null || A_0.ProjectInformation == null)
|
|
{
|
|
return null;
|
|
}
|
|
HashSet<Autodesk.Revit.DB.ElementId> hashSet = new HashSet<Autodesk.Revit.DB.ElementId>();
|
|
List<string> contents = Util.GetLibrary("Libraries\\Hanger", false);
|
|
Autodesk.Revit.DB.FilteredElementIterator elementIterator = new Autodesk.Revit.DB.FilteredElementCollector(A_0).OfClass(typeof(Autodesk.Revit.DB.FamilySymbol)).GetElementIterator();
|
|
while (elementIterator.MoveNext())
|
|
{
|
|
Autodesk.Revit.DB.FamilySymbol familySymbol = elementIterator.Current as Autodesk.Revit.DB.FamilySymbol;
|
|
if (familySymbol != null && familySymbol.Family != null && contents.Contains(familySymbol.Family.Name))
|
|
{
|
|
hashSet.Add(familySymbol.Id);
|
|
}
|
|
}
|
|
return hashSet;
|
|
}
|
|
|
|
public static bool SetSymbolIds(Document A_0, KMBIM.Revit.Tools.Cmd.Hanger.MEPCurveType A_1, Autodesk.Revit.DB.ElementId A_2, bool A_3)
|
|
{
|
|
if (A_0 == null || A_0.ProjectInformation == null || A_1 == KMBIM.Revit.Tools.Cmd.Hanger.MEPCurveType.UnDefined)
|
|
{
|
|
return false;
|
|
}
|
|
Autodesk.Revit.DB.Transaction transaction = null;
|
|
if (!A_3)
|
|
{
|
|
transaction = new Autodesk.Revit.DB.Transaction(A_0, "Set Symbol Ids");
|
|
transaction.Start();
|
|
}
|
|
IList<Autodesk.Revit.DB.ElementId> list = null;
|
|
Field field = HangerSchema.SetHangerSymbolIdsSchema().GetField("SymbolIds");
|
|
Entity entity = A_0.ProjectInformation.GetEntity(HangerSchema.SetHangerSymbolIdsSchema());
|
|
if (entity != null && entity.IsValid())
|
|
{
|
|
list = entity.Get<IList<Autodesk.Revit.DB.ElementId>>(field);
|
|
if (list.Count < 6)
|
|
{
|
|
list.Clear();
|
|
for (int i = 0; i < 6; i++)
|
|
{
|
|
list.Add(Autodesk.Revit.DB.ElementId.InvalidElementId);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
entity = new Entity(HangerSchema.SetHangerSymbolIdsSchema());
|
|
list = new List<Autodesk.Revit.DB.ElementId>();
|
|
for (int j = 0; j < 6; j++)
|
|
{
|
|
list.Add(Autodesk.Revit.DB.ElementId.InvalidElementId);
|
|
}
|
|
}
|
|
list[(int)(A_1 - 1)] = A_2;
|
|
entity.Set(field, list);
|
|
A_0.ProjectInformation.SetEntity(entity);
|
|
if (transaction != null) transaction.Commit();
|
|
return true;
|
|
}
|
|
|
|
public static Autodesk.Revit.DB.ElementId GetSymbolIds(Document A_0, KMBIM.Revit.Tools.Cmd.Hanger.MEPCurveType A_1)
|
|
{
|
|
if (A_0 == null || A_0.ProjectInformation == null || A_1 == KMBIM.Revit.Tools.Cmd.Hanger.MEPCurveType.UnDefined)
|
|
{
|
|
return Autodesk.Revit.DB.ElementId.InvalidElementId;
|
|
}
|
|
Entity entity = A_0.ProjectInformation.GetEntity(HangerSchema.SetHangerSymbolIdsSchema());
|
|
if (entity == null || !entity.IsValid())
|
|
{
|
|
return Autodesk.Revit.DB.ElementId.InvalidElementId;
|
|
}
|
|
Field field = HangerSchema.SetHangerSymbolIdsSchema().GetField("SymbolIds");
|
|
IList<Autodesk.Revit.DB.ElementId> list = entity.Get<IList<Autodesk.Revit.DB.ElementId>>(field);
|
|
if (list == null || list.Count < 6)
|
|
{
|
|
return Autodesk.Revit.DB.ElementId.InvalidElementId;
|
|
}
|
|
return list[(int)(A_1 - 1)];
|
|
}
|
|
|
|
internal static BuiltInCategory GetBuiltInCategory(KMBIM.Revit.Tools.Cmd.Hanger.MEPCurveType mepCrvType)
|
|
{
|
|
BuiltInCategory biCat = BuiltInCategory.OST_DuctAccessory;
|
|
|
|
switch(mepCrvType){
|
|
case KMBIM.Revit.Tools.Cmd.Hanger.MEPCurveType.Pipe:
|
|
biCat = BuiltInCategory.OST_PipeAccessory; break;
|
|
case KMBIM.Revit.Tools.Cmd.Hanger.MEPCurveType.Conduit:
|
|
biCat = BuiltInCategory.OST_ConduitFitting; break;
|
|
case KMBIM.Revit.Tools.Cmd.Hanger.MEPCurveType.CableTray:
|
|
biCat = BuiltInCategory.OST_CableTrayFitting; break;
|
|
default:
|
|
biCat = BuiltInCategory.OST_DuctAccessory; break;
|
|
}
|
|
|
|
return biCat;
|
|
}
|
|
|
|
internal static Autodesk.Revit.DB.FamilySymbol GetFamilysymbol(Document document, KMBIM.Revit.Tools.Cmd.Hanger.MEPCurveType mepCurveType, string familyName)
|
|
{
|
|
Autodesk.Revit.DB.FilteredElementIterator elementIterator = new Autodesk.Revit.DB.FilteredElementCollector(document).OfClass(typeof(Autodesk.Revit.DB.FamilySymbol)).GetElementIterator();
|
|
while (elementIterator.MoveNext())
|
|
{
|
|
Autodesk.Revit.DB.FamilySymbol familySymbol = elementIterator.Current as Autodesk.Revit.DB.FamilySymbol;
|
|
if (familySymbol != null && familySymbol.Family != null && familySymbol.Family.Name == familyName)
|
|
{
|
|
return familySymbol;
|
|
}
|
|
}
|
|
|
|
var versionNumber = document.Application.VersionNumber.ToString();
|
|
string text = Path.Combine(KMBIM.Revit.Tools.Cmd.Hanger.HangerSettings.GetHangerFolder()+"\\" + versionNumber, familyName + ".rfa");
|
|
if (!File.Exists(text))
|
|
{
|
|
return null;
|
|
}
|
|
Autodesk.Revit.DB.Family family = null;
|
|
if (document.LoadFamily(text, out family))
|
|
{
|
|
Autodesk.Revit.DB.FamilySymbol result = null;
|
|
var enumerator = Util.GetFamilySymbols(document, family).GetEnumerator();
|
|
if (enumerator.MoveNext())
|
|
{
|
|
result = enumerator.Current;
|
|
Util.Activate(result);
|
|
return result;
|
|
}
|
|
return result;
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|