Beispiel #1
0
        /// <summary>
        /// 判断点在多边形内(包含凹凸多边形)
        /// </summary>
        /// <param name="po"></param>
        /// <param name="points"></param>
        /// <param name="planNorm"></param>
        /// <returns></returns>
        public static bool IsPointInRegion(XYZ po, List <XYZ> points, XYZ planNorm)
        {
            bool result = false;
            var  angles = 0.0;

            for (int i = 0; i < points.Count; i++)
            {
                if (i < points.Count - 1)
                {
                    var curpo  = points.ElementAt(i);
                    var nextpo = points.ElementAt(i + 1);

                    var line = Line.CreateBound(curpo, nextpo);
                    if (po.IsOnLine(line))
                    {
                        return(true);
                    }
                    var angle = Angle(curpo, nextpo, po, planNorm);
                    //MessageBox.Show(angle.ToString());
                    angles += angle;
                }
                else if (i == points.Count - 1)
                {
                    var curpo  = points.ElementAt(i);
                    var nextpo = points.ElementAt(0);

                    var line = Line.CreateBound(curpo, nextpo);
                    if (po.IsOnLine(line))
                    {
                        return(true);
                    }
                    var angle = Angle(curpo, nextpo, po, planNorm);
                    //MessageBox.Show(angle.ToString());
                    angles += angle;
                }
            }
            //MessageBox.Show(angles.ToString());
            angles = Math.Abs(angles);
            if (angles.IsEqual(2 * Math.PI))
            {
                result = true;
            }
            else
            {
                result = false;
            }
            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// 计算∠point1_point0_point2 的角度
        /// </summary>
        /// <param name="point1"></param>
        /// <param name="point2"></param>
        /// <param name="point0"></param>
        /// <param name="planNorm"></param>
        /// <returns></returns>
        public static double Angle(XYZ point1, XYZ point2, XYZ point0, XYZ planNorm)
        {
            var line = Line.CreateBound(point1, point2);

            if (point0.IsOnLine(line))
            {
                throw new Exception("samline Exception");
            }

            var vec1 = (point1 - point0).Normalize();
            var vec2 = (point2 - point0).Normalize();

            if (vec1.IsSameDirection(vec2))
            {
                return(0);
            }
            else if (vec1.IsOppositeDirection(vec2))
            {
                return(Math.PI);
            }
            var normal = default(XYZ);

            normal = vec1.CrossProduct(vec2).Normalize();
            var angle = vec1.AngleOnPlaneTo(vec2, normal);

            if (angle > Math.PI)
            {
                angle = angle - 2 * Math.PI;
            }
            return(angle * (normal.DotProduct(planNorm)));
        }
Beispiel #3
0
        public static bool IsPointInRegion(XYZ po, List <XYZ> points, XYZ planNorm)
        {
            bool result = false;
            var  angles = 0.0;

            for (int i = 0; i < points.Count; i++)
            {
                if (i < points.Count - 1)
                {
                    var curpo  = points.ElementAt(i); // 返回序列中的指定索引处的元素。LINQ命名空间下Enumerable类的方法
                    var nextpo = points.ElementAt(i + 1);

                    var line = Line.CreateBound(curpo, nextpo);

                    if (po.IsOnLine(line))
                    {
                        return(true);
                    }

                    var angle = Angle(curpo, nextpo, po, planNorm);
                    angle += angles;
                }
                else if (i == points.Count - 1)
                {
                    var curpo  = points.ElementAt(i);
                    var nextpo = points.ElementAt(0);

                    var line = Line.CreateBound(curpo, nextpo);
                    if (po.IsOnLine(line))
                    {
                        return(true);
                    }
                    var angle = Angle(curpo, nextpo, po, planNorm);
                    angles += angle;
                }
            }
            angles = Math.Abs(angles);
            if (angles.IsEqual(2 * Math.PI))
            {
                result = true;
            }
            else
            {
                result = false;
            }
            return(result);
        }
Beispiel #4
0
        public static MEPCurve BreakCurve(this MEPCurve mep, XYZ point)
        {
            var locationline = mep.LocationLine();
            var start        = locationline.StartPoint();
            var end          = locationline.EndPoint();
            var executeflag  = point.IsOnLine(locationline) && point.DistanceTo(start) > 1d.MetricToFeet() &&
                               point.DistanceTo(end) > 1d.MetricToFeet();

            if (!executeflag)
            {
                throw new Exception("点不在线上");
            }
            var doc = mep.Document;

#if Revit2016
            return(null);
#endif
#if Revit2019
            ElementId result = null;
            if (mep is Duct)
            {
                result = MechanicalUtils.BreakCurve(doc, mep.Id, point);
            }
            else if (mep is Pipe)
            {
                result = PlumbingUtils.BreakCurve(doc, mep.Id, point);
            }
            else if (mep is CableTray)
            {
                var newline1 = Line.CreateBound(start, point);
                var newline2 = Line.CreateBound(point, end);
                (mep.Location as LocationCurve).Curve = newline1;
                var newcabletray = CableTray.Create(doc, mep.GetTypeId(), point, end, mep.ReferenceLevel.Id);
                var para_w       = newcabletray.get_Parameter(BuiltInParameter.RBS_CABLETRAY_WIDTH_PARAM);
                var para_H       = newcabletray.get_Parameter(BuiltInParameter.RBS_CABLETRAY_HEIGHT_PARAM);
                para_w.Set(mep.Width);
                para_H.Set(mep.Height);
                result = newcabletray.Id;
            }
            return(result.GetElement(doc) as MEPCurve);
#endif
        }
Beispiel #5
0
        public List <FamilyInstance> CutBeam(FamilyInstance beam, XYZ point)
        {
            var result = new List <FamilyInstance>();
            var doc    = beam.Document;

            var locationcurve = beam.Location as LocationCurve;
            var locationline  = locationcurve.Curve as Line;

            if (locationline == null)
            {
                return(result);
            }

            point = point.ProjectToXLine(locationline);
            if (point.IsOnLine(locationline))
            {
                var start = locationline.StartPoint();
                var end   = locationline.EndPoint();

                var line1 = Line.CreateBound(start, point);
                var line2 = Line.CreateBound(point, end);

                (beam.Location as LocationCurve).Curve = line1;

                var copiedBeams = ElementTransformUtils.CopyElement(beam.Document, beam.Id, new XYZ());
                var beam2Id     = copiedBeams.First();
                var beam2       = beam2Id.GetElement(doc) as FamilyInstance;

                (beam2.Location as LocationCurve).Curve = line2;

                result.Add(beam);
                result.Add(beam2);
            }
            else
            {
                throw new Exception("point is not on beam,can not cut beam!");
            }

            return(result);
        }
Beispiel #6
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            var uiapp  = commandData.Application;
            var uidoc  = uiapp.ActiveUIDocument;
            var doc    = uidoc.Document;
            var sel    = uidoc.Selection;
            var acview = doc.ActiveView;

            while (true)
            {
                try
                {
                    var wireref = sel.PickObject(ObjectType.Element, doc.GetSelectionFilter(m => m is Wire));
                    var wire    = wireref.GetElement(doc) as Wire;
                    //var connectors = (wire).ConnectorManager.Connectors.PhysicalConToList();
                    var locationcurve = wire.Location as LocationCurve;

                    //var con1 = connectors.First();
                    //var con2 = connectors.Last();
                    //var origin1 = con1.Origin;
                    //var origin2 = con2.Origin;
                    //var dir1 = connectors.First().CoordinateSystem.BasisZ;
                    //var dir2 = connectors.Last().CoordinateSystem.BasisZ;

                    //var line1 = Line.CreateUnbound(origin1, dir1);
                    //var line2 = Line.CreateUnbound(origin2, dir2);

                    var intersection = default(XYZ);

                    //if (!(locationcurve.Curve is Line))
                    //{
                    //    MessageBox.Show("本功能不适应于曲线类型的导线");
                    //}

                    var tempoint    = sel.PickPoint();
                    var linefirst   = Line.CreateBound(wire.GetVertex(0), wire.GetVertex(1));
                    var vertexcount = wire.NumberOfVertices;
                    var linelast    = Line.CreateBound(wire.GetVertex(vertexcount - 2), wire.GetVertex(vertexcount - 1));

                    var globalpoint = wireref.GlobalPoint;

                    globalpoint = new XYZ(globalpoint.X, globalpoint.Y, linefirst.StartPoint().Z);


                    if (!globalpoint.IsOnLine(linefirst) && !globalpoint.IsOnLine(linelast))
                    {
                        MessageBox.Show("本功能不适应于曲线类型的导线 选择起始端或结束端导线"
                                        //+ Environment.NewLine +
                                        //globalpoint.IsOnLine(linefirst).ToString() + Environment.NewLine +
                                        //globalpoint.IsOnLine(linelast).ToString() + Environment.NewLine +
                                        //globalpoint.ToString() + Environment.NewLine +
                                        //linefirst.StartPoint().ToString() + Environment.NewLine +
                                        //linelast.StartPoint().ToString()
                                        );
                        continue;
                    }

                    Transaction ts1 = new Transaction(doc, "更改导线");
                    ts1.Start();
                    if (vertexcount > 2)
                    {
                        if (globalpoint.IsOnLine(linefirst))
                        {
                            tempoint = tempoint.ProjectToXLine(linefirst);
                            wire.SetVertex(0, tempoint);
                        }
                        else if (globalpoint.IsOnLine(linelast))
                        {
                            tempoint = tempoint.ProjectToXLine(linelast);
                            wire.SetVertex(vertexcount - 1, tempoint);
                        }
                    }
                    else if (vertexcount == 2)
                    {
                        var startpo = wire.GetVertex(0);
                        var endpo   = wire.GetVertex(1);
                        if (globalpoint.DistanceTo(startpo) < globalpoint.DistanceTo(endpo))
                        {
                            tempoint = tempoint.ProjectToXLine(linefirst);
                            wire.SetVertex(0, tempoint);
                        }
                        else
                        {
                            tempoint = tempoint.ProjectToXLine(linelast);
                            wire.SetVertex(vertexcount - 1, tempoint);
                        }
                    }
                    ts1.Commit();
                }
                catch (Exception)
                {
                    break;
                }
            }
            return(Result.Succeeded);
        }