417 lines
16 KiB
C#
417 lines
16 KiB
C#
//using System;
|
|
//using System.Collections.Generic;
|
|
//using System.Linq;
|
|
//using System.Text;
|
|
//using Autodesk.Revit.UI;
|
|
//using Autodesk.Revit.DB;
|
|
//using Autodesk.Revit.Attributes;
|
|
//using Autodesk.Revit.DB.Plumbing;
|
|
//using Autodesk.Revit.ApplicationServices;
|
|
//using Autodesk.Revit.DB.Events;
|
|
//using System.Data;
|
|
//using System.Collections;
|
|
//using Autodesk.Revit.UI.Selection;
|
|
//using System.Diagnostics;
|
|
//using KMBIM.Revit.Tools.Utils;
|
|
//using KMBIM;
|
|
|
|
//namespace COME4Revit
|
|
//{
|
|
|
|
// [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
|
|
// class CmdWritePipeSize : IExternalCommand
|
|
// {
|
|
// static string ExecutingAssemblyPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
|
|
|
|
// public Result Execute(
|
|
// ExternalCommandData commandData,
|
|
// ref string message,
|
|
// ElementSet elements)
|
|
// {
|
|
// UIApplication uiapp = commandData.Application;
|
|
// UIDocument uidoc = uiapp.ActiveUIDocument;
|
|
// Application app = uiapp.Application;
|
|
// Document doc = uidoc.Document;
|
|
// View view = doc.ActiveView;
|
|
|
|
|
|
// Autodesk.Revit.Creation.Application creApp = uiapp.Application.Create;
|
|
// Autodesk.Revit.Creation.Document creDoc = doc.Create;
|
|
|
|
// // ***********************************
|
|
// // 패밀리 파일 해당 위치에 복사
|
|
// // ***********************************
|
|
// string strTargetPath = ExecutingAssemblyPath.Replace("Pipe.dll", "");
|
|
|
|
// // Generic Annotation 패밀리 삽입
|
|
// const string family_nameH
|
|
// = "RTools_PA_Horizontal";
|
|
// const string family_nameV
|
|
// = "RTools_PA_Vertical";
|
|
|
|
|
|
|
|
// const string extension
|
|
// = ".rfa";
|
|
|
|
|
|
// string pathFamilyH = Util.GetFileName(family_nameH + extension, "pipe", false);
|
|
// string pathFamilyV = Util.GetFileName(family_nameV + extension, "pipe", false);
|
|
|
|
|
|
// string strFamily1 = strTargetPath + @"Family\"+family_nameH + extension;
|
|
// string strFamily2 = strTargetPath + @"Family\"+family_nameV + extension;
|
|
// if (System.IO.File.Exists(pathFamilyH) == false) System.IO.File.Copy(strFamily1, pathFamilyH);
|
|
// if (System.IO.File.Exists(pathFamilyV) == false) System.IO.File.Copy(strFamily2, pathFamilyV);
|
|
|
|
|
|
|
|
|
|
// List<XYZ> pts=new List<XYZ>();
|
|
// XYZ norm = XYZ.BasisZ;
|
|
// // 1. 치수를 표기할 파이프를 선택한다.
|
|
// //------------------------------------------------------------------------------------
|
|
// List<Pipe> lstPipe = new List<Pipe>();
|
|
// Pipe pipe=null;
|
|
// Element e = null;
|
|
|
|
|
|
// while(true){
|
|
// //e=Util.SelectSingleElementOfType(uidoc, typeof(Pipe), "파이프 선택:");
|
|
// Reference pickrefs = commandData.Application.ActiveUIDocument.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element);
|
|
// e = doc.GetElement(pickrefs);
|
|
// if (e == null) break;
|
|
// pipe = e as Pipe;
|
|
|
|
// lstPipe.Add(pipe);
|
|
// if (lstPipe.Count > 4) break;
|
|
// }
|
|
|
|
// bool bIsVertical = false;
|
|
|
|
// if (lstPipe.Count<1)
|
|
// {
|
|
// message = "파이프가 유효하지 않습니다.";
|
|
// }
|
|
// else
|
|
// {
|
|
|
|
|
|
// FamilyInstanceCreator crePipeFIH = new FamilyInstanceCreator(uiapp);
|
|
// crePipeFIH.CheckFamilySymbol(family_nameH, family_nameH);
|
|
// FamilyInstanceCreator crePipeFIV = new FamilyInstanceCreator(uiapp);
|
|
// crePipeFIV.CheckFamilySymbol(family_nameV, family_nameV);
|
|
|
|
// XYZ ptDraw = XYZ.Zero;
|
|
// try
|
|
// {
|
|
// ptDraw = uidoc.Selection.PickPoint("작도점 지시:");
|
|
|
|
// }
|
|
// catch (OperationCanceledException)
|
|
// {
|
|
// return Result.Succeeded;
|
|
// }
|
|
// catch (Exception)
|
|
// {
|
|
// return Result.Succeeded;
|
|
// }
|
|
|
|
// if (ptDraw == null) return Result.Succeeded;
|
|
|
|
|
|
|
|
// XYZ startPoint = new XYZ();
|
|
// XYZ endPoint = new XYZ();
|
|
|
|
// pipe = lstPipe[0];
|
|
// if (Util.GetStartEndPoint(pipe, ref startPoint, ref endPoint) == false) return Result.Succeeded;
|
|
|
|
|
|
|
|
// // 사이즈 표기 위치에서 첫번째 파이프에 가장 가까운 점을 찾는다.
|
|
// Line linePipe = Line.CreateBound(startPoint, endPoint);
|
|
// XYZ ptClosest = Util.GetPointOnLine(linePipe, ptDraw);
|
|
// XYZ ptDraw1 = new XYZ(ptDraw.X, ptDraw.Y, ptClosest.Z);
|
|
// XYZ baseX = ptClosest.X < ptDraw1.X ? -XYZ.BasisX : XYZ.BasisX;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Options options = uiapp.Application.Create.NewGeometryOptions();
|
|
// options.DetailLevel = ViewDetailLevel.Coarse;
|
|
|
|
// double dblOffsetElb = 0;
|
|
// FamilyInstance asfi = null;
|
|
|
|
// if (Math.Abs(ptDraw.X - ptClosest.X) < 1)
|
|
// {
|
|
// asfi = crePipeFIV.CreatePipeAnnotation(ptDraw, view);
|
|
// bIsVertical = true;
|
|
// }
|
|
// else asfi = crePipeFIH.CreatePipeAnnotation(ptDraw, view);
|
|
|
|
|
|
// bool bIsInvertDir = false;
|
|
// if (bIsVertical == false) bIsInvertDir = ptClosest.X < ptDraw1.X ? false : true;
|
|
// else bIsInvertDir = ptClosest.Y > ptDraw1.Y ? false : true;
|
|
|
|
|
|
// AnnotationSymbol pipeAS= null;
|
|
// AnnotationSymbolType ast=null;
|
|
// Definition df = null;
|
|
// if (asfi != null)
|
|
// {
|
|
// pipeAS = asfi as AnnotationSymbol;
|
|
// ast = pipeAS.AnnotationSymbolType;
|
|
// // Type Parameter
|
|
// df = GetDefinition(asfi, "OffsetElb");
|
|
// Parameter parmOffsetElb = asfi.get_Parameter(df);
|
|
// if (parmOffsetElb != null)
|
|
// {
|
|
// dblOffsetElb = Unit.CovertFromAPI(parmOffsetElb.DisplayUnitType, parmOffsetElb.AsDouble());
|
|
// }
|
|
|
|
// }
|
|
|
|
// XYZ ptDrawElb = ptDraw1;// +baseX * dblOffsetElb;
|
|
// XYZ vLeader = ptClosest - ptDrawElb;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// double btwAng = baseX.AngleTo(ptClosest - ptDrawElb);
|
|
|
|
// if (vLeader.Y < 0) btwAng = btwAng * -1.0;
|
|
|
|
// double degAng = Util.RTD(btwAng);
|
|
|
|
// ptClosest = Util.GetPointOnLine(linePipe, ptDrawElb);
|
|
|
|
// Line line1 = Line.CreateUnbound(ptDrawElb, ptClosest - ptDrawElb);
|
|
// //Util.NewDetailLine(uiapp, ptDrawElb, ptClosest);
|
|
// //Util.NewDetailLine(uiapp, ptDraw1, ptClosest);
|
|
// KDCS.Utils.Util.Pyosi(doc, ptDrawElb, 1);
|
|
// List<DimPipe> lstDimPipe=new List<DimPipe>();
|
|
// foreach(Pipe pipe1 in lstPipe){
|
|
// XYZ sp=new XYZ();
|
|
// XYZ ep=new XYZ();
|
|
// Util.GetStartEndPoint(pipe1, ref sp, ref ep);
|
|
// Line linePipe1 = Line.CreateUnbound(sp, sp - ep);
|
|
// XYZ pt1 = Util.GetCurvesIntersectionPoint(linePipe1, line1);
|
|
// KDCS.Utils.Util.Pyosi(doc, pt1, 1);
|
|
// DimPipe dim_pipe=new DimPipe();
|
|
// dim_pipe.Pipe = pipe1;
|
|
// dim_pipe.Pt = pt1;
|
|
// //dim_pipe.Distance = KDCS.Utils.Unit.FeetToMM(pt1.DistanceTo(ptDrawElb));
|
|
// dim_pipe.Distance = pt1.DistanceTo(ptDrawElb);
|
|
// lstDimPipe.Add(dim_pipe);
|
|
// }
|
|
|
|
|
|
// lstDimPipe.Sort(delegate(DimPipe p1, DimPipe p2)
|
|
// {
|
|
|
|
// return p1.Distance.CompareTo(p2.Distance)*-1;
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// //DetailCurve dLine = Util.NewDetailLine(uiapp, startPoint, endPoint);
|
|
|
|
// // 상세 라인 색상 변경
|
|
// //GraphicsStyle gs = dLine.LineStyle as GraphicsStyle;
|
|
// //gs.GraphicsStyleCategory.LineColor = new Color(250, 10, 10);
|
|
|
|
// // 텍스트노트
|
|
// // Util.NewTextNote(uiapp, startPoint, XYZ.BasisX, XYZ.BasisY, 5, TextAlignFlags.TEF_ALIGN_LEFT, "Hello NewTextNote");
|
|
|
|
|
|
|
|
|
|
|
|
// if (asfi != null)
|
|
// {
|
|
|
|
|
|
// //Leader Arrowhead
|
|
// pipeAS= asfi as AnnotationSymbol;
|
|
// ast=pipeAS.AnnotationSymbolType;
|
|
|
|
|
|
|
|
// Parameter temporaryParam = ast.get_Parameter(BuiltInParameter.LEADER_ARROWHEAD);
|
|
// if (bIsVertical == false)
|
|
// {
|
|
// df = GetDefinition(asfi, "AngleUp");
|
|
// Parameter parmAngUp = asfi.get_Parameter(df);
|
|
// if (parmAngUp != null)
|
|
// {
|
|
// using (Transaction trans = new Transaction(doc))
|
|
// {
|
|
// trans.Start("1");
|
|
// parmAngUp.Set(Unit.CovertToAPI(btwAng, parmAngUp.DisplayUnitType));
|
|
// trans.Commit();
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
// df = GetDefinition(pipeAS, "IsInvertDir");
|
|
// Parameter parmIsInvertDir = pipeAS.get_Parameter(df);
|
|
// if (parmIsInvertDir != null)
|
|
// {
|
|
// using (Transaction trans = new Transaction(doc))
|
|
// {
|
|
// trans.Start("1");
|
|
// parmIsInvertDir.Set(bIsInvertDir ? 1 : 0);
|
|
// trans.Commit();
|
|
// }
|
|
// }
|
|
|
|
|
|
|
|
// List<Element> listAST = new List<Element>();
|
|
// if (temporaryParam != null)
|
|
// {
|
|
// FilteredElementCollector collector = new FilteredElementCollector(uidoc.Document);
|
|
// ICollection<Element> founds = collector.WhereElementIsElementType().ToElements();
|
|
|
|
// ArrayList objs = new ArrayList();
|
|
// foreach (Element element in founds)
|
|
// {
|
|
// if(element.Name.Contains("Filled Dot"))
|
|
// objs.Add(element);
|
|
// }
|
|
|
|
// if (objs.Count > 0)
|
|
// {
|
|
// Element el1 = objs[0] as Element;
|
|
// temporaryParam.Set(el1.Id);
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// int k=0;
|
|
// List<string> lstSize = new List<string>();
|
|
// List<string> lstOffsetArrow = new List<string>();
|
|
// lstSize.Add("VisibleSize1");
|
|
// lstSize.Add("VisibleSize2");
|
|
// lstSize.Add("VisibleSize3");
|
|
// lstSize.Add("VisibleSize4");
|
|
// lstSize.Add("VisibleSize5");
|
|
// lstOffsetArrow.Add("OffsetArrow1");
|
|
// lstOffsetArrow.Add("OffsetArrow2");
|
|
// lstOffsetArrow.Add("OffsetArrow3");
|
|
// lstOffsetArrow.Add("OffsetArrow4");
|
|
// lstOffsetArrow.Add("OffsetArrow5");
|
|
|
|
|
|
// df = GetDefinition(view, "ProjectView");
|
|
// Parameter ParmPrjView=view.get_Parameter(df);
|
|
|
|
// for(int i=0; i<lstDimPipe.Count; i++)
|
|
// {
|
|
// using(Transaction trans = new Transaction(doc))
|
|
// {
|
|
// trans.Start("1");
|
|
// df = GetDefinition(pipeAS, lstSize[i]);
|
|
// Parameter parmVisible = pipeAS.get_Parameter(df);
|
|
// //parmOffsetArrow.Set(Unit.CovertToAPI(dimPipe.Distance, parmOffsetArrow.DisplayUnitType));
|
|
// parmVisible.Set(1);
|
|
// //System.Windows.Forms.MessageBox.Show("1");
|
|
// trans.Commit();
|
|
// }
|
|
// }
|
|
// //lstDimPipe.Reverse();
|
|
// for (int i = 0; i < lstDimPipe.Count; i++)
|
|
// {
|
|
// using (Transaction trans = new Transaction(doc))
|
|
// {
|
|
// trans.Start("1");
|
|
// df = GetDefinition(asfi, lstOffsetArrow[k]);
|
|
// Parameter parmOffsetArrow = asfi.get_Parameter(df);
|
|
// //parmOffsetArrow.Set(Unit.CovertToAPI(dimPipe.Distance, parmOffsetArrow.DisplayUnitType));
|
|
// //double setDist = lstDimPipe[i].Distance / view.Scale;
|
|
// double setDist = lstDimPipe[i].Distance / view.Scale;
|
|
// parmOffsetArrow.Set(setDist);
|
|
// //parmOffsetArrow.Set(Unit.CovertToAPI(dimPipe.Distance, parmOffsetArrow.DisplayUnitType));
|
|
// trans.Commit();
|
|
// }
|
|
// //break;
|
|
|
|
|
|
// //using(Transaction trans = new Transaction(doc))
|
|
// //{
|
|
// // trans.Start("1");
|
|
// // df = GetDefinition(pipeAS, lstSize[k]);
|
|
// // Parameter parm1 = pipeAS.get_Parameter(df);
|
|
// // df = GetDefinition(dimPipe.Pipe, "Diameter");
|
|
// // Parameter pipeSize1 = dimPipe.Pipe.get_Parameter(BuiltInParameter.RBS_PIPE_DIAMETER_PARAM);
|
|
// // double dblSize1 = Unit.CovertFromAPI(pipeSize1.DisplayUnitType, pipeSize1.AsDouble());
|
|
// // parm1.Set(dblSize1);
|
|
// // k++;
|
|
// // trans.Commit();
|
|
// //}
|
|
// //pipeAS.Leaders.get_Item(k).Elbow = ptDraw2;
|
|
// //pipeAS.Leaders.get_Item(k).End = dimPipe.Pt;
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
// return Result.Succeeded;
|
|
// }
|
|
|
|
// void OnDocumentChanged(object sender, DocumentChangedEventArgs e)
|
|
// {
|
|
// // this does not work, because the handler will
|
|
// // be called each time a new instance is added,
|
|
// // overwriting the previous ones recorded:
|
|
// //
|
|
// //_added_element_ids = e.GetAddedElementIds();
|
|
|
|
|
|
// }
|
|
|
|
// 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;
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
//}
|