Ejemplo n.º 1
0
        public void Line(double[] Point1, double[] Point2, ACAD_COLOR LineColor)
        {
            AcadLine AClineSample = default(AcadLine);

            AClineSample       = AcadApp.ActiveDocument.ModelSpace.AddLine(Point1, Point2);
            AClineSample.color = LineColor;
        }
Ejemplo n.º 2
0
        public static double GetMidX(this AcadLine aline, double xx = 0, double yy = 0)
        {
            double[] st = (double[])aline.StartPoint;
            double[] ed = (double[])aline.EndPoint;


            return((st[0] + ed[0]) * 0.5);
        }
Ejemplo n.º 3
0
        private void btnLine_Click(object sender, EventArgs e)
        {
            //
            AcadLine Line = default(AcadLine);

            //  AcadLine acLine = new AcadLine(new AcadPoint(5, 5, 0), new AcadPoint(12, 3, 0));
            //Line = AcadApp.ActiveDocument.ModelSpace.AddLine(new AcadPoint(5, 5, 0),);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 高亮显示已标记部分
        /// </summary>
        /// <param name="StartPoint">起始点</param>
        /// <param name="EndPoint">结束点</param>
        /// <param name="Center">中心点</param>
        private void ReShow(double[] StartPoint, double[] EndPoint, double[] Center)
        {
            var caddocument = tAcadApplication.ActiveDocument;

            if (Center == null)
            {
                AcadLine line = caddocument.ModelSpace.AddLine(StartPoint, EndPoint);
                line.color = ACAD_COLOR.acByLayer;
                AcadObj    = line;
            }
            else
            {
                AcadCircle line = caddocument.ModelSpace.AddCircle(Center, 60);
                line.color = ACAD_COLOR.acByLayer;
                AcadObj    = line;
            }
        }
Ejemplo n.º 5
0
        static public LineLoop SearchLineLoop(AcadSelectionSet acadSelSet)
        {
            LineLoop        ret      = null;
            List <AcadLine> allLines = new List <AcadLine>();

            foreach (var item in acadSelSet)
            {
                try
                {
                    AcadLine L = (AcadLine)item;
                    allLines.Add(L);
                }
                catch (Exception)
                {
                    continue;
                }
            }



            return(ret);
        }
Ejemplo n.º 6
0
        public static void Test()
        {
            AcadApplication   AcadApp = (AcadApplication)Marshal.GetActiveObject("AutoCAD.Application.19");
            AcadDocument      doc     = AcadApp.ActiveDocument;
            AcadModelSpace    ms      = doc.ModelSpace;
            AcadSelectionSets SelSets = doc.SelectionSets;


            //SelSets.
            Console.WriteLine("请Tony选择中心线.");
            AcadSelectionSet cl = SelSets.Add(new Random().Next(1000, 9999).ToString());

            cl.Clear();
            cl.SelectOnScreen();
            Console.WriteLine("中心线选择完成.");


            Console.WriteLine("请Tony选择预应力筋.");
            AcadSelectionSet preBars = SelSets.Add(new Random().Next(1000, 9999).ToString());

            preBars.Clear();
            preBars.SelectOnScreen();
            Console.WriteLine("预应力钢筋选择完成,共计{0}根.", preBars.Count);

            Console.WriteLine("请Tony选择方向线.");
            AcadSelectionSet dirL = SelSets.Add(new Random().Next(1000, 9999).ToString());

            dirL.Clear();
            dirL.SelectOnScreen();
            List <AcadLine> NewDirLSet = new List <AcadLine>();

            foreach (var item in dirL)
            {
                AcadLine DirLine = (AcadLine)item;
                NewDirLSet.Add(DirLine);
            }
            NewDirLSet.Sort((x, y) => x.GetMidX().CompareTo(y.GetMidX()));

            Console.WriteLine("预应力钢筋选择完成,共计{0}根.", dirL.Count);

            AcadLWPolyline CLine = (AcadLWPolyline)cl.Item(0);


            FileStream   fs = new FileStream("D:\\TonyReadMe.csv", FileMode.Create);
            StreamWriter sw = new StreamWriter(fs);


            foreach (var bar in preBars)
            {
                sw.Flush();
                sw.Write("\n{0},", bar.ToString());
                //Console.WriteLine(bar.ToString());
                AcadLWPolyline PL = (AcadLWPolyline)bar;

                foreach (var item in NewDirLSet)
                {
                    double[] p1, p2;
                    double   dist;
                    try
                    {
                        AcadLine DirLine = item;

                        p1 = DirLine.IntersectWith(CLine, AcExtendOption.acExtendThisEntity);
                        p2 = DirLine.IntersectWith(PL, AcExtendOption.acExtendThisEntity);
                        if (p1.Count() == 0 || p2.Count() == 0)
                        {
                            continue;
                        }
                        dist = Math.Pow((p1[0] - p2[0]), 2) + Math.Pow((p1[1] - p2[1]), 2) + Math.Pow((p1[2] - p2[2]), 2);
                        dist = Math.Sqrt(dist);

                        int fx = p1[1] < p2[1] ? 1 : -1;

                        //Console.Write("{0:F0},",dist);

                        sw.Write("{0:F0},", fx * dist * 1000.0);
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }


                // Console.WriteLine("Length={0}", L.Length);
            }


            cl.Delete();
            preBars.Delete();
            dirL.Delete();

            sw.Close();
            fs.Close();
        }
Ejemplo n.º 7
0
        public override void DrawCADObject(Autodesk.AutoCAD.Interop.AcadDocument AcadDoc)
        {
            string Linetype = "合流";
            int    LayerID  = GetLayerIndex("YSLine", AcadDoc);

            if (this.US_SURVEY_ID.StartsWith("WS"))
            {
                LayerID  = GetLayerIndex("WSLine", AcadDoc);
                Linetype = "污水";
            }
            else if (this.US_SURVEY_ID.StartsWith("YS"))
            {
                Linetype = "雨水";
            }
            AcadDoc.ActiveLayer = AcadDoc.Layers.Item(LayerID);

            IPCPoint SPoint = GetPointByID(this.US_SURVEY_ID);
            IPCPoint EPoint = GetPointByID(this.DS_SURVEY_ID);

            double[] StartPoint = new double[3] {
                double.Parse(SPoint.X), double.Parse(SPoint.Y), 0
            };
            double[] EndPoint = new double[3] {
                double.Parse(EPoint.X), double.Parse(EPoint.Y), 0
            };
            AcadLine       pAcadLine       = AcadDoc.ModelSpace.AddLine(StartPoint, EndPoint);
            AcadDictionary pAcadDictionary = pAcadLine.GetExtensionDictionary();

            //pAcadDictionary.AddXRecord(ClassName);
            pAcadDictionary.AddXRecord(ID);

            string MinArrowVal = CIni.ReadINI("DrawCAD", "ArrowMin");
            bool   IsDrawArrow = false;

            if (string.IsNullOrEmpty(MinArrowVal))
            {
                IsDrawArrow = true;
            }
            else
            {
                double MinArrow = double.Parse(MinArrowVal);
                if (pAcadLine.Length < MinArrow)
                {
                    IsDrawArrow = false;
                }
                else
                {
                    IsDrawArrow = true;
                }
            }
            double[] MidPoint = new double[3] {
                (double.Parse(SPoint.X) + double.Parse(EPoint.X)) / 2, (double.Parse(SPoint.Y) + double.Parse(EPoint.Y)) / 2, 0
            };
            if (IsDrawArrow)
            {
                string           WidthValue = this.Width;
                AcadMInsertBlock pBlock     = AcadDoc.ModelSpace.AddMInsertBlock(MidPoint, "GP4", 1, 1, 1, 0, 1, 1, 1, 1);
                pBlock.Rotate(MidPoint, pAcadLine.Angle);
                pAcadDictionary = pBlock.GetExtensionDictionary();
                pAcadDictionary.AddXRecord(ID);
            }
            string MinLableVal = CIni.ReadINI("DrawCAD", "LableMin");

            if (!string.IsNullOrEmpty(MinLableVal))
            {
                double MinLable = double.Parse(MinLableVal);
                if (pAcadLine.Length < MinLable)
                {
                    return;
                }
            }
            string pUS_INVERT_LEVEL = double.Parse(SPoint.INVERT_LEVEL).ToString("0.000");
            string pDS_INVERT_LEVEL = double.Parse(EPoint.INVERT_LEVEL).ToString("0.000");
            string LineLable        = string.Format("{0} {1}m {2}Φ{3} {4}m", Linetype, pUS_INVERT_LEVEL, this.MATERIAL, this.Width, pDS_INVERT_LEVEL);

            LayerID = GetLayerIndex("YSZJ", AcadDoc);
            if (this.US_SURVEY_ID.StartsWith("WS"))
            {
                LayerID = GetLayerIndex("WSZJ", AcadDoc);
            }
            else
            {
                LayerID = GetLayerIndex("YSZJ", AcadDoc);
            }
            AcadDoc.ActiveLayer = AcadDoc.Layers.Item(LayerID);

            AcadText pAcadText = AcadDoc.ModelSpace.AddText(LineLable, MidPoint, 2.0);
            double   LineAngle = pAcadLine.Angle;

            if (LineAngle > Math.PI / 2 && LineAngle < 3 * Math.PI / 2)
            {
                LineAngle = LineAngle - Math.PI;
            }
            pAcadText.Rotate(MidPoint, LineAngle);
            pAcadDictionary = pAcadText.GetExtensionDictionary();
            //pAcadDictionary.AddXRecord(ClassName);
            pAcadDictionary.AddXRecord(ID);
            //}

            AcadDoc.Save();
        }