예제 #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
        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();
                    }
        }
예제 #3
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);
        }