215 lines
7.7 KiB
C#
215 lines
7.7 KiB
C#
using System;
|
|
using Autodesk.Revit.UI;
|
|
using Autodesk.Revit.DB;
|
|
using System.Diagnostics;
|
|
using System.Collections.Generic;
|
|
using System.Windows.Forms;
|
|
using System.Linq;
|
|
using Autodesk.Revit.Creation;
|
|
using Autodesk.Revit.UI.Selection;
|
|
using Autodesk.Revit.DB.Structure;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Windows;
|
|
//using System.Windows.Media; // WindowsBase
|
|
//using System.Windows.Media.Imaging; // PresentationCore
|
|
using Size = System.Drawing.Size;
|
|
using KDCS.Utils;
|
|
using KMBIM.Revit.Tools;
|
|
|
|
namespace KMBIM
|
|
{
|
|
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
|
|
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
|
|
public class SprinKlerSpray : IExternalCommand
|
|
{
|
|
UIApplication m_application;
|
|
Autodesk.Revit.Creation.ItemFactoryBase m_CreationBase;
|
|
UIDocument m_document;
|
|
Autodesk.Revit.DB.Document doc;
|
|
|
|
public const double PI = 3.14159265358;
|
|
public Autodesk.Revit.UI.ExternalCommandData m_revit;
|
|
public double ksv = 7.545932; //2300을 pit로 변환해놓은값
|
|
public Autodesk.Revit.UI.Result Execute(ExternalCommandData revit, ref string message, ElementSet elements)
|
|
{
|
|
if (!WorkMain.GetInstance().IsValid) return Autodesk.Revit.UI.Result.Succeeded;
|
|
m_application = revit.Application;
|
|
m_document = m_application.ActiveUIDocument;
|
|
doc = m_document.Document;
|
|
if (m_document.Document.IsFamilyDocument)
|
|
m_CreationBase = m_document.Document.FamilyCreate;
|
|
else
|
|
m_CreationBase = m_document.Document.Create;
|
|
try
|
|
{
|
|
|
|
m_revit = revit;
|
|
|
|
//살수반경 표시
|
|
|
|
GetRadius dlg = new GetRadius();
|
|
dlg.textBox1.Text = "2300";
|
|
if (dlg.ShowDialog() == DialogResult.OK)
|
|
{
|
|
|
|
SprayRadius(Convert.ToDouble(dlg.textBox1.Text));
|
|
}
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
//message = e.Message;
|
|
return Autodesk.Revit.UI.Result.Failed;
|
|
}
|
|
|
|
return Autodesk.Revit.UI.Result.Succeeded;
|
|
}
|
|
|
|
private void SprayRadius(double getradius)
|
|
{
|
|
if (getradius <= 0)
|
|
{
|
|
MessageBox.Show("입력한 값이 없거나 0입니다. 기본값으로 표시합니다.");
|
|
getradius = 2300;
|
|
}
|
|
|
|
double radius = Unit.MMToFeet(getradius);
|
|
//double radius = Unit.CovertToAPI(getradius, DisplayUnitType.DUT_MILLIMETERS);
|
|
IList<Element> ElementList = m_revit.Application.ActiveUIDocument.Selection.PickElementsByRectangle();
|
|
|
|
FamilySymbol sp_dia = LoadFamilys("\\SP_Dia.rfa", "SP_Dia");
|
|
|
|
if (sp_dia == null)
|
|
sp_dia = getNameByFamily("SP_Dia");
|
|
using (Transaction trans = new Transaction(doc))
|
|
{
|
|
trans.Start("NewFamilyInstance");
|
|
for (int i = 0; i < ElementList.Count; i++)
|
|
{
|
|
if (ElementList[i].Category.Name == "Sprinklers" || ElementList[i].Category.Name == "스프링클러")
|
|
{
|
|
Autodesk.Revit.DB.LocationPoint asdf = ElementList[i].Location as Autodesk.Revit.DB.LocationPoint;
|
|
|
|
XYZ location = asdf.Point;
|
|
FamilyInstance fi = null;
|
|
|
|
if (sp_dia.IsActive == false)
|
|
sp_dia.Activate();
|
|
fi = m_document.Document.Create.NewFamilyInstance(location, sp_dia, StructuralType.NonStructural);
|
|
|
|
|
|
|
|
Definition df = GetDefinition(fi, "Diameter");
|
|
if (df == null) df = GetDefinition(fi, "지름");
|
|
Parameter familyParam = fi.get_Parameter(df);
|
|
bool sw = familyParam.Set(radius);
|
|
|
|
}
|
|
|
|
}
|
|
trans.Commit();
|
|
}
|
|
|
|
}
|
|
private FamilySymbol LoadFamilys(string famroot, string famname)
|
|
{
|
|
string versionNumber = doc.Application.VersionNumber.ToString();
|
|
|
|
UIApplication uiapp = m_revit.Application;
|
|
UIDocument uidoc = uiapp.ActiveUIDocument;
|
|
doc = uidoc.Document;
|
|
//string Tmp = System.Reflection.Assembly.GetExecutingAssembly().Location;
|
|
//Tmp = Tmp.Replace("\\KMBIM2019.dll", "");
|
|
string Tmp = Util.GetKMBIMLibraryFolder("Libraries\\Sprinkler");
|
|
// get the active view's level for beam creation
|
|
Level level = m_document.Document.GetElement(m_document.ActiveView.LevelId) as Level;
|
|
// load a family symbol from file
|
|
FamilySymbol gotSymbol = null;
|
|
String fileName = Tmp + "\\" + versionNumber + famroot;// "\\data\\2010-0240312-글로브_밸브_(플랜지형).rfa";
|
|
// 아래의 이름은 패밀리 고유의 이름이다. 패밀리 작업할때 입력하게 되어있다.
|
|
String name = famname;//"2010-0240312-글로브_밸브_(플랜지형)";
|
|
|
|
FamilyInstance instance = null;
|
|
// 패밀리를 로드한다.
|
|
Family fam = null;
|
|
ElementType elemType = null;
|
|
|
|
//m_document.Document.LoadFamilySymbol(fileName, "", out gotSymbol);
|
|
bool sw = false;
|
|
using (Transaction trans = new Transaction(doc))
|
|
{
|
|
trans.Start("LoadFamily");
|
|
sw = m_document.Document.LoadFamily(fileName, out fam);
|
|
trans.Commit();
|
|
}
|
|
|
|
if (sw == true)
|
|
{
|
|
/*foreach (FamilySymbol c in fam.Symbols)
|
|
{
|
|
gotSymbol = c;
|
|
|
|
}*/
|
|
ISet<ElementId> fam_ids = fam.GetFamilySymbolIds();
|
|
List<string> fam_sym_names = new List<string>();
|
|
|
|
if (fam_ids.Count() == 0) return null;
|
|
gotSymbol = (FamilySymbol)doc.GetElement(fam_ids.ElementAt(0));
|
|
|
|
}
|
|
return gotSymbol;
|
|
}
|
|
// 패밀리 존재 여부 검토
|
|
private FamilySymbol getNameByFamily(string name)
|
|
{
|
|
|
|
List<FamilyInstanceCreationData> fiCreationDatas = new List<FamilyInstanceCreationData>();
|
|
ElementSet elementSet = null;
|
|
//Try to get a FamilySymbol
|
|
FilteredElementCollector collector = new FilteredElementCollector(m_revit.Application.ActiveUIDocument.Document);
|
|
ICollection<Element> collection = collector.OfClass(typeof(FamilySymbol)).ToElements();
|
|
FamilySymbol Symbol;
|
|
FamilySymbol target = null;
|
|
|
|
foreach (Element e in collection)
|
|
{
|
|
|
|
Symbol = e as FamilySymbol;
|
|
|
|
|
|
|
|
if (null != Symbol.Category)
|
|
{
|
|
if (name == Symbol.Family.Name)
|
|
{
|
|
// MessageBox.Show(Symbol.Family.Name);
|
|
target = Symbol;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
return target;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 매개 변수 정의를 반환합니다.
|
|
/// 주어진 요소와 매개 변수 이름.
|
|
/// </summary>
|
|
static Definition GetDefinition(Element elem, string parameter_name)
|
|
{
|
|
IList<Parameter> ps = elem.GetParameters(parameter_name);
|
|
|
|
int n = ps.Count;
|
|
|
|
Debug.Assert(1 >= n, "expected maximum one shared parameters" + "named " + parameter_name);
|
|
|
|
Definition d = (0 == n) ? null
|
|
: ps[0].Definition;
|
|
|
|
return d;
|
|
}
|
|
}
|
|
}
|