413 lines
14 KiB
C#
413 lines
14 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Windows.Forms;
|
|
using Autodesk.Revit.UI;
|
|
using Autodesk.Revit.DB;
|
|
using Autodesk.Revit.Creation;
|
|
using System.IO;
|
|
using KDCS.Utils;
|
|
|
|
|
|
namespace KMBIM
|
|
{
|
|
public partial class FormSprinKler : System.Windows.Forms.Form
|
|
{
|
|
public int RTcode, Rad_Idx;
|
|
public string str_Workplane;
|
|
public Autodesk.Revit.UI.ExternalCommandData revit;
|
|
public FamilySymbol insertsb;
|
|
List<FamilySymbol> familySymbol;
|
|
private System.Windows.Forms.Label normalLabel;
|
|
private System.Windows.Forms.Label originLabel;
|
|
|
|
private System.Windows.Forms.GroupBox creationGroupBox;
|
|
private System.Windows.Forms.Button okButton;
|
|
private System.Windows.Forms.Button cancelButton;
|
|
|
|
Autodesk.Revit.Creation.Application creApp;
|
|
Autodesk.Revit.Creation.Document creDoc;
|
|
Autodesk.Revit.DB.Document doc;
|
|
UIApplication m_application;
|
|
UIDocument m_document;
|
|
List<FileInfo> infoList = new List<FileInfo>();
|
|
|
|
public FormSprinKler()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
// 스크링쿨러 리스트를 가져와라
|
|
|
|
private List<FamilySymbol> getFamily()
|
|
{
|
|
this.Hide();
|
|
List<FamilySymbol> familySymbol = new List<FamilySymbol>();
|
|
List<FamilyInstanceCreationData> fiCreationDatas = new List<FamilyInstanceCreationData>();
|
|
|
|
//Try to get a FamilySymbol
|
|
FilteredElementCollector collector = new FilteredElementCollector(revit.Application.ActiveUIDocument.Document);
|
|
ICollection<Element> collection = collector.OfClass(typeof(FamilySymbol)).ToElements();
|
|
FamilySymbol Symbol;
|
|
foreach (Element e in collection)
|
|
{
|
|
|
|
Symbol = e as FamilySymbol;
|
|
|
|
if (null != Symbol.Category)
|
|
{
|
|
if ("Sprinklers" == Symbol.Category.Name || "스프링클러" == Symbol.Category.Name)
|
|
{
|
|
familySymbol.Add(Symbol);
|
|
}
|
|
}
|
|
}
|
|
this.Show();
|
|
return familySymbol;
|
|
}
|
|
|
|
public void getFileName(string path)
|
|
{
|
|
string versionNumber = doc.Application.VersionNumber.ToString();
|
|
//string Tmp = System.Reflection.Assembly.GetExecutingAssembly().Location;
|
|
//Tmp = Tmp.Replace("\\KMBIM2019.dll", "");
|
|
string Tmp = Util.GetKMBIMLibraryFolder("Libraries\\Sprinkler");
|
|
|
|
String fileName = Tmp + "\\" + versionNumber + path;
|
|
|
|
if (Directory.Exists(fileName))
|
|
{
|
|
DirectoryInfo di = new DirectoryInfo(fileName);
|
|
foreach (var item in di.GetFiles())
|
|
{
|
|
infoList.Add(item);
|
|
listBox1.Items.Add(item.Name);
|
|
//Stream stream = item.OpenRead();
|
|
//Bitmap bitmap = new Bitmap(stream);
|
|
//pictureBox1.Image = bitmap;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
private FamilySymbol LoadFamilys(string famroot, string famname)
|
|
{
|
|
string versionNumber = doc.Application.VersionNumber.ToString();
|
|
//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;
|
|
// 아래의 이름은 패밀리 고유의 이름이다. 패밀리 작업할때 입력하게 되어있다.
|
|
String name = famname;
|
|
|
|
// 패밀리를 로드한다.
|
|
Family fam = 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)
|
|
{
|
|
|
|
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 void FormSprinKler_Load(object sender, EventArgs e)
|
|
{
|
|
this.KeyPreview = true;
|
|
m_application = revit.Application;
|
|
m_document = m_application.ActiveUIDocument;
|
|
Autodesk.Revit.ApplicationServices.Application app = m_application.Application;
|
|
doc = m_document.Document;
|
|
RTcode = 0;
|
|
|
|
//txt_Offset.Text = "0";
|
|
|
|
//getFileName("\\data\\sprinkler");
|
|
|
|
//콤보박스 리스트
|
|
IList<Element> levelLst = new FilteredElementCollector(doc).OfClass(typeof(Level)).ToElements();
|
|
IList<Element> referPlaneLst = new FilteredElementCollector(doc).OfClass(typeof(ReferencePlane)).ToElements();
|
|
|
|
foreach (Element elem in levelLst)
|
|
{
|
|
Level lvl = elem as Level;
|
|
|
|
if (combo_work.Items.Contains(lvl.Name) == false)
|
|
combo_work.Items.Add(lvl.Name);
|
|
}
|
|
|
|
foreach(Element elem in referPlaneLst)
|
|
{
|
|
ReferencePlane referPlane = elem as ReferencePlane;
|
|
if (combo_work.Items.Contains(referPlane.Name) == false)
|
|
combo_work.Items.Add(referPlane.Name);
|
|
}
|
|
|
|
if (rad_work.Checked == true)
|
|
combo_work.Enabled = true;
|
|
else
|
|
combo_work.Enabled = false;
|
|
|
|
if (Reg.getReg("Spkr_Rad_Idx") == "")
|
|
{
|
|
Rad_Idx = 1;
|
|
rad_ceiling.Checked = true;
|
|
}
|
|
else
|
|
{
|
|
Rad_Idx = Convert.ToInt32(Reg.getReg("Spkr_Rad_Idx"));
|
|
if (Rad_Idx == 1)
|
|
rad_ceiling.Checked = true;
|
|
else if (Rad_Idx == 2)
|
|
rad_work.Checked = true;
|
|
}
|
|
|
|
if (Reg.getReg("WorkPlane_Name") == "")
|
|
{
|
|
combo_work.SelectedIndex = 0;
|
|
str_Workplane = combo_work.SelectedItem.ToString();
|
|
}
|
|
else
|
|
{
|
|
str_Workplane = Reg.getReg("WorkPlane_Name");
|
|
int work_Idx = combo_work.Items.IndexOf(str_Workplane);
|
|
if (work_Idx == -1)
|
|
combo_work.SelectedIndex = 0;
|
|
else
|
|
combo_work.SelectedIndex = work_Idx;
|
|
}
|
|
|
|
if(Reg.getReg("Spkr_offset") == "")
|
|
{
|
|
txt_Offset.Text = "0";
|
|
m_Offset = 0;
|
|
}
|
|
else
|
|
{
|
|
string str_offset = Reg.getReg("Spkr_offset");
|
|
txt_Offset.Text = str_offset;
|
|
}
|
|
|
|
if (infoList.Count > 0)
|
|
//listBox1.SelectedIndex = 0;
|
|
familySymbol = new List<FamilySymbol>();
|
|
|
|
familySymbol = getFamily();
|
|
|
|
if (familySymbol.Count == 0)
|
|
{
|
|
//패밀리가 1개도없을 경우 기본 1개 로드
|
|
FamilySymbol fs = LoadFamilys("\\M_스프링클러 - 상향.rfa", null);
|
|
familySymbol.Add(fs);
|
|
}
|
|
|
|
for (int i = 0; i < familySymbol.Count; i++)
|
|
{
|
|
listBox1.Items.Add(familySymbol[i].Name);
|
|
}
|
|
|
|
listBox1.SelectedIndex = 0;
|
|
|
|
}
|
|
|
|
private void FormSprinKler_FormClosed(object sender, FormClosedEventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
|
|
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
insertsb = familySymbol[listBox1.SelectedIndex];
|
|
MakePreView(insertsb);
|
|
//int idx = listBox1.SelectedIndex;
|
|
|
|
//listBox1.Items.Add(infoList[idx].Name);
|
|
//Stream stream = infoList[idx].OpenRead();
|
|
|
|
//Bitmap bitmap = new Bitmap(infoList[idx].FullName);
|
|
//pictureBox1.Image = bitmap;
|
|
|
|
}
|
|
|
|
public void MakePreView(FamilySymbol sb)
|
|
{
|
|
|
|
//Debug.Assert(null != fi.Category,
|
|
//"expected family instance to have a valid category");
|
|
UIApplication uiapp = revit.Application;
|
|
UIDocument uidoc = uiapp.ActiveUIDocument;
|
|
Autodesk.Revit.DB.Document doc = uidoc.Document;
|
|
|
|
|
|
FilteredElementCollector collector1 = new FilteredElementCollector(revit.Application.ActiveUIDocument.Document);
|
|
Level level2 = collector1.OfClass(typeof(Level)).FirstElement() as Level;
|
|
|
|
using (Transaction trans = new Transaction(doc))
|
|
{
|
|
trans.Start("isActive");
|
|
if (sb.IsActive == false)
|
|
sb.Activate();
|
|
|
|
|
|
|
|
|
|
FamilyInstance fi = revit.Application.ActiveUIDocument.Document.Create.NewFamilyInstance(XYZ.Zero, sb, level2, Autodesk.Revit.DB.Structure.StructuralType.Column);
|
|
|
|
|
|
ElementId typeId = fi.GetTypeId();
|
|
|
|
ElementType type = revit.Application.ActiveUIDocument.Document.GetElement(typeId)
|
|
as ElementType;
|
|
|
|
System.Drawing.Size imgSize = new System.Drawing.Size(200, 200);
|
|
|
|
Bitmap image = type.GetPreviewImage(imgSize);
|
|
|
|
revit.Application.ActiveUIDocument.Document.Delete(fi.Id);
|
|
// encode image to jpeg for test display purposes:
|
|
|
|
//JpegBitmapEncoder encoder
|
|
// = new JpegBitmapEncoder();
|
|
|
|
// encoder.Frames.Add(BitmapFrame.Create(
|
|
// ConvertBitmapToBitmapSource(image)));
|
|
|
|
//encoder.QualityLevel = 25;
|
|
|
|
/*string filename = "Data\\"+sb.Name +".jpg";
|
|
|
|
FileStream file = new FileStream(
|
|
filename, FileMode.Create, FileAccess.Write);
|
|
|
|
encoder.Save(file);
|
|
file.Close();
|
|
*/
|
|
// Process.Start(filename); // test display
|
|
pictureBox1.Image = image;
|
|
trans.Commit();
|
|
}
|
|
}
|
|
//작업 기준면에 배치
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
RTcode = 1;
|
|
}
|
|
//현재 레벨에 배치
|
|
private void button2_Click(object sender, EventArgs e)
|
|
{
|
|
RTcode = 2;
|
|
}
|
|
//천장 배치
|
|
private void button3_Click(object sender, EventArgs e)
|
|
{
|
|
RTcode = 3;
|
|
}
|
|
|
|
private void FormSprinKler_KeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
if (e.KeyCode == Keys.Escape)
|
|
{
|
|
//this.Close();
|
|
this.DialogResult = DialogResult.Cancel;
|
|
}
|
|
else if (e.KeyCode == Keys.Enter)
|
|
{
|
|
this.DialogResult = DialogResult.OK;
|
|
}
|
|
}
|
|
|
|
//2020-10-22 스프링클러 작업 기준면 간격띄우기 옵션 추가.
|
|
//작업 기준면 배치 offset 간격
|
|
private double _m_Offset;
|
|
public double m_Offset
|
|
{
|
|
get { return _m_Offset; }
|
|
set { _m_Offset = value; }
|
|
}
|
|
//작업 기준면 배치 offset 간격 변경 시
|
|
private void txt_Offset_TextChanged(object sender, EventArgs e)
|
|
{
|
|
if (txt_Offset.Text == "") return;
|
|
if(txt_Offset.Text != "-")
|
|
{
|
|
m_Offset = double.Parse(txt_Offset.Text);
|
|
Reg.setReg("Spkr_offset", txt_Offset.Text);
|
|
}
|
|
|
|
}
|
|
|
|
//라디오 천장 배치
|
|
private void rad_ceiling_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
Rad_Idx = 1;
|
|
if (rad_work.Checked == true)
|
|
combo_work.Enabled = true;
|
|
else
|
|
combo_work.Enabled = false;
|
|
|
|
Reg.setReg("Spkr_Rad_Idx", Rad_Idx.ToString());
|
|
}
|
|
|
|
//라디오 작업 기준면에 배치
|
|
private void rad_work_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
Rad_Idx = 2;
|
|
if (rad_work.Checked == true)
|
|
combo_work.Enabled = true;
|
|
else
|
|
combo_work.Enabled = false;
|
|
|
|
Reg.setReg("Spkr_Rad_Idx", Rad_Idx.ToString());
|
|
}
|
|
|
|
//작업기준면 콤보박스
|
|
private void combo_work_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
int work_Idx = combo_work.SelectedIndex;
|
|
str_Workplane = combo_work.SelectedItem.ToString();
|
|
Reg.setReg("WorkPlane_Name", str_Workplane);
|
|
}
|
|
|
|
private void txt_Offset_KeyPress(object sender, KeyPressEventArgs e)
|
|
{
|
|
int keyCode = (int)e.KeyChar;
|
|
if ((keyCode < 48 || keyCode > 57) && keyCode != 8 && keyCode != 46 && keyCode != 45)
|
|
e.Handled = true;
|
|
|
|
if (keyCode == 45)
|
|
{
|
|
if (txt_Offset.Text.Contains("-") == true) e.Handled = true;
|
|
}
|
|
|
|
if (keyCode == 46)
|
|
{
|
|
if (string.IsNullOrEmpty(txt_Offset.Text) || txt_Offset.Text.Contains('.') == true)
|
|
e.Handled = true;
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
}
|