851 lines
33 KiB
C#
851 lines
33 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Runtime.CompilerServices;
|
|
using Autodesk.Revit.DB;
|
|
using Autodesk.Revit.DB.ExtensibleStorage;
|
|
using Autodesk.Revit.DB.Mechanical;
|
|
using Autodesk.Revit.DB.Plumbing;
|
|
using Autodesk.Revit.DB.Structure;
|
|
using KDCS.Utils;
|
|
|
|
|
|
namespace KMBIM.Revit.Tools.Cmd.Hanger
|
|
{
|
|
class HangerSchema
|
|
{
|
|
|
|
private static Autodesk.Revit.DB.AddInId _AddInId;
|
|
|
|
|
|
private static Autodesk.Revit.DB.UpdaterId _UpdaterId;
|
|
|
|
|
|
private static Schema HangerDataSchema;
|
|
|
|
|
|
private static Schema HangerParentIdAndRelPosSchema;
|
|
|
|
|
|
private static Schema HangerAttachTypeSchema;
|
|
|
|
|
|
private static Schema HangerSymbolIdsSchema;
|
|
|
|
|
|
public static Autodesk.Revit.DB.AddInId GetAddInId()
|
|
{
|
|
return HangerSchema._AddInId;
|
|
}
|
|
|
|
|
|
public static void SetAddInId(Autodesk.Revit.DB.AddInId id)
|
|
{
|
|
HangerSchema._AddInId = id;
|
|
}
|
|
|
|
|
|
public static Autodesk.Revit.DB.UpdaterId GetUpdaterId()
|
|
{
|
|
return HangerSchema._UpdaterId;
|
|
}
|
|
|
|
|
|
public static void SetUpdaterId(Autodesk.Revit.DB.UpdaterId id)
|
|
{
|
|
HangerSchema._UpdaterId = id;
|
|
}
|
|
|
|
|
|
public static Schema GetHangerDataSchema()
|
|
{
|
|
return HangerSchema.HangerDataSchema;
|
|
}
|
|
|
|
|
|
public static void SetHangerDataSchema(Schema schema)
|
|
{
|
|
HangerSchema.HangerDataSchema = schema;
|
|
}
|
|
|
|
|
|
public static Schema GetHangerRelPosSchema()
|
|
{
|
|
return HangerSchema.HangerParentIdAndRelPosSchema;
|
|
}
|
|
|
|
|
|
public static void SetHangerRelPosSchema(Schema schema)
|
|
{
|
|
HangerSchema.HangerParentIdAndRelPosSchema = schema;
|
|
}
|
|
|
|
|
|
public static Schema GetHangerInstallBaseSchema()
|
|
{
|
|
return HangerSchema.HangerAttachTypeSchema;
|
|
}
|
|
|
|
|
|
public static void SetHangerInstallBaseSchema(Schema schema)
|
|
{
|
|
HangerSchema.HangerAttachTypeSchema = schema;
|
|
}
|
|
|
|
|
|
public static Schema SetHangerSymbolIdsSchema()
|
|
{
|
|
return HangerSchema.HangerSymbolIdsSchema;
|
|
}
|
|
|
|
|
|
public static void SetHangerSymbolIdsSchema(Schema schema)
|
|
{
|
|
HangerSchema.HangerSymbolIdsSchema = schema;
|
|
}
|
|
|
|
public static void Init()
|
|
{
|
|
AddInId mAddInId = GetAddInId();
|
|
Guid mAddInGUID = mAddInId.GetGUID();
|
|
SetUpdaterId(new Autodesk.Revit.DB.UpdaterId(mAddInId, new Guid("{11AD1549-4715-4AD4-AB69-7C1BBAAF520D}")));
|
|
|
|
|
|
Guid schemaId1 = new Guid("{4D6D9075-7A12-4D38-8CFB-EFE929329710}");
|
|
Schema schema1 = Schema.Lookup(schemaId1);
|
|
if (schema1 == null)
|
|
{
|
|
SchemaBuilder schemaBuilder = new SchemaBuilder(schemaId1);
|
|
schemaBuilder.SetSchemaName("KMBIMHangerData");
|
|
schemaBuilder.AddArrayField("KMBIMHangerIds", typeof(Autodesk.Revit.DB.ElementId));
|
|
schemaBuilder.SetVendorId("KMBIM");
|
|
schemaBuilder.SetApplicationGUID(mAddInGUID);
|
|
schema1 = schemaBuilder.Finish();
|
|
}
|
|
SetHangerDataSchema(schema1);
|
|
|
|
|
|
Guid schemaId2 = new Guid("{C499DC95-A5A4-4646-86F5-673FB2BC13C6}");
|
|
Schema schema2 = Schema.Lookup(schemaId2);
|
|
if (schema2 == null)
|
|
{
|
|
SchemaBuilder schemaBuilder = new SchemaBuilder(schemaId2);
|
|
schemaBuilder.SetSchemaName("KMBIMHangerRelPos");
|
|
schemaBuilder.AddSimpleField("ParentId", typeof(Autodesk.Revit.DB.ElementId));
|
|
#if _22 || _23
|
|
//schemaBuilder.AddSimpleField("RelDist", typeof(double)).SetSpec(UnitTypeId.Feet);
|
|
schemaBuilder.AddSimpleField("RelDist", typeof(double)).SetSpec(SpecTypeId.Length);
|
|
#else
|
|
schemaBuilder.AddSimpleField("RelDist", typeof(double)).SetUnitType(Autodesk.Revit.DB.UnitType.UT_Length);
|
|
#endif
|
|
|
|
|
|
schemaBuilder.SetVendorId("KMBIM");
|
|
schemaBuilder.SetApplicationGUID(mAddInGUID);
|
|
schema2 = schemaBuilder.Finish();
|
|
}
|
|
SetHangerRelPosSchema(schema2);
|
|
|
|
|
|
Guid schemaId3 = new Guid("{78F46BF0-EBDE-44C5-A69E-11812594AA44}");
|
|
Schema schema3 = Schema.Lookup(schemaId3);
|
|
if (schema3 == null)
|
|
{
|
|
SchemaBuilder schemaBuilder = new SchemaBuilder(schemaId3);
|
|
schemaBuilder.SetSchemaName("KMBIMHangerInstallBase");
|
|
schemaBuilder.AddSimpleField("AnchorInstallBase", typeof(string));
|
|
schemaBuilder.SetVendorId("KMBIM");
|
|
schemaBuilder.SetApplicationGUID(mAddInGUID);
|
|
schema3 = schemaBuilder.Finish();
|
|
}
|
|
SetHangerInstallBaseSchema(schema3);
|
|
|
|
Guid schemaId4 = new Guid("{27F334AA-D0D8-4D82-B894-177D54E12221}");
|
|
Schema schema4 = Schema.Lookup(schemaId4);
|
|
if (schema4 == null)
|
|
{
|
|
SchemaBuilder schemaBuilder = new SchemaBuilder(schemaId4);
|
|
schemaBuilder.SetSchemaName("KIMBIMSymbolData");
|
|
schemaBuilder.AddArrayField("SymbolIds", typeof(Autodesk.Revit.DB.ElementId));
|
|
schemaBuilder.SetVendorId("KMBIM");
|
|
schemaBuilder.SetApplicationGUID(mAddInGUID);
|
|
schema4 = schemaBuilder.Finish();
|
|
}
|
|
SetHangerSymbolIdsSchema(schema4);
|
|
}
|
|
|
|
public static void g(Autodesk.Revit.DB.Element element)
|
|
{
|
|
Schema schema = GetHangerDataSchema();
|
|
Entity entity = element.GetEntity(schema);
|
|
if (entity == null || !entity.IsValid())
|
|
{
|
|
return;
|
|
}
|
|
Field field = GetHangerDataSchema().GetField("KMBIMHangerIds");
|
|
IList<Autodesk.Revit.DB.ElementId> list = entity.Get<IList<Autodesk.Revit.DB.ElementId>>(field);
|
|
if (list == null || list.Count == 0)
|
|
{
|
|
return;
|
|
}
|
|
List<Autodesk.Revit.DB.ElementId> list2 = new List<Autodesk.Revit.DB.ElementId>();
|
|
foreach (Autodesk.Revit.DB.ElementId item in list)
|
|
{
|
|
if (item != Autodesk.Revit.DB.ElementId.InvalidElementId)
|
|
{
|
|
list2.Add(item);
|
|
}
|
|
}
|
|
if (list2.Count > 0)
|
|
{
|
|
element.Document.Delete(list2);
|
|
}
|
|
list.Clear();
|
|
entity.Set(field, list);
|
|
element.SetEntity(entity);
|
|
}
|
|
|
|
public static IList<Autodesk.Revit.DB.ElementId> f(Autodesk.Revit.DB.Element A_0)
|
|
{
|
|
Entity entity = A_0.GetEntity(GetHangerDataSchema());
|
|
if (entity == null)
|
|
{
|
|
return null;
|
|
}
|
|
Field field = GetHangerDataSchema().GetField("KMBIMHangerIds");
|
|
if (entity.IsValid())
|
|
{
|
|
return entity.Get<IList<Autodesk.Revit.DB.ElementId>>(field);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static bool e(Autodesk.Revit.DB.Element A_0)
|
|
{
|
|
if (A_0 == null)
|
|
{
|
|
return false;
|
|
}
|
|
if (!(A_0 is MEPCurve))
|
|
{
|
|
return false;
|
|
}
|
|
if (A_0 is FlexPipe)
|
|
{
|
|
return false;
|
|
}
|
|
if (A_0 is FlexDuct)
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
private static EnumAnchorInstallBase GetAttachType(Autodesk.Revit.DB.Element A_0, EnumAnchorInstallBase A_1)
|
|
{
|
|
Entity entity = A_0.GetEntity(GetHangerInstallBaseSchema());
|
|
if (entity == null || !entity.IsValid())
|
|
{
|
|
return A_1;
|
|
}
|
|
if (!(entity.Get<string>("AnchorInstallBase") == EnumAnchorInstallBase.Structrual.ToString()))
|
|
{
|
|
return EnumAnchorInstallBase.Level;
|
|
}
|
|
return EnumAnchorInstallBase.Structrual;
|
|
}
|
|
|
|
public static bool SetParameter(Autodesk.Revit.DB.Element element1, Autodesk.Revit.DB.Element element2, View3DHanger view3dHanger, HangerSettings A_3)
|
|
{
|
|
if (element1 == null || element2 == null)
|
|
{
|
|
return true;
|
|
}
|
|
Autodesk.Revit.DB.FamilyInstance familyInstance = element1 as Autodesk.Revit.DB.FamilyInstance;
|
|
if (familyInstance == null)
|
|
{
|
|
return true;
|
|
}
|
|
Entity entity = familyInstance.GetEntity(GetHangerRelPosSchema());
|
|
if (entity == null || !entity.IsValid())
|
|
{
|
|
return false;
|
|
}
|
|
Autodesk.Revit.DB.XYZ origin = familyInstance.GetTransform().Origin;
|
|
Autodesk.Revit.DB.Level level = familyInstance.Document.GetElement(familyInstance.LevelId) as Autodesk.Revit.DB.Level;
|
|
Autodesk.Revit.DB.XYZ a_ = new Autodesk.Revit.DB.XYZ(origin.X, origin.Y, c(familyInstance) + (level != null ? level.ProjectElevation : 0.0));
|
|
Line line = GetLine(element2);
|
|
if (line == null)
|
|
{
|
|
return false;
|
|
}
|
|
double A_4 = 0.0;
|
|
Autodesk.Revit.DB.XYZ xYZ = GetIntersectionPoint(a_, line, ref A_4);
|
|
if (A_4 <= 0.001 || line.ApproximateLength < A_4 + 0.001)
|
|
{
|
|
b(element2, familyInstance);
|
|
return true;
|
|
}
|
|
HangerFamily hangerFamily = new HangerFamily(null);
|
|
hangerFamily.SetView3dHanger(view3dHanger);
|
|
|
|
|
|
hangerFamily.SetFamilySymbol(familyInstance.Symbol);
|
|
if (!hangerFamily.getSize(element2, A_3))
|
|
{
|
|
SetSize(element2, familyInstance);
|
|
return false;
|
|
}
|
|
EnumAnchorInstallBase a_2 = GetAttachType(familyInstance, A_3.AnchorInstallBase);
|
|
if (!hangerFamily.GetElevation(xYZ, a_2))
|
|
{
|
|
SetSize(element2, familyInstance);
|
|
return false;
|
|
}
|
|
Autodesk.Revit.DB.ElementId elementId = Util.GetLevelId(familyInstance);
|
|
if (elementId != Autodesk.Revit.DB.ElementId.InvalidElementId && elementId != hangerFamily.GetLevel().Id)
|
|
{
|
|
Autodesk.Revit.DB.Parameter parameter = ((Autodesk.Revit.DB.Element)familyInstance).get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM);
|
|
if (parameter != null && parameter.StorageType == StorageType.ElementId)
|
|
{
|
|
parameter.Set(hangerFamily.GetLevel().Id);
|
|
}
|
|
}
|
|
LocationPoint locationPoint = familyInstance.Location as LocationPoint;
|
|
if (locationPoint == null)
|
|
{
|
|
return false;
|
|
}
|
|
if (!Util.fuzzyEqual(Math.Abs(xYZ.X - locationPoint.Point.X) + Math.Abs(xYZ.Y - locationPoint.Point.Y), 0.0))
|
|
{
|
|
locationPoint.Point = xYZ;
|
|
var hostOffsetParam = ((Autodesk.Revit.DB.Element)familyInstance).get_Parameter(BuiltInParameter.INSTANCE_FREE_HOST_OFFSET_PARAM);
|
|
if (hostOffsetParam != null) hostOffsetParam.Set(0);
|
|
}
|
|
else
|
|
{
|
|
xYZ = locationPoint.Point;
|
|
}
|
|
Autodesk.Revit.DB.Parameter parameter2 = Util.GetParameter(familyInstance, "CenterElevation");
|
|
if (parameter2 == null)
|
|
{
|
|
return false;
|
|
}
|
|
double num = parameter2.AsDouble();
|
|
if (!Util.fuzzyEqual(num, hangerFamily.getLocationElevation()))
|
|
{
|
|
parameter2.Set(hangerFamily.getLocationElevation());
|
|
}
|
|
parameter2 = Util.GetParameter(familyInstance, "AnchorElevation");
|
|
if (parameter2 != null)
|
|
{
|
|
double a_3 = parameter2.AsDouble();
|
|
if (!double.IsNaN(hangerFamily.getAnchorElevation()))
|
|
{
|
|
if (!Util.fuzzyEqual(hangerFamily.getAnchorElevation(), a_3))
|
|
{
|
|
parameter2.Set(hangerFamily.getAnchorElevation());
|
|
}
|
|
}
|
|
else
|
|
{
|
|
double num2 = parameter2.AsDouble() - num + hangerFamily.getLocationElevation();
|
|
if (!Util.fuzzyEqual(num2, a_3))
|
|
{
|
|
parameter2.Set(num2);
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public static void SetSize(Document A_0, MEPCurve A_1, Autodesk.Revit.DB.ElementId A_2, HangerSettings A_3)
|
|
{
|
|
KMBIM.Revit.Tools.Cmd.Hanger.MEPCurveType mEPCurveType = GetMEPCurveType(A_1);
|
|
switch (mEPCurveType)
|
|
{
|
|
case KMBIM.Revit.Tools.Cmd.Hanger.MEPCurveType.Pipe:
|
|
{
|
|
double a_ = HangerFamily.GetPipeOuterDiameter((Autodesk.Revit.DB.Element)A_1, A_3);
|
|
SetDiameter(A_0, A_2, KMBIM.Revit.Tools.Cmd.Hanger.MEPCurveType.Pipe, a_);
|
|
break;
|
|
}
|
|
case KMBIM.Revit.Tools.Cmd.Hanger.MEPCurveType.RectDuct:
|
|
case KMBIM.Revit.Tools.Cmd.Hanger.MEPCurveType.OvalDuct:
|
|
{
|
|
double a_ = HangerFamily.GetDuctWidth(A_1, A_3);
|
|
double a_2 = HangerFamily.GetDuctHeight(A_1, A_3);
|
|
SetWidth(A_0, A_2, mEPCurveType, a_);
|
|
SetHeight(A_0, A_2, mEPCurveType, a_2);
|
|
break;
|
|
}
|
|
case KMBIM.Revit.Tools.Cmd.Hanger.MEPCurveType.RoundDuct:
|
|
{
|
|
double a_ = HangerFamily.GetDuctDiameter(A_1, A_3);
|
|
SetDiameter(A_0, A_2, KMBIM.Revit.Tools.Cmd.Hanger.MEPCurveType.RoundDuct, a_);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void SetSize(Document A_0, MEPCurve A_1, IList<Autodesk.Revit.DB.ElementId> A_2, HangerSettings A_3)
|
|
{
|
|
KMBIM.Revit.Tools.Cmd.Hanger.MEPCurveType mEPCurveType = GetMEPCurveType(A_1);
|
|
switch (mEPCurveType)
|
|
{
|
|
case KMBIM.Revit.Tools.Cmd.Hanger.MEPCurveType.Pipe:
|
|
{
|
|
double a_ = HangerFamily.GetPipeOuterDiameter((Autodesk.Revit.DB.Element)A_1, A_3);
|
|
foreach (Autodesk.Revit.DB.ElementId item in A_2)
|
|
{
|
|
SetDiameter(A_0, item, KMBIM.Revit.Tools.Cmd.Hanger.MEPCurveType.Pipe, a_);
|
|
}
|
|
break;
|
|
}
|
|
case KMBIM.Revit.Tools.Cmd.Hanger.MEPCurveType.RectDuct:
|
|
case KMBIM.Revit.Tools.Cmd.Hanger.MEPCurveType.OvalDuct:
|
|
{
|
|
double a_ = HangerFamily.GetDuctWidth(A_1, A_3);
|
|
double a_2 = HangerFamily.GetDuctHeight(A_1, A_3);
|
|
foreach (Autodesk.Revit.DB.ElementId item2 in A_2)
|
|
{
|
|
SetWidth(A_0, item2, mEPCurveType, a_);
|
|
SetHeight(A_0, item2, mEPCurveType, a_2);
|
|
}
|
|
break;
|
|
}
|
|
case KMBIM.Revit.Tools.Cmd.Hanger.MEPCurveType.RoundDuct:
|
|
{
|
|
double a_ = HangerFamily.GetDuctDiameter(A_1, A_3);
|
|
foreach (Autodesk.Revit.DB.ElementId item3 in A_2)
|
|
{
|
|
SetDiameter(A_0, item3, KMBIM.Revit.Tools.Cmd.Hanger.MEPCurveType.RoundDuct, a_);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
public static Autodesk.Revit.DB.ElementId d(Autodesk.Revit.DB.Element A_0)
|
|
{
|
|
Entity entity = A_0.GetEntity(GetHangerRelPosSchema());
|
|
if (entity == null || !entity.IsValid())
|
|
{
|
|
return Autodesk.Revit.DB.ElementId.InvalidElementId;
|
|
}
|
|
return entity.Get<Autodesk.Revit.DB.ElementId>(GetHangerRelPosSchema().GetField("ParentId"));
|
|
}
|
|
|
|
public static bool b(Autodesk.Revit.DB.Element A_0, Autodesk.Revit.DB.Element A_1)
|
|
{
|
|
Entity entity = A_0.GetEntity(GetHangerDataSchema());
|
|
Field field = GetHangerDataSchema().GetField("KMBIMHangerIds");
|
|
IList<Autodesk.Revit.DB.ElementId> list = null;
|
|
if (entity != null && entity.IsValid())
|
|
{
|
|
list = entity.Get<IList<Autodesk.Revit.DB.ElementId>>(field);
|
|
if (list != null) list.Remove(A_1.Id);
|
|
entity.Set(field, list);
|
|
A_0.SetEntity(entity);
|
|
}
|
|
entity = A_1.GetEntity(GetHangerRelPosSchema());
|
|
if (entity != null && entity.IsValid())
|
|
{
|
|
entity.Set(GetHangerRelPosSchema().GetField("ParentId"), Autodesk.Revit.DB.ElementId.InvalidElementId);
|
|
A_0.SetEntity(entity);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public static bool SetSize(Autodesk.Revit.DB.Element A_0, Autodesk.Revit.DB.Element A_1)
|
|
{
|
|
Entity entity = A_0.GetEntity(GetHangerDataSchema());
|
|
Field field = GetHangerDataSchema().GetField("KMBIMHangerIds");
|
|
IList<Autodesk.Revit.DB.ElementId> list = null;
|
|
if (entity != null && entity.IsValid())
|
|
{
|
|
list = entity.Get<IList<Autodesk.Revit.DB.ElementId>>(field);
|
|
if (list != null) list.Remove(A_1.Id);
|
|
entity.Set(field, list);
|
|
A_0.SetEntity(entity);
|
|
Util.Delete(A_0.Document, A_1);
|
|
return true;
|
|
}
|
|
Util.Delete(A_0.Document, A_1);
|
|
return true;
|
|
}
|
|
|
|
public static bool a(Autodesk.Revit.DB.Element A_0, Autodesk.Revit.DB.ElementId A_1)
|
|
{
|
|
Entity entity = A_0.GetEntity(GetHangerDataSchema());
|
|
Field field = GetHangerDataSchema().GetField("KMBIMHangerIds");
|
|
IList<Autodesk.Revit.DB.ElementId> list = null;
|
|
if (entity != null && entity.IsValid())
|
|
{
|
|
list = entity.Get<IList<Autodesk.Revit.DB.ElementId>>(field);
|
|
if (list == null)
|
|
{
|
|
list = new List<Autodesk.Revit.DB.ElementId>();
|
|
}
|
|
if (!list.Contains(A_1))
|
|
{
|
|
list.Add(A_1);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
entity = new Entity(GetHangerDataSchema());
|
|
list = new List<Autodesk.Revit.DB.ElementId>();
|
|
list.Add(A_1);
|
|
}
|
|
entity.Set(field, list);
|
|
A_0.SetEntity(entity);
|
|
return true;
|
|
}
|
|
|
|
public static bool a(Autodesk.Revit.DB.Element A_0, Autodesk.Revit.DB.ElementId A_1, Autodesk.Revit.DB.ElementId A_2)
|
|
{
|
|
Entity entity = A_0.GetEntity(GetHangerDataSchema());
|
|
if (entity != null && entity.IsValid())
|
|
{
|
|
Field field = GetHangerDataSchema().GetField("KMBIMHangerIds");
|
|
IList<Autodesk.Revit.DB.ElementId> list = entity.Get<IList<Autodesk.Revit.DB.ElementId>>(field);
|
|
if (list == null || !list.Contains(A_1))
|
|
{
|
|
return false;
|
|
}
|
|
list.Remove(A_1);
|
|
list.Add(A_2);
|
|
entity.Set(field, list);
|
|
A_0.SetEntity(entity);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public static bool SetAnchorElevation(Autodesk.Revit.DB.Element element, double val)
|
|
{
|
|
Autodesk.Revit.DB.Parameter parameter = Util.GetParameter(element, "AnchorElevation");
|
|
if (parameter != null)
|
|
{
|
|
if (!Util.fuzzyEqual(parameter.AsDouble(), val))
|
|
{
|
|
return parameter.Set(val);
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public static double c(Autodesk.Revit.DB.Element A_0)
|
|
{
|
|
var cen_elev = Util.GetParameter(A_0, "CenterElevation");
|
|
return cen_elev != null ? cen_elev.AsDouble() : 0.0;
|
|
}
|
|
|
|
public static bool SetDiameter(Document A_0, Autodesk.Revit.DB.ElementId A_1, KMBIM.Revit.Tools.Cmd.Hanger.MEPCurveType A_2, double A_3)
|
|
{
|
|
Autodesk.Revit.DB.Element element = Util.GetElement(A_0, A_1);
|
|
if (element == null)
|
|
{
|
|
return false;
|
|
}
|
|
Autodesk.Revit.DB.Parameter parameter = Util.GetParameter(element, "Diameter");
|
|
if (parameter == null)
|
|
{
|
|
return false;
|
|
}
|
|
if (Util.fuzzyEqual(A_3, parameter.AsDouble()))
|
|
{
|
|
return true;
|
|
}
|
|
return parameter.Set(A_3);
|
|
}
|
|
|
|
public static bool SetWidth(Document document, Autodesk.Revit.DB.ElementId elementId, KMBIM.Revit.Tools.Cmd.Hanger.MEPCurveType mepCurveType, double val)
|
|
{
|
|
Autodesk.Revit.DB.Element element = Util.GetElement(document, elementId);
|
|
if (element == null)
|
|
{
|
|
return false;
|
|
}
|
|
Autodesk.Revit.DB.Parameter parameter = Util.GetParameter(element, "Width");
|
|
if (parameter == null)
|
|
{
|
|
return false;
|
|
}
|
|
if (Util.fuzzyEqual(val, parameter.AsDouble()))
|
|
{
|
|
return true;
|
|
}
|
|
return parameter.Set(val);
|
|
}
|
|
|
|
public static bool SetHeight(Document document, Autodesk.Revit.DB.ElementId elementId, KMBIM.Revit.Tools.Cmd.Hanger.MEPCurveType mepCurveType, double height)
|
|
{
|
|
Autodesk.Revit.DB.Element element = Util.GetElement(document, elementId);
|
|
if (element == null)
|
|
{
|
|
return false;
|
|
}
|
|
Autodesk.Revit.DB.Parameter parameter = Util.GetParameter(element, "Height");
|
|
if (parameter == null)
|
|
{
|
|
return false;
|
|
}
|
|
if (Util.fuzzyEqual(height, parameter.AsDouble()))
|
|
{
|
|
return true;
|
|
}
|
|
return parameter.Set(height);
|
|
}
|
|
|
|
public static bool CreateFamilyInstance(Document document, HangerFamily hangerFamily, EnumAnchorInstallBase anchorInstallBase, ref string errMsg)
|
|
{
|
|
if (!hangerFamily.af())
|
|
{
|
|
return false;
|
|
}
|
|
Autodesk.Revit.DB.FamilyInstance familyInstance = document.Create.NewFamilyInstance(hangerFamily.GetLocation(), hangerFamily.GetFamilySymbol(), hangerFamily.GetLevel(), Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
|
|
if (familyInstance == null)
|
|
{
|
|
errMsg = "Create family instance fail!";
|
|
return false;
|
|
}
|
|
Autodesk.Revit.DB.ElementId elementId = Util.GetLevelId(familyInstance);
|
|
if (elementId != Autodesk.Revit.DB.ElementId.InvalidElementId && elementId != hangerFamily.GetLevel().Id)
|
|
{
|
|
Autodesk.Revit.DB.Parameter parameter = ((Autodesk.Revit.DB.Element)familyInstance).get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM);
|
|
if (parameter != null && parameter.StorageType == StorageType.ElementId)
|
|
{
|
|
parameter.Set(hangerFamily.GetLevel().Id);
|
|
}
|
|
}
|
|
|
|
var hostOffsetParm = ((Autodesk.Revit.DB.Element)familyInstance).get_Parameter(BuiltInParameter.INSTANCE_FREE_HOST_OFFSET_PARAM);
|
|
if (hostOffsetParm != null) hostOffsetParm.Set(0);
|
|
|
|
a(hangerFamily.GetElement(), familyInstance.Id);
|
|
Autodesk.Revit.DB.Parameter parameter2 = Util.GetParameter(familyInstance, "CenterElevation");
|
|
if (parameter2 == null)
|
|
{
|
|
return false;
|
|
}
|
|
double num = parameter2.AsDouble();
|
|
parameter2.Set(hangerFamily.getLocationElevation());
|
|
parameter2 = Util.GetParameter(familyInstance, "AnchorElevation");
|
|
if (parameter2 != null)
|
|
{
|
|
if (!double.IsNaN(hangerFamily.getAnchorElevation()))
|
|
{
|
|
parameter2.Set(hangerFamily.getAnchorElevation());
|
|
}
|
|
else
|
|
{
|
|
double value = parameter2.AsDouble() - num + hangerFamily.getLocationElevation();
|
|
parameter2.Set(value);
|
|
}
|
|
}
|
|
var kdcsmepcurveType = hangerFamily.GetKMBIMMEPCurveType();
|
|
if (kdcsmepcurveType == KMBIM.Revit.Tools.Cmd.Hanger.MEPCurveType.OvalDuct || kdcsmepcurveType == KMBIM.Revit.Tools.Cmd.Hanger.MEPCurveType.RectDuct || kdcsmepcurveType == KMBIM.Revit.Tools.Cmd.Hanger.MEPCurveType.CableTray)
|
|
{
|
|
parameter2 = Util.GetParameter(familyInstance, "Width");
|
|
if (parameter2 != null)
|
|
{
|
|
parameter2.Set(hangerFamily.getWidth());
|
|
var paramHgt = Util.GetParameter(familyInstance, "Height");
|
|
if (paramHgt != null) paramHgt.Set(hangerFamily.getHeight());
|
|
}
|
|
else
|
|
{
|
|
var paramDia = Util.GetParameter(familyInstance, "Diameter");
|
|
if (paramDia != null) paramDia.Set(hangerFamily.getHeight());
|
|
}
|
|
}
|
|
else
|
|
{
|
|
parameter2 = Util.GetParameter(familyInstance, "Diameter");
|
|
if (parameter2 != null)
|
|
{
|
|
parameter2.Set(hangerFamily.getDiameter());
|
|
}
|
|
else
|
|
{
|
|
var paramWidth = Util.GetParameter(familyInstance, "Width");
|
|
var paramHeight = Util.GetParameter(familyInstance, "Height");
|
|
if (paramWidth != null) paramWidth.Set(hangerFamily.getDiameter());
|
|
if (paramHeight != null) paramHeight.Set(hangerFamily.getDiameter());
|
|
}
|
|
}
|
|
double num2 = 0.0;
|
|
double elev = 0.0;
|
|
if (!GetElevation(hangerFamily.GetLocation(), hangerFamily.GetLine(), ref elev))
|
|
{
|
|
Util.Delete(document, familyInstance);
|
|
return false;
|
|
}
|
|
hangerFamily.q(familyInstance);
|
|
if (!Util.fuzzyEqual(hangerFamily.getAngleOnPlane(), 0.0))
|
|
{
|
|
Line axis = Util.CreateBound(document, hangerFamily.GetLocation(), hangerFamily.GetLocation().Add(new Autodesk.Revit.DB.XYZ(0.0, 0.0, 1.0)));
|
|
ElementTransformUtils.RotateElement(document, familyInstance.Id, axis, hangerFamily.getAngleOnPlane());
|
|
}
|
|
var ptEnd = Util.GetEndPoint(hangerFamily.GetLine(), 0);
|
|
num2 = new Autodesk.Revit.DB.XYZ(hangerFamily.GetLocation().X, hangerFamily.GetLocation().Y, elev).Subtract(ptEnd).GetLength();
|
|
Entity entity = familyInstance.GetEntity(GetHangerRelPosSchema());
|
|
if (entity == null || !entity.IsValid())
|
|
{
|
|
entity = new Entity(GetHangerRelPosSchema());
|
|
}
|
|
entity.Set("ParentId", hangerFamily.GetElement().Id);
|
|
#if(_22 || _23 || _24)
|
|
entity.Set("RelDist", num2, UnitTypeId.Feet);
|
|
#else
|
|
entity.Set("RelDist", num2, Autodesk.Revit.DB.DisplayUnitType.DUT_DECIMAL_FEET);
|
|
#endif
|
|
familyInstance.SetEntity(entity);
|
|
entity = familyInstance.GetEntity(GetHangerInstallBaseSchema());
|
|
if (entity == null || !entity.IsValid())
|
|
{
|
|
entity = new Entity(GetHangerInstallBaseSchema());
|
|
}
|
|
entity.Set("AnchorInstallBase", anchorInstallBase.ToString());
|
|
familyInstance.SetEntity(entity);
|
|
return true;
|
|
}
|
|
|
|
public static Line GetLine(Autodesk.Revit.DB.Element element)
|
|
{
|
|
LocationCurve locationCurve = element.Location as LocationCurve;
|
|
if (locationCurve == null)
|
|
{
|
|
return null;
|
|
}
|
|
return locationCurve.Curve as Line;
|
|
}
|
|
|
|
public static KMBIM.Revit.Tools.Cmd.Hanger.MEPCurveType GetMEPCurveType(Autodesk.Revit.DB.Element element)
|
|
{
|
|
Autodesk.Revit.DB.ElementId elementId = d(element);
|
|
if (elementId == Autodesk.Revit.DB.ElementId.InvalidElementId)
|
|
{
|
|
return KMBIM.Revit.Tools.Cmd.Hanger.MEPCurveType.UnDefined;
|
|
}
|
|
return GetMEPCurveType(Util.GetElement(element.Document, elementId) as MEPCurve);
|
|
}
|
|
|
|
public static KMBIM.Revit.Tools.Cmd.Hanger.MEPCurveType GetMEPCurveType(MEPCurve mepCurve)
|
|
{
|
|
if (mepCurve == null)
|
|
{
|
|
return KMBIM.Revit.Tools.Cmd.Hanger.MEPCurveType.UnDefined;
|
|
}
|
|
switch (mepCurve.Category.Id.IntegerValue)
|
|
{
|
|
case -2008044:
|
|
return KMBIM.Revit.Tools.Cmd.Hanger.MEPCurveType.Pipe;
|
|
case -2008132:
|
|
return KMBIM.Revit.Tools.Cmd.Hanger.MEPCurveType.Conduit;
|
|
case -2008130:
|
|
return KMBIM.Revit.Tools.Cmd.Hanger.MEPCurveType.CableTray;
|
|
case -2008000:
|
|
{
|
|
IEnumerator enumerator = mepCurve.ConnectorManager.Connectors.GetEnumerator();
|
|
try
|
|
{
|
|
if (enumerator.MoveNext())
|
|
{
|
|
return Util.GetKMBIMMEPCurveType((Autodesk.Revit.DB.Connector)enumerator.Current);
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
IDisposable disposable = enumerator as IDisposable;
|
|
if (disposable != null)
|
|
{
|
|
disposable.Dispose();
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
return KMBIM.Revit.Tools.Cmd.Hanger.MEPCurveType.UnDefined;
|
|
}
|
|
|
|
private static void a(Autodesk.Revit.DB.XYZ A_0, Autodesk.Revit.DB.XYZ A_1, out Autodesk.Revit.DB.XYZ A_2, out Autodesk.Revit.DB.XYZ A_3)
|
|
{
|
|
A_2 = null;
|
|
A_3 = null;
|
|
double num = A_1.DotProduct(A_1);
|
|
if (!(num < 1E-07))
|
|
{
|
|
A_2 = A_0.DotProduct(A_1) / num * A_1;
|
|
A_3 = A_0.Subtract(A_2);
|
|
}
|
|
}
|
|
|
|
public static bool GetElevation(Autodesk.Revit.DB.XYZ A_0, Line line, ref double A_2)
|
|
{
|
|
if (line == null || A_0 == null)
|
|
{
|
|
return false;
|
|
}
|
|
Autodesk.Revit.DB.XYZ xYZ = Util.GetEndPoint(line, 0);
|
|
Autodesk.Revit.DB.XYZ direction = line.Direction;
|
|
if (!Util.fuzzyEqual(direction.Y, 0.0))
|
|
{
|
|
A_2 = (A_0.Y - xYZ.Y) * direction.Z / direction.Y + xYZ.Z;
|
|
return true;
|
|
}
|
|
if (!Util.fuzzyEqual(direction.X, 0.0))
|
|
{
|
|
A_2 = (A_0.X - xYZ.X) * direction.Z / direction.X + xYZ.Z;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public static Autodesk.Revit.DB.XYZ GetIntersectionPoint(Autodesk.Revit.DB.XYZ A_0, Line A_1, ref double A_2)
|
|
{
|
|
if (A_0 == null || A_1 == null)
|
|
{
|
|
return null;
|
|
}
|
|
IntersectionResult intersectionResult = A_1.Project(A_0);
|
|
if (intersectionResult == null)
|
|
{
|
|
return null;
|
|
}
|
|
A_2 = intersectionResult.Parameter;
|
|
return intersectionResult.XYZPoint;
|
|
}
|
|
|
|
internal static void AdjustAnchorElevation(Document document, Autodesk.Revit.DB.FamilyInstance fi)
|
|
{
|
|
EnumAnchorInstallBase attachTo = HangerSettings.GetSettings().AnchorInstallBase;
|
|
Autodesk.Revit.DB.Level level = document.GetElement(fi.LevelId) as Autodesk.Revit.DB.Level;
|
|
if (level == null)
|
|
{
|
|
return;
|
|
}
|
|
Autodesk.Revit.DB.XYZ origin = fi.GetTransform().Origin;
|
|
View3DHanger view3dHanger = new View3DHanger(document);
|
|
HangerFamily hangerFamily = new HangerFamily(null);
|
|
hangerFamily.SetFamilySymbol(fi.Symbol);
|
|
Autodesk.Revit.DB.XYZ pos = new Autodesk.Revit.DB.XYZ(origin.X, origin.Y, c(fi) + level.ProjectElevation);
|
|
double elevation = 0.0;
|
|
if (attachTo == EnumAnchorInstallBase.Structrual)
|
|
{
|
|
if (view3dHanger.GetIntersectionElevation(pos, hangerFamily.IsSupport(), out elevation))
|
|
{
|
|
SetAnchorElevation(fi, elevation - level.ProjectElevation);
|
|
}
|
|
}
|
|
else if (view3dHanger.GetAnchorElevation(pos, hangerFamily.IsSupport(), out elevation))
|
|
{
|
|
SetAnchorElevation(fi, elevation - level.ProjectElevation);
|
|
}
|
|
}
|
|
}
|
|
|
|
} |