bool CopyLineElement(Document sourceDocument, Document destinationDocument)
        {
            string tagViewName = "Viewr_LineStyle";

            View view = GetViewByName(sourceDocument, tagViewName);

            if (view == null)
            {
                return(false);
            }

            IList <ElementId>        copyElemIdList = new List <ElementId>();
            FilteredElementCollector elems          = new FilteredElementCollector(sourceDocument, view.Id);

            foreach (Element elem in elems.OfCategory(BuiltInCategory.OST_Lines))
            {
                DetailLine detailLine = elem as DetailLine;
                if (detailLine != null)
                {
                    copyElemIdList.Add(detailLine.LineStyle.Id);
                }
            }

            //copyElemIdList.GroupBy(a => a.IntegerValue).Select(b => b.First());
            copyElemIdList.Distinct(new ElementIdComparer());

            CopyPasteOptions options = new CopyPasteOptions();

            options.SetDuplicateTypeNamesHandler(new ElementCopyCoverHandler());
            ElementTransformUtils.CopyElements(sourceDocument, copyElemIdList, destinationDocument, null, options);

            return(true);
        }
        /// <summary>
        /// Create vertical dimensioning, cf.
        /// http://forums.autodesk.com/t5/revit-api-forum/how-can-i-create-dimension-line-that-is-not-parallel-to-detail/m-p/6801271
        /// </summary>
        void CreateVerticalDimensioning(ViewSection viewSection)
        {
            Document doc = viewSection.Document;

            XYZ point3 = new XYZ(417.8, 80.228, 46.8);
            XYZ point4 = new XYZ(417.8, 80.811, 46.3);

            Line geomLine3 = Line.CreateBound(point3, point4);
            Line dummyLine = Line.CreateBound(XYZ.Zero, XYZ.BasisY);

            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("tx");

                DetailLine line3 = doc.Create.NewDetailCurve(
                    viewSection, geomLine3) as DetailLine;

                DetailLine dummy = doc.Create.NewDetailCurve(
                    viewSection, dummyLine) as DetailLine;

                ReferenceArray refArray = new ReferenceArray();
                refArray.Append(dummy.GeometryCurve.Reference);
                refArray.Append(line3.GeometryCurve.GetEndPointReference(0));
                refArray.Append(line3.GeometryCurve.GetEndPointReference(1));
                XYZ  dimPoint1 = new XYZ(417.8, 80.118, 46.8);
                XYZ  dimPoint2 = new XYZ(417.8, 80.118, 46.3);
                Line dimLine3  = Line.CreateBound(dimPoint1, dimPoint2);

                Dimension dim = doc.Create.NewDimension(
                    viewSection, dimLine3, refArray);

                doc.Delete(dummy.Id);
                tx.Commit();
            }
        }
示例#3
0
        public static CurveElement NearestLinesToFace(PlanarFace face, IList <CurveElement> listLines)
        {
            CurveElement curveElement = null;
            double       num          = 0.0;

            foreach (CurveElement curveElement2 in listLines)
            {
                DetailLine detailLine = curveElement2 as DetailLine;
                bool       flag       = detailLine == null;
                if (!flag)
                {
                    XYZ    endPoint = detailLine.GeometryCurve.GetEndPoint(0);
                    double num2     = Facelibry.PointToFace(endPoint, face);
                    bool   flag2    = curveElement == null;
                    if (flag2)
                    {
                        num          = num2;
                        curveElement = curveElement2;
                    }
                    else
                    {
                        bool flag3 = num2 < num;
                        if (flag3)
                        {
                            num          = num2;
                            curveElement = curveElement2;
                        }
                    }
                }
            }
            return(curveElement);
        }
示例#4
0
        /// <summary>
        /// Draw all lines defined by the list of (start, end) points, which are bigger than the given tolerance.
        /// The lines are drawn as detail lines (DetailLine).
        /// </summary>
        /// <param name="view">The view to draw the lines in.</param>
        /// <param name="points">The list of (start, end) points of the lines.</param>
        /// <param name="tolerance">The smallest curve length allowed to be drawn. Lines smaller than this are not drawn.</param>
        static void drawLines(View view, IList <XYZ> points, double tolerance)
        {
            Plane plane = getAppropriatePlane(view);

            if (plane != null)
            {
                for (int ii = 0; ii < points.Count; ii++)
                {
                    UV     uvStart, uvEnd;
                    double distance = double.MaxValue;
                    plane.Project(points[ii], out uvStart, out distance);
                    plane.Project(points[ii + 1], out uvEnd, out distance);

                    XYZ projectionStart;
                    XYZ projectionEnd;
                    projectionStart = uvStart.U * plane.XVec + uvStart.V * plane.YVec + plane.Origin;
                    projectionEnd   = uvEnd.U * plane.XVec + uvEnd.V * plane.YVec + plane.Origin;

                    if (projectionStart.DistanceTo(projectionEnd) < tolerance)
                    {
                        ii++;
                        continue;
                    }

                    Line       geomLine = Line.CreateBound(projectionStart, projectionEnd);
                    DetailLine line     = view.Document.Create.NewDetailCurve(view, geomLine) as DetailLine;

                    ii++;
                }
            }
        }
示例#5
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            // Get application and document objects
            UIApplication uiApp = commandData.Application;

            try
            {
                // Implement Selection Filter to select curves
                IList <Element>  pickedRef = null;
                Selection        sel       = uiApp.ActiveUIDocument.Selection;
                DetailLineFilter selFilter = new DetailLineFilter();
                pickedRef = sel.PickElementsByRectangle(selFilter, "Select lines");

                // Measure their total length
                List <double> lengthList = new List <double>();
                foreach (Element e in pickedRef)
                {
                    DetailLine line = e as DetailLine;
                    if (line != null)
                    {
                        lengthList.Add(line.GeometryCurve.Length);
                    }
                }

                string lengthFeet        = Math.Round(lengthList.Sum(), 2).ToString() + " ft";
                string lengthMeters      = Math.Round(lengthList.Sum() * 0.3048, 2).ToString() + " m";
                string lengthMillimeters = Math.Round(lengthList.Sum() * 304.8, 2).ToString() + " mm";
                string lengthInch        = Math.Round(lengthList.Sum() * 12, 2).ToString() + " inch";

                StringBuilder sb = new StringBuilder();
                sb.AppendLine("Total Length is:");
                sb.AppendLine("");
                sb.AppendLine(lengthMillimeters);
                sb.AppendLine(lengthMeters);
                sb.AppendLine(lengthInch);
                sb.AppendLine(lengthFeet);

                // Return a message window that displays total length to user
                TaskDialog.Show("Line Length", sb.ToString());

                // Assuming that everything went right return Result.Succeeded
                return(Result.Succeeded);
            }
            // This is where we "catch" potential errors and define how to deal with them
            catch (Autodesk.Revit.Exceptions.OperationCanceledException)
            {
                // If user decided to cancel the operation return Result.Canceled
                return(Result.Cancelled);
            }
            catch (Exception ex)
            {
                // If something went wrong return Result.Failed
                message = ex.Message;
                return(Result.Failed);
            }
        }
示例#6
0
        public static void DrawInView(Document doc, View view, XYZ point)
        {
            XYZ   xyz = view.get_CropBox().get_Transform().get_Inverse().OfPoint(point);
            Plane byNormalAndOrigin = Plane.CreateByNormalAndOrigin(view.get_ViewDirection(), xyz);
            Arc   arc = Arc.Create(xyz, 10.0, 0.0, 2.0 * Math.PI, byNormalAndOrigin.get_XVec(), byNormalAndOrigin.get_YVec());

            SketchPlane.Create(doc, byNormalAndOrigin);
            DetailLine detailLine = ((ItemFactoryBase)doc.get_Create()).NewDetailCurve(view, (Curve)arc) as DetailLine;
        }
        public void UpdateDetailLine(DetailLineDTO detailLineDTO)
        {
            DetailLine detailLine = _mapper.Mapper().Map <DetailLine>(detailLineDTO);

            detailLine.InvoiceId = detailLineDTO.InvoiceDTOId;
            detailLine.Invoice   = _invoiceRepository.GetById(detailLine.InvoiceId);

            _detailLineRepository.UpdateEntity(detailLine);
            _detailLineRepository.Save();
        }
示例#8
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            //Get application and document objects
            UIApplication uiApp = commandData.Application;
            Document      doc   = uiApp.ActiveUIDocument.Document;
            UIDocument    uidoc = uiApp.ActiveUIDocument;

            try
            {
                IList <Element>  pickedRef = null;
                Selection        sel       = uiApp.ActiveUIDocument.Selection;
                DetailLineFilter selFilter = new DetailLineFilter();
                pickedRef = sel.PickElementsByRectangle(selFilter, "Select lines");

                List <double> lengthList = new List <double>();
                foreach (Element e in pickedRef)
                {
                    DetailLine line = e as DetailLine;
                    if (line != null)
                    {
                        lengthList.Add(line.GeometryCurve.Length);
                    }
                }

                string lengthFeet       = Math.Round(lengthList.Sum(), 2).ToString() + " ft";
                string lengthMeters     = Math.Round(lengthList.Sum() * 0.3048, 2).ToString() + " m";
                string lengthMilimeters = Math.Round(lengthList.Sum() * 304.8, 2).ToString() + " mm";
                string lengthInch       = Math.Round(lengthList.Sum() * 12, 2).ToString() + " inch";

                StringBuilder sb = new StringBuilder();
                sb.AppendLine("Total Length is:");
                sb.AppendLine(lengthFeet);
                sb.AppendLine(lengthInch);
                sb.AppendLine(lengthMeters);
                sb.AppendLine(lengthMilimeters);

                TaskDialog.Show("Line Length", sb.ToString());

                return(Result.Succeeded);
            }
            catch (Autodesk.Revit.Exceptions.OperationCanceledException)
            {
                return(Result.Cancelled);
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return(Result.Failed);
            }
        }
        public void Delete(DetailLineViewModel detailLineDTO)
        {
            try
            {
                DetailLine detailLine = mapper.MapDTO(detailLineDTO);
                _uow.DetailLineRepository.Delete(detailLine);

                _uow.SaveChanges();
            }
            catch (Exception ex)
            {
                new LogWriter(ex.ToString());
            }
        }
 public DetailLineViewModel FindById(int?id)
 {
     try
     {
         DetailLine detailLine = _uow.DetailLineRepository.FindById(id);
         detailLine.Product = _uow.ProductRepository.FindById(detailLine.ProductId);
         return(mapper.MapModel(detailLine));
     }
     catch (Exception ex)
     {
         new LogWriter(ex.ToString());
         throw;
     }
 }
示例#11
0
        public static string[] GetLinestyle(Document doc, Reference refLine)
        {
            //			width = 0;
            //			depth = 0;

            DetailLine line = doc.GetElement(refLine.ElementId) as DetailLine;

            string[] penoWidthDepth = line.LineStyle.Name.Split(' ')[3].Split('x');
            //string[] sa = line.LineStyle.Name.Split(' ');

            //			width = Int16.Parse(sa[0]);
            //			depth = Int16.Parse(sa[1]);

            return(penoWidthDepth);
        }
示例#12
0
        /// <summary>
        /// 详图线在区域内 或 与区域边界线相交
        /// </summary>
        public bool isDetaillineInorIntersectRegion(DetailLine detailLine, CurveArray _curveArray)
        {
            bool isInRegion = false;

            XYZ endPoint01 = detailLine.GeometryCurve.GetEndPoint(0);
            XYZ endPoint02 = detailLine.GeometryCurve.GetEndPoint(1);
            // z值 归零
            XYZ _endPoint01 = new XYZ(endPoint01.X, endPoint01.Y, 0);
            XYZ _endPoint02 = new XYZ(endPoint02.X, endPoint02.Y, 0);

            if (_Methods.IsInsidePolygon(_endPoint01, _curveArray) || _Methods.IsInsidePolygon(_endPoint02, _curveArray))
            {
                isInRegion = true;
            }
            return(isInRegion);
        }
示例#13
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;

            doc = uidoc.Document;
            Selection sel                 = uidoc.Selection;
            Reference rf                  = sel.PickObject(ObjectType.Element);
            ElementtransformToCopy kl     = new ElementtransformToCopy();
            Element        ele            = doc.GetElement(rf);
            FamilyInstance familyInstance = ele as FamilyInstance;
            FamilyInstance flat           = kl.GetFlat(doc, familyInstance);
            var            t1             = flat.GetReferences(FamilyInstanceReferenceType.StrongReference).First();
            var            t2             = flat.GetReferences(FamilyInstanceReferenceType.StrongReference).First();
            Transform      transform      = flat.GetTransform();
            EdgeArray      edgeArray      = kl.FlEdgeArray(flat);
            List <Edge>    list           = new List <Edge>();

            foreach (Edge i in edgeArray)
            {
                list.Add(i);
            }
            list.OrderBy(i => i.ApproximateLength).ToList();
            Edge           max            = list.Last();
            Curve          cure           = max.AsCurve();
            Line           lop            = cure as Line;
            ReferenceArray referenceArray = new ReferenceArray();
            XYZ            startpoint     = lop.GetEndPoint(0);
            XYZ            endpoint       = lop.GetEndPoint(1);

            using (Transaction tr = new Transaction(doc, "cre"))
            {
                tr.Start();
                Line       line       = Line.CreateBound(transform.OfPoint(startpoint), transform.OfPoint(endpoint));
                DetailLine detailLine = doc.Create.NewDetailCurve(doc.ActiveView, line) as DetailLine;
                referenceArray.Append(t1);
                referenceArray.Append(t2);
                var t = doc.Create.NewDimension(doc.ActiveView, line, referenceArray);
                tr.Commit();
            }
            return(Result.Succeeded);
        }
示例#14
0
 /// <summary>
 /// 修改详图线样式
 /// </summary>
 /// <param name="doc"></param>
 /// <param name="_tarLineStyleName"></param>
 /// <param name="_modelLine"></param>
 public static void SetLineStyle(Document doc, string _tarLineStyleName, DetailLine _DetailLine)
 {
     using (Transaction trans = new Transaction(doc))
     {
         trans.Start("trans");
         ICollection <ElementId> LineStyleIds = GetAllLineStyleIdsFromSetting(doc);
         foreach (ElementId _eleId in LineStyleIds)
         {
             GraphicsStyle _lineStyle = doc.GetElement(_eleId) as GraphicsStyle;
             string        _name      = _lineStyle.Name;
             if (_name == _tarLineStyleName)
             {
                 _DetailLine.LineStyle = _lineStyle;
             }
         }
         trans.Commit();
     }
 }
示例#15
0
        public bool AllowElement(Element elem)
        {
            DetailLine line = elem as DetailLine;

            if (line != null)
            {
                Line geoline = line.GeometryCurve as Line;
                if (geoline.Length < (501 / 304.8) && geoline.Length > (49 / 304.8))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            return(false);
        }
示例#16
0
        public List <DetailLine> GetDetailLines(Document doc, ElementId viewId)
        {
            FilteredElementCollector collector  = new FilteredElementCollector(doc, viewId);
            ICollection <Element>    Lines      = collector.OfClass(typeof(CurveElement)).WhereElementIsNotElementType().ToElements();
            List <DetailLine>        List_Lines = new List <DetailLine>();

            foreach (Element w in Lines)
            {
                DetailLine dl = w as DetailLine;
                if (dl == null)
                {
                    continue;
                }

                List_Lines.Add(dl);
            }

            return(List_Lines);
        }
示例#17
0
        public static void DrawInView(Document doc, View view, XYZ point)
        {
            // Create a geometry plane

            XYZ origin = view.CropBox.Transform.Inverse.OfPoint(point);
            XYZ normal = view.ViewDirection;

            Plane geomPlane = Plane.CreateByNormalAndOrigin(normal, origin);

            //Create a circle
            Arc geomCircle = Arc.Create(origin, 10, 0, 2.0 * Math.PI, geomPlane.XVec, geomPlane.YVec);


            // Create a sketch plane in current document

            SketchPlane.Create(doc, geomPlane);

            // Create a DetailLine element using the
            // newly created geometry line and sketch plane

            DetailLine line = doc.Create.NewDetailCurve(view, geomCircle) as DetailLine;
        }
示例#18
0
        /// <summary>
        /// 提取 详图线 或者 模型线 的 lines
        /// </summary>
        /// <param name="_Eles"></param>
        /// <returns></returns>
        public static List <Line> ConvetDocLinesTolines(List <Element> _Eles)
        {
            List <Line> _Lines = new List <Line>();

            foreach (Element _ele in _Eles)
            {
                if (_ele is DetailLine)
                {
                    DetailLine _DetailLine = _ele as DetailLine;
                    Curve      _Curve      = _DetailLine.GeometryCurve;
                    Line       _Line       = _Curve as Line;
                    _Lines.Add(_Line);
                }
                else if (_ele is ModelLine)
                {
                    ModelLine _ModelLine = _ele as ModelLine;
                    Curve     _Curve     = _ModelLine.GeometryCurve;
                    Line      _Line      = _Curve as Line;
                    _Lines.Add(_Line);
                }
                else if (_ele is DetailCurve)//将圆弧转化为多段线,取列表并集
                {
                    DetailCurve _DetaillArc = _ele as DetailCurve;
                    Curve       _Curve      = _DetaillArc.GeometryCurve;
                    List <Line> __Lines     = GetunClosedLinesFromArc(_Curve);//将圆弧划分成一定段数的线段相连
                    _Lines.AddRange(__Lines);
                }
                else if (_ele is ModelCurve)//将圆弧转化为多段线,取列表并集
                {
                    ModelCurve  _ModelArc = _ele as ModelCurve;
                    Curve       _Curve    = _ModelArc.GeometryCurve;
                    List <Line> __Lines   = GetunClosedLinesFromArc(_Curve);//将圆弧划分成一定段数的线段相连
                    _Lines.AddRange(__Lines);
                }
            }
            return(_Lines);
        }
示例#19
0
        /// <summary>
        /// Create wall system, floor, and allocate rooms
        /// </summary>

        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 appCreation = app.Create;
            Autodesk.Revit.Creation.Document    docCreation = doc.Create;

            // Access current selection
            Selection sel = uidoc.Selection;

            // Extraction of CurveElements by LineStyle WALL
            CurveElementFilter       filter       = new CurveElementFilter(CurveElementType.ModelCurve);
            FilteredElementCollector collector    = new FilteredElementCollector(doc);
            ICollection <Element>    founds       = collector.WherePasses(filter).ToElements();
            List <CurveElement>      importCurves = new List <CurveElement>();

            foreach (CurveElement ce in founds)
            {
                importCurves.Add(ce);
            }
            var          strayCurves = importCurves.Where(x => x.LineStyle.Name == "WALL").ToList();
            List <Curve> strayLines  = new List <Curve>();

            foreach (CurveElement ce in strayCurves)
            {
                strayLines.Add(ce.GeometryCurve as Line);
            }


            // Grab the current building level
            FilteredElementCollector colLevels = new FilteredElementCollector(doc)
                                                 .WhereElementIsNotElementType()
                                                 .OfCategory(BuiltInCategory.INVALID)
                                                 .OfClass(typeof(Level));
            Level firstLevel = colLevels.FirstElement() as Level;


            // Grab the building view
            // This may be useful when handling room allocation on separate levels
            //FilteredElementCollector colViews = new FilteredElementCollector(doc)
            //    .OfClass(typeof(View));
            //View firstView = colViews.FirstElement() as View;


            // Grab the building floortype
            FloorType floorType = new FilteredElementCollector(doc)
                                  .OfClass(typeof(FloorType))
                                  .First <Element>(e => e.Name.Equals("Generic 150mm")) as FloorType;


            // Modify document within a transaction
            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Generate Walls");

                List <CurveArray> curveGroup = RegionCluster(strayLines);
                //var (mesh, perimeter) = FlattenLines(curveGroup);

                Plane       Geomplane = Plane.CreateByNormalAndOrigin(XYZ.BasisZ, XYZ.Zero);
                SketchPlane sketch    = SketchPlane.Create(doc, Geomplane);

                foreach (CurveArray group in curveGroup)
                {
                    foreach (Curve edge in group)
                    {
                        DetailLine    axis = doc.Create.NewDetailCurve(view, edge) as DetailLine;
                        GraphicsStyle gs   = axis.LineStyle as GraphicsStyle;
                        gs.GraphicsStyleCategory.LineColor = new Color(202, 51, 82);
                        gs.GraphicsStyleCategory.SetLineWeight(7, gs.GraphicsStyleType);
                    }
                }


                /*
                 * Region detect and boolean union all have bugs to fix
                 * DO NOT TEST THIS ONE
                 *
                 *
                 *
                 * // Wall generation
                 * foreach (Curve wallAxis in mesh)
                 * {
                 *  Wall.Create(doc, wallAxis, firstLevel.Id, true);
                 * }
                 *
                 * // Create.NewRoom will automatically detect the topology according to the wall system
                 * // Don't bother sketching boundary lines unless you're handling a virtual room
                 * //docCreation.NewSpaceBoundaryLines(doc.ActiveView.SketchPlane, mesh, doc.ActiveView);
                 * doc.Regenerate();
                 *
                 * PlanTopology planTopology = doc.get_PlanTopology(firstLevel);
                 * if (doc.ActiveView.ViewType == ViewType.FloorPlan)
                 * {
                 *  foreach (PlanCircuit circuit in planTopology.Circuits)
                 *  {
                 *      if (null != circuit && !circuit.IsRoomLocated)
                 *      {
                 *          var room = doc.Create.NewRoom(null, circuit);
                 *          //Debug.Print("New room created!");
                 *      }
                 *  }
                 * }
                 * /* // add error handling here
                 * else
                 * {
                 *  System.Windows.Forms.MessageBox.Show("You can not create spaces in this plan view");
                 * }
                 */
                /*
                 * Floor newFloor = doc.Create.NewFloor(AlignCrv(perimeter), floorType, firstLevel, false, XYZ.BasisZ);
                 * newFloor.get_Parameter(BuiltInParameter.FLOOR_HEIGHTABOVELEVEL_PARAM).Set(0);
                 */

                tx.Commit();
            }


            return(Result.Succeeded);
        }
示例#20
0
        // Main thread
        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;

            Selection sel = uidoc.Selection;

            double tolerance = app.ShortCurveTolerance;

            // Pick Import Instance
            ImportInstance import = null;

            try
            {
                Reference r = uidoc.Selection.PickObject(ObjectType.Element, new Util.ElementsOfClassSelectionFilter <ImportInstance>());
                import = doc.GetElement(r) as ImportInstance;
            }
            catch
            {
                return(Result.Cancelled);
            }
            if (import == null)
            {
                System.Windows.MessageBox.Show("CAD not found", "Tips");
                return(Result.Cancelled);
            }

            List <Curve> columnCrvs = Util.TeighaGeometry.ShatterCADGeometry(uidoc, import, "COLUMN", tolerance);
            List <Curve> wallCrvs   = Util.TeighaGeometry.ShatterCADGeometry(uidoc, import, "WALL", tolerance);
            List <Curve> doorCrvs   = Util.TeighaGeometry.ShatterCADGeometry(uidoc, import, "DOOR", tolerance);
            List <Curve> windowCrvs = Util.TeighaGeometry.ShatterCADGeometry(uidoc, import, "WINDOW", tolerance);

            //List<Line> columnLines = Util.CrvsToLines(columnCrvs);
            //List<Line> wallLines = Util.CrvsToLines(wallCrvs);

            // Merge the overlapped wall boundaries
            // Seal the wall boundary by column block
            // INPUT List<Line> wallLines, List<Line> columnLines
            #region PATCH wallLines
            List <Line> patchLines = new List <Line>();
            List <XYZ>  sectPts    = new List <XYZ>();

            // Seal the wall when encountered with column
            foreach (Curve columnCrv in columnCrvs)
            {
                sectPts.Clear();
                foreach (Line wallCrv in wallCrvs)
                {
                    if (!Algorithm.IsParallel(columnCrv, wallCrv))
                    {
                        SetComparisonResult result = wallCrv.Intersect(columnCrv, out IntersectionResultArray results);
                        if (result != SetComparisonResult.Disjoint)
                        {
                            XYZ sectPt = results.get_Item(0).XYZPoint;
                            sectPts.Add(sectPt);
                        }
                    }
                    else
                    {
                        continue;
                    }
                }
                if (sectPts.Count() == 2)
                {
                    patchLines.Add(Line.CreateBound(sectPts[0], sectPts[1]));
                }
                if (sectPts.Count() > 2)  // not sure how to solve this
                {
                    Line minPatch = Line.CreateBound(XYZ.Zero, 10000 * XYZ.BasisX);
                    for (int i = 0; i < sectPts.Count(); i++)
                    {
                        for (int j = i + 1; j < sectPts.Count(); j++)
                        {
                            if (sectPts[i].DistanceTo(sectPts[j]) > 0.001)
                            {
                                Line testPatch = Line.CreateBound(sectPts[i], sectPts[j]);
                                if (testPatch.Length < minPatch.Length)
                                {
                                    minPatch = testPatch;
                                }
                            }
                        }
                    }
                    patchLines.Add(minPatch);
                }
            }

            // Patch for the wall lines
            wallCrvs.AddRange(patchLines);

            // Merge lines when they are parallel and almost intersected (knob)
            List <Curve> mergeLines = CloseGapAtBreakpoint(wallCrvs);

            //
            List <Curve> fixedLines = CloseGapAtCorner(mergeLines);

            #endregion
            // OUTPUT List<Line> fixedLines


            // INPUT List<Line> fixedLines
            #region Cluster the wallLines by hierarchy

            var wallClusters = Algorithm.ClusterByIntersect(fixedLines);
            Debug.Print("{0} clustered wall blocks in total", wallClusters.Count);

            // Generate boundingbox marker for the wall cluster
            List <List <Curve> > wallBlocks = new List <List <Curve> > {
            };
            foreach (List <Curve> cluster in wallClusters)
            {
                List <Curve> clusterCrv = cluster;
                if (null != Algorithm.CreateBoundingBox2D(clusterCrv))
                {
                    wallBlocks.Add(Algorithm.CreateBoundingBox2D(clusterCrv));
                }
            }
            Debug.Print("{0} clustered wall bounding boxes in total", wallBlocks.Count);

            #endregion
            // INPUT List<List< Curve >> wallClusters
            Debug.Print("WALL LINES PATCH & CLUSTERING COMPLETE!");


            // INPUT List<List<Curve>> wallClusters
            #region Iterate the generaion of axis

            // Wall axes
            List <Curve> axes = new List <Curve>();
            double       bias = Misc.MmToFoot(20);
            foreach (List <Curve> wallCluster in wallClusters)
            {
                List <Line> lines = Misc.CrvsToLines(wallCluster);
                for (int i = 0; i < lines.Count; i++)
                {
                    for (int j = 0; j < lines.Count - i; j++)
                    {
                        if (Algorithm.IsParallel(lines[i], lines[i + j]) &&
                            !Algorithm.IsIntersected(lines[i], lines[i + j]))
                        {
                            if (Algorithm.LineSpacing(lines[i], lines[i + j]) < Misc.MmToFoot(200) + bias &&
                                Algorithm.LineSpacing(lines[i], lines[i + j]) > Misc.MmToFoot(200) - bias &&
                                Algorithm.IsShadowing(lines[i], lines[i + j]))
                            {
                                if (Algorithm.GenerateAxis(lines[i], lines[i + j]) != null)
                                {
                                    axes.Add(Algorithm.GenerateAxis(lines[i], lines[i + j]));
                                    Debug.Print("got it!");
                                }
                            }
                        }
                    }
                }
            }
            #endregion
            // OUTPUT List<Line> axes
            Debug.Print("WALL AXIS ITERATION COMPLETE!");


            // INPUT List<Curve> doorCrvs
            // INPUT List<Curve> windowCrvs
            // INPUT List<Line> axes
            #region Merge axis joined/overlapped

            // Door axes
            var doorClusters = Algorithm.ClusterByIntersect(doorCrvs);
            List <List <Curve> > doorBlocks = new List <List <Curve> > {
            };
            foreach (List <Curve> cluster in doorClusters)
            {
                if (null != Algorithm.CreateBoundingBox2D(cluster))
                {
                    doorBlocks.Add(Algorithm.CreateBoundingBox2D(cluster));
                }
            }
            List <Curve> doorAxes = new List <Curve> {
            };
            foreach (List <Curve> doorBlock in doorBlocks)
            {
                List <Curve> doorFrame = new List <Curve> {
                };
                for (int i = 0; i < doorBlock.Count; i++)
                {
                    int         sectCount = 0;
                    List <Line> fenses    = new List <Line>();
                    foreach (Line line in fixedLines)
                    {
                        Curve testCrv = doorBlock[i].Clone();
                        SetComparisonResult result = RegionDetect.ExtendCrv(testCrv, 0.01).Intersect(line,
                                                                                                     out IntersectionResultArray results);
                        if (result == SetComparisonResult.Overlap)
                        {
                            sectCount += 1;
                            fenses.Add(line);
                        }
                    }
                    if (sectCount == 2)
                    {
                        XYZ projecting = fenses[0].Evaluate(0.5, true);
                        XYZ projected  = fenses[1].Project(projecting).XYZPoint;
                        if (fenses[0].Length > fenses[1].Length)
                        {
                            projecting = fenses[1].Evaluate(0.5, true);
                            projected  = fenses[0].Project(projecting).XYZPoint;
                        }
                        Line doorAxis = Line.CreateBound(projecting, projected);
                        doorAxes.Add(doorAxis);
                        //doorAxes.Add(doorBlock[i]);
                    }
                }
            }

            // Window axes
            var windowClusters = Algorithm.ClusterByIntersect(windowCrvs);

            List <List <Curve> > windowBlocks = new List <List <Curve> > {
            };
            foreach (List <Curve> cluster in windowClusters)
            {
                if (null != Algorithm.CreateBoundingBox2D(cluster))
                {
                    windowBlocks.Add(Algorithm.CreateBoundingBox2D(cluster));
                }
            }
            List <Curve> windowAxes = new List <Curve> {
            };
            foreach (List <Curve> windowBlock in windowBlocks)
            {
                Line axis1 = Line.CreateBound((windowBlock[0].GetEndPoint(0) + windowBlock[0].GetEndPoint(1)).Divide(2),
                                              (windowBlock[2].GetEndPoint(0) + windowBlock[2].GetEndPoint(1)).Divide(2));
                Line axis2 = Line.CreateBound((windowBlock[1].GetEndPoint(0) + windowBlock[1].GetEndPoint(1)).Divide(2),
                                              (windowBlock[3].GetEndPoint(0) + windowBlock[3].GetEndPoint(1)).Divide(2));
                if (axis1.Length > axis2.Length)
                {
                    windowAxes.Add(axis1);
                }
                else
                {
                    windowAxes.Add(axis2);
                }
            }


            axes.AddRange(windowAxes);
            axes.AddRange(doorAxes);
            Debug.Print("Checklist for axes: Door-{0}, Window-{1}, All-{2}", doorAxes.Count, windowAxes.Count,
                        axes.Count);
            List <Curve> axesExtended = new List <Curve>();
            foreach (Curve axis in axes)
            {
                axesExtended.Add(Algorithm.ExtendLine(axis, 200));
            }
            // Axis merge
            List <List <Curve> > axisGroups  = Algorithm.ClusterByOverlap(axesExtended);
            List <Curve>         centerLines = new List <Curve>();
            foreach (List <Curve> axisGroup in axisGroups)
            {
                var merged = Algorithm.FuseLines(axisGroup);
                centerLines.Add(merged);
            }

            #endregion
            // OUTPUT List<Line> centerLines
            Debug.Print("WINDOW / DOOR LINES JOINED!");


            // INPUT List<Curve> columnCrvs
            // INPUT List<Line> centerLines
            #region Extend and trim the axis (include column corner)

            List <List <Curve> > columnGroups = Algorithm.ClusterByIntersect(columnCrvs);
            foreach (List <Curve> columnGroup in columnGroups)
            {
                //List<Line> columnGrouplines = Util.CrvsToLines(columnGroup);
                List <Curve> nestLines = new List <Curve>();
                for (int i = 0; i < columnGroup.Count; i++)
                {
                    foreach (Line centerLine in centerLines)
                    {
                        SetComparisonResult result = columnGroup[i].Intersect(centerLine, out IntersectionResultArray results);
                        if (result == SetComparisonResult.Overlap)
                        {
                            for (int j = 0; j < columnGroup.Count; j++)
                            {
                                if (j != i)
                                {
                                    if (null != ExtendLine(centerLine, columnGroup[j]))
                                    {
                                        nestLines.Add(ExtendLine(centerLine, columnGroup[j]));
                                    }
                                }
                            }
                        }
                    }
                }
                Debug.Print("Got nested lines: " + nestLines.Count.ToString());
                if (nestLines.Count < 2)
                {
                    continue;
                }
                else
                {
                    centerLines.AddRange(nestLines);
                    int count = 0;
                    for (int i = 1; i < nestLines.Count; i++)
                    {
                        if (!Algorithm.IsParallel(nestLines[0], nestLines[i]))
                        {
                            count += 1;
                        }
                    }
                    if (count == 0)
                    {
                        var patches = Algorithm.CenterLinesOfBox(columnGroup);
                        foreach (Line patch in patches)
                        {
                            if (Algorithm.IsLineIntersectLines(patch, nestLines))
                            {
                                centerLines.Add(patch);
                            }
                        }
                    }
                }
            }

            #endregion
            // OUTPUT List<Line> centerLines
            Debug.Print("AXES JOINED AT COLUMN");


            // INPUT List<Line> centerLines
            //#The region detect function has fatal bug during boolean union operation
            #region Call region detection
            // Axis merge
            List <List <Curve> > tempStrays = Algorithm.ClusterByOverlap(centerLines);
            List <Curve>         strays     = new List <Curve>();
            foreach (List <Curve> tempStray in tempStrays)
            {
                Curve merged = Algorithm.FuseLines(tempStray);
                strays.Add(merged);
            }

            //var strayClusters = Algorithm.ClusterByIntersect(Util.LinesToCrvs(strays));
            //Debug.Print("Cluster of strays: " + strayClusters.Count.ToString());
            //Debug.Print("Cluster of strays[0]: " + strayClusters[0].Count.ToString());
            //Debug.Print("Cluster of strays[1]: " + strayClusters[1].Count.ToString());
            // The RegionCluster method should be applied to each cluster of the strays
            // It only works on a bunch of intersected line segments
            List <CurveArray> loops = RegionDetect.RegionCluster(strays);
            // The boolean union method of the loops needs to fix
            var perimeter      = RegionDetect.GetBoundary(loops);
            var recPerimeter   = CloseGapAtBreakpoint(perimeter);
            var arrayPerimeter = RegionDetect.AlignCrv(recPerimeter);
            for (int i = 0; i < arrayPerimeter.Size; i++)
            {
                Debug.Print("Line-{0} {1} {2}", i, Misc.PointString(arrayPerimeter.get_Item(i).GetEndPoint(0)),
                            Misc.PointString(arrayPerimeter.get_Item(i).GetEndPoint(1)));
            }
            #endregion
            // OUTPUT List<CurveArray> loops
            Debug.Print("REGION COMPLETE!");



            // Get the linestyle of "long-dashed"
            FilteredElementCollector fec = new FilteredElementCollector(doc)
                                           .OfClass(typeof(LinePatternElement));
            LinePatternElement linePatternElem = fec.FirstElement() as LinePatternElement;

            // Main visualization process
            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Generate Floor");

                // Draw wall patch lines

                /*
                 * foreach (Curve patchLine in patchLines)
                 * {
                 *  DetailLine axis = doc.Create.NewDetailCurve(view, patchLine) as DetailLine;
                 *  GraphicsStyle gs = axis.LineStyle as GraphicsStyle;
                 *  gs.GraphicsStyleCategory.LineColor = new Color(202, 51, 82);
                 *  gs.GraphicsStyleCategory.SetLineWeight(3, gs.GraphicsStyleType);
                 * }
                 */

                Plane       Geomplane = Plane.CreateByNormalAndOrigin(XYZ.BasisZ, XYZ.Zero);
                SketchPlane sketch    = SketchPlane.Create(doc, Geomplane);

                /*
                 * // Draw bounding boxes
                 * foreach (List<Curve> wallBlock in wallBlocks)
                 * {
                 *  foreach (Curve edge in wallBlock)
                 *  {
                 *      DetailLine axis = doc.Create.NewDetailCurve(view, edge) as DetailLine;
                 *      GraphicsStyle gs = axis.LineStyle as GraphicsStyle;
                 *      gs.GraphicsStyleCategory.LineColor = new Color(210, 208, 185);
                 *      gs.GraphicsStyleCategory.SetLineWeight(1, gs.GraphicsStyleType);
                 *      gs.GraphicsStyleCategory.SetLinePatternId(linePatternElem.Id, gs.GraphicsStyleType);
                 *  }
                 * }
                 */

                /*
                 * // Draw Axes
                 * Debug.Print("Axes all together: " + strays.Count.ToString());
                 * foreach (Line centerLine in strays)
                 * {
                 *  ModelCurve modelline = doc.Create.NewModelCurve(centerLine, sketch) as ModelCurve;
                 * }
                 */

                // Draw Regions

                foreach (CurveArray loop in loops)
                {
                    foreach (Curve edge in loop)
                    {
                        ModelCurve modelline = doc.Create.NewModelCurve(edge, sketch) as ModelCurve;
                    }
                }

                foreach (Curve edge in arrayPerimeter)
                {
                    DetailLine    axis = doc.Create.NewDetailCurve(view, edge) as DetailLine;
                    GraphicsStyle gs   = axis.LineStyle as GraphicsStyle;
                    gs.GraphicsStyleCategory.LineColor = new Color(202, 51, 82);
                    gs.GraphicsStyleCategory.SetLineWeight(8, gs.GraphicsStyleType);
                }


                tx.Commit();
            }

            return(Result.Succeeded);
        }
示例#21
0
 //DetailLine
 public DetailLineViewModel MapModel(DetailLine detailLine)
 {
     return(mapper.Map <DetailLineViewModel>(detailLine));
 }
示例#22
0
        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;
            Methods       methods = new Methods();

            //MainWindow mWindow = new MainWindow(doc);
            //mWindow.ShowDialog();

            //pick a detail line
            Reference lineRef = uidoc.Selection.PickObject(
                ObjectType.Element, new LineSelectionFilter(), "Pick a detail line.");
            DetailLine pickedLine = (DetailLine)uidoc.Document.GetElement(lineRef.ElementId);

            FilteredElementCollector lines = new FilteredElementCollector(doc);

            //manual filters
            List <DetailLine> detailLines = new List <DetailLine>();

            lines.OfClass(typeof(CurveElement));
            foreach (Element element in lines)
            {
                if (element is DetailLine)
                {
                    detailLines.Add(element as DetailLine);
                }
                else
                {
                    //do nothing
                }
            }
            List <DetailLine> filteredLines = new List <DetailLine>();

            foreach (DetailLine line in detailLines)
            {
                if (line.LineStyle.Name == pickedLine.LineStyle.Name &&
                    line.GroupId.IntegerValue == -1)
                {
                    filteredLines.Add(line);
                }
                else
                {
                    //do nothing
                }
            }

            //Pick a line based detail component =============(fill in element type)
            Reference componentRef = uidoc.Selection.PickObject(
                ObjectType.Element, new ComponentSelectionFilter(), "Pick a line-based detail component.");
            FamilyInstance pickedComponent = (FamilyInstance)uidoc.Document.GetElement(componentRef.ElementId);

            var componentType    = pickedComponent.Symbol;
            var replacementCount = 0;


            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Replace Lines");

                foreach (DetailLine line in filteredLines)
                {
                    var view = doc.GetElement(line.OwnerViewId) as View;

                    LocationCurve curve = line.Location as LocationCurve;
                    //XYZ start = curve.Curve.GetEndPoint(0);
                    //XYZ end = curve.Curve.GetEndPoint(1);
                    doc.Create.NewFamilyInstance(line.GeometryCurve as Line, componentType, view);
                    doc.Delete(line.Id);

                    replacementCount++;
                }


                tx.Commit();
            }

            TaskDialog.Show("Revit Task", "Replaced " + replacementCount + " detail lines.");

            return(Result.Succeeded);
        }
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app  = commandData.Application;
            Document      doc  = app.ActiveUIDocument.Document;
            View          view = doc.ActiveView;

            Autodesk.Revit.Creation.Application creApp = app.Application.Create;
            Autodesk.Revit.Creation.Document    creDoc = doc.Create;

            // Create a geometry line

            XYZ startPoint = new XYZ(0, 0, 0);
            XYZ endPoint   = new XYZ(10, 10, 0);

            //Line geomLine = creApp.NewLine( startPoint, endPoint, true ); // 2013

            Line geomLine = Line.CreateBound(startPoint, endPoint); // 2014

            // Create a geometry arc

            XYZ end0         = new XYZ(0, 0, 0);
            XYZ end1         = new XYZ(10, 0, 0);
            XYZ pointOnCurve = new XYZ(5, 5, 0);

            //Arc geomArc = creApp.NewArc( end0, end1, pointOnCurve ); // 2013

            Arc geomArc = Arc.Create(end0, end1, pointOnCurve); // 2014

#if NEED_PLANE
            // Create a geometry plane

            XYZ origin = new XYZ(0, 0, 0);
            XYZ normal = new XYZ(1, 1, 0);

            Plane geomPlane = creApp.NewPlane(
                normal, origin);

            // Create a sketch plane in current document

            SketchPlane sketch = creDoc.NewSketchPlane(
                geomPlane);
#endif // NEED_PLANE

            // Create a DetailLine element using the
            // newly created geometry line and sketch plane

            DetailLine line = creDoc.NewDetailCurve(
                view, geomLine) as DetailLine;

            // Create a DetailArc element using the
            // newly created geometry arc and sketch plane

            DetailArc arc = creDoc.NewDetailCurve(
                view, geomArc) as DetailArc;

            // Change detail curve colour.
            // Initially, this only affects the newly
            // created curves. However, when the view
            // is refreshed, all detail curves will
            // be updated.

            GraphicsStyle gs = arc.LineStyle as GraphicsStyle;

            gs.GraphicsStyleCategory.LineColor
                = new Color(250, 10, 10);

            return(Result.Succeeded);
        }
示例#24
0
文件: CMD2.cs 项目: inktan/RevitApi_
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument uiDoc      = commandData.Application.ActiveUIDocument;
            Document   doc        = uiDoc.Document;
            View       activeview = uiDoc.ActiveView;

            double radius = 12000 / 304.8;
            double offset = 2000 / 304.8;


            FilteredElementCollector collector_temp = new FilteredElementCollector(doc);

            collector_temp.OfCategory(BuiltInCategory.OST_Lines).WhereElementIsNotElementType();
            DetailLine dl_temp = null;

            foreach (Element elem in collector_temp)
            {
                if (elem is DetailLine)
                {
                    dl_temp = elem as DetailLine;
                }
            }
            if (dl_temp == null)
            {
                TaskDialog.Show("goa", "请用符号线绘制路中线"); return(Result.Failed);
            }
            ICollection <ElementId> collection_id_linestyle = dl_temp.GetLineStyleIds();
            List <GraphicsStyle>    list_linestyle          = new List <GraphicsStyle>();

            foreach (ElementId id in collection_id_linestyle)
            {
                list_linestyle.Add(doc.GetElement(id) as GraphicsStyle);
            }

            UI ui = new UI();

            ui.combobox.ItemsSource = list_linestyle;
            int l = -1;

            foreach (GraphicsStyle gs in list_linestyle)
            {
                l++;
                if (gs.Name == "C-FIRE-FLOW")
                {
                    break;
                }
            }
            ui.combobox.SelectedIndex = l;
            ui.ShowDialog();

            GraphicsStyle graphicsstyle = ui.combobox.SelectedItem as GraphicsStyle;

            radius = Convert.ToDouble(ui.textbox_radius.Text) / 304.8;
            offset = Convert.ToDouble(ui.textbox_offset.Text) / 2 / 304.8;



            //选择所有线
            IList <Element> list_DetailLines = uiDoc.Selection.PickElementsByRectangle(new SelectionFilter_DetailLine(), "选择符号线");
            List <Line>     list_line        = new List <Line>();

            foreach (Element elem in list_DetailLines)
            {
                DetailLine dl   = elem as DetailLine;
                Line       line = dl.GeometryCurve as Line;
                list_line.Add(line);
            }

            // List<Line> list_line_split = new List<Line>();
            //先打散所有线段.
            for (int i = 0; i < list_line.Count; i++)
            {
                for (int j = i + 1; j < list_line.Count; j++)
                {
                    if (list_line[i].Intersect(list_line[j]) == SetComparisonResult.Overlap)
                    {
                        List <Line> temps = SplitLine(list_line[i], list_line[j]);
                        if (temps == null)
                        {
                            continue;
                        }
                        list_line.RemoveAt(j);
                        list_line.RemoveAt(i);
                        list_line.AddRange(temps);
                        i--;
                        break;
                    }
                }
            }


            List <Arc> list_arc = new List <Arc>();



            //单线模式下,将两根线的转折点做倒角(排除3根及以上线汇到一个点的情况)
            for (int i = 0; i < list_line.Count; i++)
            {
                for (int c = 0; c < 2; c++)
                {
                    int temp = i;

                    List <int> list_int = new List <int>();    //收集与 i 线段 一个端点重合的 线段的索引值

                    XYZ point_i = list_line[i].GetEndPoint(c); //第一根线的第一个端点

                    for (int j = 0; j < list_line.Count; j++)  //判断 i 线段与 j 线段的关系
                    {
                        if (j == i)
                        {
                            continue;
                        }
                        XYZ point_start_j = list_line[j].GetEndPoint(0);                                    //拿出 j 线段的两个端点
                        XYZ point_end_j   = list_line[j].GetEndPoint(1);
                        if (point_i.IsAlmostEqualTo(point_start_j) || point_i.IsAlmostEqualTo(point_end_j)) //如果 i 线段与 j 线段 端点重合
                        {
                            list_int.Add(j);                                                                //如果重合,则把j索引值拿到列表中
                        }
                    }

                    if (list_int.Count == 1)//基于条件 判断是否倒角 如果收集的重合线段索引值只有1个,则开展倒角
                    {
                        int  j = list_int[0];
                        Line newline1;
                        Line newline2;
                        Arc  arc = Chamfer(list_line[i], list_line[j], radius, out newline1, out newline2);//进行倒角
                        list_arc.Add(arc);
                        list_line[i] = newline1;
                        list_line[j] = newline2;
                        i--; continue;
                    }
                    if (temp != i)
                    {
                        break;
                    }
                }
            }


            //偏移,从单线变为双线.
            List <Arc> list_temp = new List <Arc>();

            foreach (Arc arc in list_arc)
            {
                list_temp.Add(arc.CreateOffset(offset, new XYZ(0, 0, -1)) as Arc);
                list_temp.Add(arc.CreateOffset(offset, new XYZ(0, 0, 1)) as Arc);
            }
            list_arc = list_temp;

            List <Line> list_temp2 = new List <Line>();

            foreach (Line line in list_line)
            {
                list_temp2.Add(line.CreateOffset(offset, new XYZ(0, 0, -1)) as Line);
                list_temp2.Add(line.CreateOffset(offset, new XYZ(0, 0, 1)) as Line);
            }
            list_line = list_temp2;



            //将偏移后的线,倒角.
            List <Arc> list_arc_nooffset = new List <Arc>();

            for (int i = 0; i < list_line.Count; i++)
            {
                for (int j = 0; j < list_line.Count; j++)
                {
                    if (i == j)
                    {
                        continue;
                    }

                    //排除没有交点的线
                    IntersectionResultArray intersectionResultArray;
                    XYZ intersection;
                    if (list_line[i].Intersect(list_line[j], out intersectionResultArray) == SetComparisonResult.Overlap)
                    {
                        intersection = intersectionResultArray.get_Item(0).XYZPoint;
                    }
                    else
                    {
                        continue;
                    }

                    //排除首尾相接的线.(因为之前单线打断了以后才偏移,存在很多首尾相接的线)
                    XYZ point_start_temp  = list_line[i].GetEndPoint(0);
                    XYZ point_end_temp    = list_line[i].GetEndPoint(1);
                    XYZ point_start_temp2 = list_line[j].GetEndPoint(0);
                    XYZ point_end_temp2   = list_line[j].GetEndPoint(1);
                    if (point_start_temp.IsAlmostEqualTo(point_start_temp2) || point_start_temp.IsAlmostEqualTo(point_end_temp2) ||
                        point_end_temp.IsAlmostEqualTo(point_start_temp2) || point_end_temp.IsAlmostEqualTo(point_end_temp2))
                    {
                        continue;
                    }

                    Line newline1;
                    Line newline2;
                    Arc  arc = Chamfer(list_line[i], list_line[j], radius, out newline1, out newline2);
                    if (arc == null)
                    {
                        continue;
                    }
                    list_arc_nooffset.Add(arc);
                    list_line[i] = newline1;
                    list_line[j] = newline2;
                }
            }



            using (Transaction offset_line = new Transaction(doc))
            {
                offset_line.Start("start");
                foreach (Arc arc in list_arc_nooffset)
                {
                    DetailCurve dc1 = doc.Create.NewDetailCurve(activeview, arc);
                    DetailCurve dc2 = doc.Create.NewDetailCurve(activeview, arc);
                    dc1.LineStyle = graphicsstyle;
                    dc2.LineStyle = graphicsstyle;
                }
                foreach (Arc arc in list_arc)
                {
                    DetailCurve dc1 = doc.Create.NewDetailCurve(activeview, arc);
                    DetailCurve dc2 = doc.Create.NewDetailCurve(activeview, arc);
                    dc1.LineStyle = graphicsstyle;
                    dc2.LineStyle = graphicsstyle;
                }
                foreach (Line line in list_line)
                {
                    DetailCurve dc1 = doc.Create.NewDetailCurve(activeview, line);
                    DetailCurve dc2 = doc.Create.NewDetailCurve(activeview, line);
                    dc1.LineStyle = graphicsstyle;
                    dc2.LineStyle = graphicsstyle;
                }

                offset_line.Commit();
            }



            return(Result.Succeeded);
        }
示例#25
0
        private void Stream( ArrayList data, DetailLine detLine )
        {
            data.Add( new Snoop.Data.ClassSeparator( typeof( DetailLine ) ) );

              // nothing at this level
        }
示例#26
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app   = commandData.Application;
            UIDocument    uidoc = app.ActiveUIDocument;
            Document      doc   = uidoc.Document;
            View          view  = doc.ActiveView;

            Autodesk.Revit.Creation.Document creDoc
                = doc.Create;

            #region Check for pre-selected wall element
            Selection sel = uidoc.Selection;
            ICollection <ElementId> ids = sel.GetElementIds();

            if (1 == ids.Count)
            {
                Element e = doc.GetElement(ids.First <ElementId>());
                if (e is Wall)
                {
                    LocationCurve lc    = e.Location as LocationCurve;
                    Curve         curve = lc.Curve;

                    using (Transaction tx = new Transaction(doc))
                    {
                        tx.Start("Create Detail Line in Wall Centre");
                        creDoc.NewDetailCurve(view, curve);
                        tx.Commit();
                    }
                    return(Result.Succeeded);
                }
            }
            #endregion // Check for pre-selected wall element

            // Create a geometry line

            XYZ startPoint = new XYZ(0, 0, 0);
            XYZ endPoint   = new XYZ(10, 10, 0);

            //Line geomLine = creApp.NewLine( startPoint, endPoint, true ); // 2013

            Line geomLine = Line.CreateBound(startPoint, endPoint); // 2014

            // Create a geometry arc

            XYZ end0         = new XYZ(0, 0, 0);
            XYZ end1         = new XYZ(10, 0, 0);
            XYZ pointOnCurve = new XYZ(5, 5, 0);

            //Arc geomArc = creApp.NewArc( end0, end1, pointOnCurve ); // 2013

            Arc geomArc = Arc.Create(end0, end1, pointOnCurve); // 2014

#if NEED_PLANE
            // Create a geometry plane

            XYZ origin = new XYZ(0, 0, 0);
            XYZ normal = new XYZ(1, 1, 0);

            Plane geomPlane = creApp.NewPlane(
                normal, origin);

            // Create a sketch plane in current document

            SketchPlane sketch = creDoc.NewSketchPlane(
                geomPlane);
#endif // NEED_PLANE

            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Create Detail Line and Arc");

                // Create a DetailLine element using the
                // newly created geometry line and sketch plane

                DetailLine line = creDoc.NewDetailCurve(
                    view, geomLine) as DetailLine;

                // Create a DetailArc element using the
                // newly created geometry arc and sketch plane

                DetailArc arc = creDoc.NewDetailCurve(
                    view, geomArc) as DetailArc;

                // Change detail curve colour.
                // Initially, this only affects the newly
                // created curves. However, when the view
                // is refreshed, all detail curves will
                // be updated.

                GraphicsStyle gs = arc.LineStyle as GraphicsStyle;

                gs.GraphicsStyleCategory.LineColor
                    = new Color(250, 10, 10);

                tx.Commit();
            }
            return(Result.Succeeded);
        }
示例#27
0
 public static void CreateDetailLine(Curve c, Document doc, View v)
 {
     DetailLine dl = doc.Create.NewDetailCurve(v, c) as DetailLine;
 }
示例#28
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Autodesk.Revit.ApplicationServices.Application app = commandData.Application.Application;
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document   doc   = uidoc.Document;

            Autodesk.Revit.DB.View view = doc.ActiveView;
            ViewType vt = view.ViewType;

            if (vt == ViewType.FloorPlan || vt == ViewType.Elevation)
            {
                #region

                /*
                 * Reference eRef = uidoc.Selection.PickObject(ObjectType.Element, "Please pick a curve based element like wall.");
                 * Element element = doc.GetElement(eRef);
                 * if (eRef != null && element != null)
                 * {
                 *  XYZ dirVec = new XYZ();
                 *  //视图投影位置
                 *  XYZ viewNormal = view.ViewDirection;
                 *  //元素的曲线位置
                 *  LocationCurve locCurve = element.Location as LocationCurve;
                 *  if (locCurve == null || locCurve.Curve == null)
                 *  {
                 *      TaskDialog.Show("Prompt", "Selected element isn’t curve based!");
                 *      //  return Result.Cancelled;
                 *  }
                 *  //曲线开始坐标减去终点坐标并标准化
                 *  XYZ dirCur = locCurve.Curve.GetEndPoint(0).Subtract(locCurve.Curve.GetEndPoint(1)).Normalize();
                 *  //点积
                 *  double d = dirCur.DotProduct(viewNormal);
                 *  //点积是否为0  即这两个向量是否垂直
                 *  if (d > -0.000000001 && d < 0.000000001)
                 *  {
                 *      //交叉乘积
                 *      dirVec = dirCur.CrossProduct(viewNormal);
                 *      XYZ p0 = locCurve.Curve.GetEndPoint(0);
                 *      XYZ p2 = locCurve.Curve.GetEndPoint(1);
                 *
                 *      XYZ p1 = new XYZ(p0.X, p2.Y, 0);
                 *      XYZ dirLine = XYZ.Zero.Add(p0);
                 *      double distancep2 = p2.DistanceTo(p1);
                 *      double distancep0 = p0.DistanceTo(p1);
                 *      double slope = distancep2 / distancep0;
                 *      dirLine = dirLine.Subtract(p2);
                 *      //这几行主要设置标注的位置
                 *      XYZ newVec = XYZ.Zero.Add(dirVec);
                 *       newVec = newVec.Normalize().Multiply(10);
                 *       p1 = p1.Add(newVec);
                 *          p2 = p2.Add(newVec);
                 *     // TaskDialog.Show("Prompt", p0.ToString()+ p2.ToString()+ p1.ToString());
                 *      //end
                 *      Line newLine = Line.CreateBound(p1, p2);
                 *      ReferenceArray arrRefs = new ReferenceArray();
                 *
                 *      Options options = app.Create.NewGeometryOptions();
                 *      options.ComputeReferences = true;
                 *      options.DetailLevel = ViewDetailLevel.Fine;
                 *      GeometryElement gelement = element.get_Geometry(options);
                 *      foreach (var geoObject in gelement)
                 *      {
                 *          Solid solid = geoObject as Solid;
                 *          if (solid == null)
                 *              continue;
                 *
                 *          FaceArrayIterator fIt = solid.Faces.ForwardIterator();
                 *          while (fIt.MoveNext())
                 *          {
                 *              PlanarFace p = fIt.Current as PlanarFace;
                 *              if (p == null)
                 *                  continue;
                 *
                 *              p2 = p.FaceNormal.CrossProduct(dirLine);
                 *           if (p2.IsZeroLength())
                 *             {
                 *                  arrRefs.Append(p.Reference);
                 *              }
                 *              if (2 == arrRefs.Size)
                 *              {
                 *                  break;
                 *              }
                 *          }
                 *          if (2 == arrRefs.Size)
                 *          {
                 *              break;
                 *          }
                 *      }
                 *      if (arrRefs.Size != 2)
                 *      {
                 *          TaskDialog.Show("Prompt", "Couldn’t find enough reference for creating dimension");
                 *          //return Result.Cancelled;
                 *      }
                 *
                 *      Transaction trans = new Transaction(doc, "create dimension");
                 *      trans.Start();
                 *      doc.Create.NewDimension(doc.ActiveView, newLine, arrRefs);
                 *      TextNote text = AddNewTextNote(uidoc,p0,0.2,slope.ToString());
                 *      trans.Commit();
                 *  }
                 *  else
                 *  {
                 *      TaskDialog.Show("Prompt", "Selected element isn’t curve based!");
                 *      // return Result.Cancelled;
                 *  }
                 * }
                 * }
                 * else
                 * {
                 * TaskDialog.Show("Prompt", "Only support Plan View or Elevation View");
                 * }*/
                #endregion

                XYZ         pt1    = XYZ.Zero;
                XYZ         pt2    = new XYZ(10, 20, 0);
                XYZ         pt3    = new XYZ(30, 10, 0);
                Line        line1  = Line.CreateBound(pt1, pt2);
                Line        line2  = Line.CreateBound(pt2, pt3);
                Transaction trans1 = new Transaction(doc, "creaerwqte dimension");
                trans1.Start();
                //辅助线
                Line dummyLine = Line.CreateBound(XYZ.Zero, XYZ.BasisY);
                //辅助点
                XYZ pt0 = new XYZ(pt3.X, pt1.Y, 0);

                Line newLine  = Line.CreateBound(pt0, pt3);
                Line newLine2 = Line.CreateBound(pt0, pt1);

                DetailLine dummy       = doc.Create.NewDetailCurve(view, dummyLine) as DetailLine;
                DetailLine detailLine1 = doc.Create.NewDetailCurve(view, line1) as DetailLine;
                DetailLine detailLine2 = doc.Create.NewDetailCurve(view, line2) as DetailLine;

                ReferenceArray arrRefs = new ReferenceArray();
                arrRefs.Append(dummy.GeometryCurve.Reference);
                arrRefs.Append(detailLine1.GeometryCurve.GetEndPointReference(0));
                arrRefs.Append(detailLine2.GeometryCurve.GetEndPointReference(1));

                Dimension        newdimension     = doc.Create.NewDimension(view, newLine, arrRefs);
                Dimension        newdimension2    = doc.Create.NewDimension(view, newLine2, arrRefs);
                List <Dimension> linearDimensions = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Dimensions)
                                                    .Cast <Dimension>().Where(q => q.DimensionShape == DimensionShape.Linear).ToList();
                newdimension2 = linearDimensions[0];
                Arc arc = Arc.Create(pt1, pt3, pt2);
                IList <Reference> refe = new List <Reference>();
                refe.Add(detailLine1.GeometryCurve.GetEndPointReference(0));
                refe.Add(detailLine2.GeometryCurve.GetEndPointReference(1));
                FilteredElementCollector DimesionTypeCollector = new FilteredElementCollector(doc);
                DimesionTypeCollector.OfClass(typeof(DimensionType));

                DimensionType dimesionType = DimesionTypeCollector.Cast <DimensionType>().ToList().FirstOrDefault();
                //   DimensionType newdimesionType = dimesionType.Duplicate("new dimesionType") as DimensionType;
                //  newdimesionType.LookupParameter("Color").Set(125);
                AngularDimension dd = AngularDimension.Create(doc, view, arc, refe, dimesionType);
                //删除辅助线
                doc.Delete(dummy.Id);
                trans1.Commit();
            }
            return(Result.Succeeded);
        }
        public void DeleteDetailLine(DetailLineDTO detailLineDTO)
        {
            DetailLine detailLine = _mapper.Mapper().Map <DetailLine>(detailLineDTO);

            _detailLineRepository.DeleteEntity(detailLine);
        }