示例#1
0
        private void DrawAxisBlock(Point3d point, Vector3d direction, double chainage)
        {
            var doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            var db  = doc.Database;

            using (Transaction tr = db.TransactionManager.StartTransaction())
                using (BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead))
                    using (BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite))
                    {
                        // Draw block
                        ObjectId blockId = ObjectId.Null;
                        if (bt.Has(BlockName))
                        {
                            blockId = bt[BlockName];
                        }

                        // Chainage string
                        string chainageString = ChPrefix + AcadText.ChainageToString(chainage, ChPrecision);

                        // Insert block
                        BlockReference bref = new BlockReference(point, blockId);
                        bref.Rotation     = Vector3d.YAxis.GetAngleTo(direction, Vector3d.ZAxis);
                        bref.ScaleFactors = new Scale3d(1);

                        btr.AppendEntity(bref);
                        tr.AddNewlyCreatedDBObject(bref, true);

                        BlockTableRecord blockDef = tr.GetObject(blockId, OpenMode.ForRead) as BlockTableRecord;
                        foreach (ObjectId id in blockDef)
                        {
                            AttributeDefinition attDef = tr.GetObject(id, OpenMode.ForRead) as AttributeDefinition;
                            if ((attDef != null) && (!attDef.Constant))
                            {
                                // Create a new AttributeReference
                                AttributeReference attRef = new AttributeReference();
                                attRef.SetAttributeFromBlock(attDef, bref.BlockTransform);
                                if (string.Compare(attDef.Tag, AxisAttribute, true) == 0)
                                {
                                    attRef.TextString = AxisName;
                                }
                                else if (string.Compare(attDef.Tag, ChAttribute, true) == 0)
                                {
                                    attRef.TextString = chainageString;
                                }
                                bref.AttributeCollection.AppendAttribute(attRef);
                                tr.AddNewlyCreatedDBObject(attRef, true);
                            }
                        }

                        tr.Commit();
                    }
        }
示例#2
0
        /// <summary>
        /// 创建读取对象的ID编号
        /// </summary>
        /// <param name="Position">文字防止位置</param>
        /// <param name="Content">文字内容</param>
        /// <param name="Height">文字高度</param>
        private void WriteObjectID(double[] StartPosition, double[] endPosition, string Content)
        {
            double[] Position = new double[3] {
                0, 0, 0
            };
            double Height = 100;

            Position[0] = StartPosition[0] + (endPosition[0] - StartPosition[0]) / 2;
            Position[1] = StartPosition[1] + (endPosition[1] - StartPosition[1]) / 2;
            Position[2] = StartPosition[2] + (endPosition[2] - StartPosition[2]) / 2;
            var      caddocument = tAcadApplication.ActiveDocument;
            AcadText line        = caddocument.ModelSpace.AddText(Content, Position, Height);

            line.color = ACAD_COLOR.acByLayer;
            AcadObj    = line;
        }
示例#3
0
        public static void ShowDialog(string caption, string text)
        {
            using (HelpForm form = new HelpForm())
            {
                form.txtCaption.Text = caption;
                if (AcadText.IsRtfText(text))
                {
                    form.txtDialog.Rtf = text;
                }
                else
                {
                    form.txtDialog.Text = text;
                }

                int minWidth = TextRenderer.MeasureText(caption, form.txtCaption.Font).Width;

                Size size = form.txtDialog.GetPreferredSize(form.txtDialog.Size);
                form.Size = new Size(size.Width + 97, size.Height + 133);
                form.ShowDialog();
            }
        }
示例#4
0
        private void btnCaption_Click(object sender, EventArgs e)
        {
            // Caption - AcadText object to hold the reference of the AcadText
            AcadText Caption = default(AcadText);

            // Syntax for creating Text in AutoCAD
            // AcadApp.ActiveDocument.ModelSpace.AddText(TextString, InsertionPoint, Height);
            //
            // AcadApp        - Reference to the running instance of AutoCAD.
            // ActiveDocument - Represents the current working drawing in AutoCAD.
            // ModelSpace     - Work Area in the current drawing.
            // AddText        - Method, which adds a Text to the modelspace of the current drawing using the TextString, InsertionPoint and Height.
            // TextString     - string, which represents the text to be written.
            // InsertionPoint - 3 Dimensional double array variable holds the insertion point of the circle in the X, Y and Z axis.
            // Height         - Double variable holds the height of text.

            // Text to be written just below the circle as a caption.
            string TextString = "CIRCLE";

            // Definfing the insertion point for the circle, in this example, we are going to place the text just below the circle.
            double[] InsertionPoint = new double[3];

            // Getting Centerpoint of circle we have created earlier to define the insertion point for the Caption.
            double[] CenterOfCircle = (double[])Circle.Center;

            InsertionPoint[0] = CenterOfCircle[0] - Circle.Radius / 2;
            InsertionPoint[1] = CenterOfCircle[1] - (Circle.Radius + 50);
            InsertionPoint[2] = 0;

            // Defining height of the text
            double Height = 20;

            // Adding text to the modelspace and getting reference to the text created.
            Caption = AcadApp.ActiveDocument.ModelSpace.AddText(TextString, InsertionPoint, Height);

            // Changing the text color
            Caption.color = ACAD_COLOR.acGreen;
        }
示例#5
0
        public override void DrawCADObject(Autodesk.AutoCAD.Interop.AcadDocument AcadDoc)
        {
            double pX = double.Parse(this.X);
            double pY = double.Parse(this.Y);

            double[] InsertPoint = new double[] { pX, pY, 0 };

            string BlockName = "一般管线点";
            int    LayerID   = GetLayerIndex("0", AcadDoc);


            //string TrueType = GetTrueType(this.Type);
            if (this.Type == "雨水篦")
            {
                BlockName = "雨篦";
            }
            else if (this.Type == "检修井")
            {
                BlockName = "排水检修井";
            }
            else if (this.Type == "出水口")
            {
                BlockName = "出水口";
            }
            if (!string.IsNullOrEmpty(this.Type))
            {
                if (this.SURVEY_ID.StartsWith("WS"))
                {
                    LayerID = GetLayerIndex("WSPoint", AcadDoc);
                }
                else if (this.SURVEY_ID.StartsWith("YS"))
                {
                    LayerID = GetLayerIndex("YSPoint", AcadDoc);
                }
            }


            AcadDoc.ActiveLayer = AcadDoc.Layers.Item(LayerID);

            AcadMInsertBlock pAcadMInsertBlock = AcadDoc.ModelSpace.AddMInsertBlock(InsertPoint, BlockName, 1, 1, 1, 0, 1, 1, 1, 1);

            //pAcadMInsertBlock.TrueColor.SetRGB(255, 255, 255);
            AcadDictionary pAcadDictionary = pAcadMInsertBlock.GetExtensionDictionary();

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

            LayerID = GetLayerIndex("0", AcadDoc);
            if (!string.IsNullOrEmpty(this.Type))
            {
                if (this.SURVEY_ID.StartsWith("WS"))
                {
                    LayerID = GetLayerIndex("WSText", AcadDoc);
                }
                else if (this.SURVEY_ID.StartsWith("YS"))
                {
                    LayerID = GetLayerIndex("YSText", AcadDoc);
                }
            }
            AcadDoc.ActiveLayer = AcadDoc.Layers.Item(LayerID);

            AcadText pAcadText = AcadDoc.ModelSpace.AddText(this.SURVEY_ID, InsertPoint, 2.0);

            pAcadDictionary = pAcadText.GetExtensionDictionary();
            //pAcadDictionary.AddXRecord(ClassName);
            pAcadDictionary.AddXRecord(this.ID);
            AcadDoc.Save();
        }
示例#6
0
        public void PrintChainage()
        {
            if (!CheckLicense.Check())
            {
                return;
            }

            Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Autodesk.AutoCAD.DatabaseServices.Database    db  = doc.Database;

            ObjectId textStyleId = ObjectId.Null;

            using (Transaction tr = db.TransactionManager.StartTransaction())
                using (TextStyleTable tt = (TextStyleTable)tr.GetObject(db.TextStyleTableId, OpenMode.ForRead))
                {
                    if (tt.Has(TextStyleName))
                    {
                        textStyleId = tt[TextStyleName];
                    }
                    tr.Commit();
                }

            Matrix3d ucs2wcs = AcadUtility.AcadGraphics.UcsToWcs;
            Matrix3d wcs2ucs = AcadUtility.AcadGraphics.WcsToUcs;

            // Pick polyline
            bool     flag         = true;
            ObjectId centerlineId = ObjectId.Null;

            while (flag)
            {
                PromptEntityOptions entityOpts = new PromptEntityOptions("\nEksen: [Seçenekler]", "Settings");
                entityOpts.SetRejectMessage("\nSelect a curve.");
                entityOpts.AddAllowedClass(typeof(Curve), false);
                PromptEntityResult entityRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetEntity(entityOpts);

                if (entityRes.Status == PromptStatus.Keyword && entityRes.StringResult == "Settings")
                {
                    ShowSettings();
                    continue;
                }
                else if (entityRes.Status == PromptStatus.OK)
                {
                    centerlineId = entityRes.ObjectId;
                    break;
                }
                else
                {
                    return;
                }
            }

            // Start point
            Point3d           startPoint;
            PromptPointResult pointRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetPoint("\nBaşlangıç Noktası: ");

            if (pointRes.Status == PromptStatus.OK)
            {
                startPoint = pointRes.Value.TransformBy(ucs2wcs);
            }
            else
            {
                return;
            }

            // Start CH
            string       startCH   = "";
            PromptResult stringRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetString("\nBaşlangıç KM: <0+000.00>");

            startCH = stringRes.StringResult;
            if (stringRes.Status == PromptStatus.None)
            {
                startCH = "0+000.00";
            }
            else if (stringRes.Status != PromptStatus.OK)
            {
                return;
            }

            // Print chainages
            using (Transaction tr = db.TransactionManager.StartTransaction())
                using (BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite))
                    using (TextStyleTable tt = (TextStyleTable)tr.GetObject(db.TextStyleTableId, OpenMode.ForRead))
                    {
                        Autodesk.AutoCAD.DatabaseServices.Curve centerline = tr.GetObject(centerlineId, OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Curve;
                        if (centerline != null)
                        {
                            double curveStartCH          = AcadText.ChainageFromString(startCH) - centerline.GetDistAtPoint(startPoint);
                            double distToNearestInterval = Math.Ceiling(curveStartCH / Interval) * Interval - curveStartCH;
                            double currentDistance       = distToNearestInterval;
                            double curveLength           = centerline.GetDistanceAtParameter(centerline.EndParam);
                            while (currentDistance < curveLength)
                            {
                                string   currentCH    = AcadText.ChainageToString(currentDistance + curveStartCH, Precision);
                                Point3d  currentPoint = centerline.GetPointAtDist(currentDistance);
                                Vector3d perp         = centerline.GetFirstDerivative(currentPoint).RotateBy(Math.PI / 2.0, Vector3d.ZAxis);
                                perp /= perp.Length;
                                Point3d lineStart = currentPoint + perp * TextHeight / 2.0;
                                Point3d lineEnd   = currentPoint - perp * TextHeight / 2.0;
                                Point3d textStart = currentPoint + perp * TextHeight / 2.0 * 1.2;

                                // Tick mark
                                Line line = new Line();
                                line.StartPoint = lineStart;
                                line.EndPoint   = lineEnd;
                                btr.AppendEntity(line);
                                tr.AddNewlyCreatedDBObject(line, true);

                                // CH text
                                double             textRotation       = Vector3d.XAxis.GetAngleTo(perp, Vector3d.ZAxis);
                                double             rot                = textRotation * 180 / Math.PI;
                                TextHorizontalMode textHorizontalMode = TextHorizontalMode.TextLeft;
                                if (rot > 90.0 && rot < 270.0)
                                {
                                    textRotation       = textRotation + Math.PI;
                                    textHorizontalMode = TextHorizontalMode.TextRight;
                                }
                                textStyleId = ObjectId.Null;
                                if (tt.Has(TextStyleName))
                                {
                                    textStyleId = tt[TextStyleName];
                                }
                                DBText text = AcadEntity.CreateText(db, textStart, currentCH, TextHeight, textRotation, 0.8, textHorizontalMode, TextVerticalMode.TextVerticalMid, textStyleId);

                                btr.AppendEntity(text);
                                tr.AddNewlyCreatedDBObject(text, true);

                                currentDistance += Interval;
                            }
                        }

                        tr.Commit();
                    }
        }
示例#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();
        }
示例#8
0
        private bool GetAlignmentParameters()
        {
            var doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            var ed  = doc.Editor;

            Matrix3d ucs2wcs = AcadGraphics.UcsToWcs;
            Matrix3d wcs2ucs = AcadGraphics.WcsToUcs;

            // Alignment type
            Alignment = Bridge.PickAlignment();
            if (Alignment == Bridge.AlignmentType.None)
            {
                return(false);
            }

            // Alignment line
            PromptEntityOptions entityOpts = new PromptEntityOptions("\nEksen: ");

            entityOpts.SetRejectMessage("\nSelect a curve.");
            entityOpts.AddAllowedClass(typeof(Curve), false);
            PromptEntityResult entityRes = ed.GetEntity(entityOpts);

            if (entityRes.Status == PromptStatus.OK)
            {
                CenterlineId = entityRes.ObjectId;
            }
            else
            {
                return(false);
            }

            // Start point
            PromptPointResult ptRes = ed.GetPoint("\nBaşlangıç noktası: ");

            if (ptRes.Status == PromptStatus.OK)
            {
                StartPoint = ptRes.Value.TransformBy(ucs2wcs);
            }
            else
            {
                return(false);
            }

            // Start CH
            AcadEditor.PromptChainageOptions chOpts = new AcadEditor.PromptChainageOptions("\nBaşlangıç kilometresi: ");
            chOpts.DefaultValue    = AcadText.ChainageToString(StartCH, ChPrecision);
            chOpts.UseDefaultValue = true;
            AcadEditor.PromptChainageResult chRes = ed.GetChainage(chOpts);
            if (chRes.Status == PromptStatus.OK)
            {
                StartCH = chRes.DoubleResult;
            }
            else if (chRes.Status == PromptStatus.None)
            {
                // Use default
            }
            else if (chRes.Status != PromptStatus.OK)
            {
                return(false);
            }

            return(true);
        }