170 lines
6.1 KiB
C#
170 lines
6.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
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;
|
|
using Autodesk.Revit.UI;
|
|
|
|
|
|
namespace KMBIM.Revit.Tools.Cmd.Hanger
|
|
{
|
|
/// <summary>
|
|
/// 설치 유형
|
|
/// </summary>
|
|
public enum EnumAnchorInstallBase
|
|
{
|
|
Structrual, // 구조물
|
|
Level // 레벨
|
|
}
|
|
|
|
class Hanger
|
|
{
|
|
|
|
// 행거의 중심 고도를 넘겨준다.
|
|
public static double GetCenterElevation(Autodesk.Revit.DB.Element elm)
|
|
{
|
|
var parm = elm.LookupParameter("CenterElevation");
|
|
return parm != null ? parm.AsDouble() : 0d;
|
|
}
|
|
|
|
// 현재 행거의 앵커 고도가 주어진 값과 같지 않으면 주어진 값으로 수정한다.
|
|
public static bool SetAnchorElevation(Autodesk.Revit.DB.Element elm, double anchorElevation)
|
|
{
|
|
var parameter = elm.LookupParameter("AnchorElevation");
|
|
if (parameter != null)
|
|
{
|
|
var curElevation = parameter.AsDouble();
|
|
if (!Util.IsEqual(curElevation, anchorElevation))
|
|
{
|
|
return parameter.Set(anchorElevation);
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
|
|
// 주어진 색인에 해당하는 행거 패밀리 파일을 선택한 커브 객체에 배치합니다.
|
|
internal static Result PlaceManual(int index, ExternalCommandData commandData, ref string errMsg)
|
|
{
|
|
try
|
|
{
|
|
Document document = commandData.Application.ActiveUIDocument.Document;
|
|
if (index >= App.hanger_families.Count)
|
|
{
|
|
return Result.Succeeded;
|
|
}
|
|
string hangerFamilyFile = App.hanger_families[index];
|
|
|
|
|
|
//HangerFamily hangerFamily = new HangerFamily();
|
|
//hangerFamily.SetView3dHanger(new View3DHanger(document));
|
|
|
|
|
|
//HangerSettings settings = HangerSettings.GetSettings();
|
|
Autodesk.Revit.UI.Selection.Selection selection = commandData.Application.ActiveUIDocument.Selection;
|
|
while (true)
|
|
{
|
|
Reference reference = null;
|
|
try
|
|
{
|
|
reference = selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.PointOnElement, new MEPCurveSelectionFilter(), "MEP 곡선의 한 점을 선택하십시오!");
|
|
if (reference == null)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
errMsg = ex.Message;
|
|
break;
|
|
}
|
|
//MEPCurve a_2 = Util.a(document, reference.ElementId) as MEPCurve;
|
|
//if (!HangerSchema.HasCurve(a_2))
|
|
//{
|
|
// return Result.Succeeded;
|
|
//}
|
|
/*
|
|
Autodesk.Revit.DB.Transaction transaction = new Autodesk.Revit.DB.Transaction(document, Resources.STRING_TADD_HANGER);
|
|
transaction.Start();
|
|
|
|
if (!n.r((Autodesk.Revit.DB.Element)a_2, settings))
|
|
{
|
|
return Result.Succeeded;
|
|
}
|
|
n.q(m.a(document, n.ac(), hangerFamilyFile));
|
|
if (n.ae() == null)
|
|
{
|
|
transaction.RollBack();
|
|
return Result.Failed;
|
|
}
|
|
if (!n.q(reference.GlobalPoint, settings.AttachTo))
|
|
{
|
|
transaction.RollBack();
|
|
return Result.Failed;
|
|
}
|
|
if (!HangerSchema.a(document, n, settings.AttachTo, ref errMsg))
|
|
{
|
|
transaction.RollBack();
|
|
return Result.Failed;
|
|
}
|
|
transaction.Commit();
|
|
* */
|
|
}
|
|
return Result.Succeeded;
|
|
}
|
|
catch (Exception ex2)
|
|
{
|
|
errMsg = ex2.Message;
|
|
return Result.Failed;
|
|
}
|
|
}
|
|
|
|
|
|
// 행거 부착 방식(유형)에 따라 레벨 또는 구조물에 부착합니다.
|
|
internal static void Attach_XX(Document doc, Autodesk.Revit.DB.FamilyInstance fi)
|
|
{
|
|
// 행거 설정값 가져오기
|
|
EnumAnchorInstallBase attachType = HangerSettings.GetSettings().AnchorInstallBase;
|
|
|
|
// 행거
|
|
Autodesk.Revit.DB.Level level = doc.GetElement(fi.LevelId) as Autodesk.Revit.DB.Level;
|
|
if (level == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
|
|
// 행거 원점
|
|
Autodesk.Revit.DB.XYZ origin = fi.GetTransform().Origin;
|
|
View3DHanger view3dHanger = new View3DHanger(doc);
|
|
HangerFamily n = new HangerFamily(null);
|
|
n.SetFamilySymbol(fi.Symbol);
|
|
// 행거 중심 높이
|
|
var hangerCenterElevation = GetCenterElevation(fi);
|
|
// 행거 삽입점
|
|
Autodesk.Revit.DB.XYZ ptAttachment = new Autodesk.Revit.DB.XYZ(origin.X, origin.Y, hangerCenterElevation + level.ProjectElevation);
|
|
double elevation = 0.0;
|
|
if (attachType == EnumAnchorInstallBase.Structrual)
|
|
{
|
|
if (view3dHanger.GetIntersectionElevation(ptAttachment, n.IsSupport(), out elevation))
|
|
{
|
|
SetAnchorElevation(fi, elevation - level.ProjectElevation);
|
|
}
|
|
}
|
|
else if (view3dHanger.GetAnchorElevation(ptAttachment, n.IsSupport(), out elevation))
|
|
{
|
|
SetAnchorElevation(fi, elevation - level.ProjectElevation);
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}
|