Exemplo n.º 1
0
    public void TestMethod()
    {
        Document activeDoc = Application.DocumentManager.MdiActiveDocument;
        Database db        = activeDoc.Database;
        Editor   ed        = activeDoc.Editor;

        PromptEntityOptions peo = new PromptEntityOptions("Select a polyline : ");

        peo.SetRejectMessage("Not a polyline");
        peo.AddAllowedClass(typeof(Autodesk.AutoCAD.DatabaseServices.Polyline), true);

        PromptEntityResult per = ed.GetEntity(peo);

        if (per.Status != PromptStatus.OK)
        {
            return;
        }

        ObjectId plOid = per.ObjectId;

        PromptPointResult ppr = ed.GetPoint(new PromptPointOptions("Select an internal point : "));

        if (ppr.Status != PromptStatus.OK)
        {
            return;
        }

        Point3d testPoint = ppr.Value;

        PromptAngleOptions pao

            = new PromptAngleOptions("Specify ray direction");

        pao.BasePoint = testPoint;

        pao.UseBasePoint = true;

        PromptDoubleResult rayAngle = ed.GetAngle(pao);

        if (rayAngle.Status != PromptStatus.OK)
        {
            return;
        }
        Point3d tempPoint = testPoint.Add(Vector3d.XAxis);

        tempPoint = tempPoint.RotateBy(rayAngle.Value, Vector3d.ZAxis, testPoint);

        Vector3d rayDir = tempPoint - testPoint;

        ClearTransientGraphics();
        _markers = new DBObjectCollection();
        using (Transaction tr = db.TransactionManager.StartTransaction())
        {
            Curve plcurve = tr.GetObject(plOid, OpenMode.ForRead) as Curve;

            for (int cnt = 0; cnt < 2; cnt++)
            {
                if (cnt == 1)
                {
                    rayDir = rayDir.Negate();
                }

                using (Ray ray = new Ray())
                {
                    ray.BasePoint = testPoint;

                    ray.UnitDir = rayDir;
                    Point3dCollection intersectionPts = new Point3dCollection();

                    plcurve.IntersectWith(ray, Intersect.OnBothOperands, intersectionPts, IntPtr.Zero, IntPtr.Zero);

                    foreach (Point3d pt in intersectionPts)
                    {
                        Circle marker = new Circle(pt, Vector3d.ZAxis, 0.2);
                        marker.Color = Autodesk.AutoCAD.Colors.Color.FromRgb(0, 255, 0);
                        _markers.Add(marker);

                        IntegerCollection intCol = new IntegerCollection();

                        TransientManager tm = TransientManager.CurrentTransientManager;
                        tm.AddTransient(marker, TransientDrawingMode.Highlight, 128, intCol);

                        ed.WriteMessage("\n" + pt.ToString());
                    }
                }
            }

            tr.Commit();
        }
    }
Exemplo n.º 2
0
        public void MakeCoordGrid()
        {
            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();
                }

            ObjectId textLayerId = AcadUtility.AcadEntity.GetOrCreateLayer(db, TextLayerName, Color.FromColorIndex(ColorMethod.ByAci, 1));
            ObjectId lineLayerId = AcadUtility.AcadEntity.GetOrCreateLayer(db, LineLayerName, Color.FromColorIndex(ColorMethod.ByAci, 3));

            ObjectId blockId = GetOrCreateBlock(db, BlockName, textLayerId, lineLayerId, textStyleId);

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

            // Pick polyline
            PromptPointResult ptRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetPoint("\nKöşe noktası: ");

            if (PolylineJig.Jig(ptRes.Value, out Point3dCollection points))
            {
                int xmin = int.MaxValue;
                int xmax = int.MinValue;
                int ymin = int.MaxValue;
                int ymax = int.MinValue;
                for (int i = 0; i < 4; i++)
                {
                    Point3d pt = points[i];
                    xmin = Math.Min(xmin, (int)pt.X); xmax = Math.Max(xmax, (int)pt.X);
                    ymin = Math.Min(ymin, (int)pt.Y); ymax = Math.Max(ymax, (int)pt.Y);
                }

                // Interval
                PromptIntegerOptions intOpts = new PromptIntegerOptions("\nAralık: ");
                intOpts.AllowNegative   = false;
                intOpts.AllowZero       = false;
                intOpts.AllowNone       = false;
                intOpts.DefaultValue    = Properties.Settings.Default.Command_COORDGRID_Interval;
                intOpts.UseDefaultValue = true;
                PromptIntegerResult intRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetInteger(intOpts);
                if (intRes.Status == PromptStatus.OK)
                {
                    Interval = intRes.Value;
                }
                else
                {
                    return;
                }

                // Round limits to multiples of the interval
                xmin = (int)Math.Floor((double)xmin / Interval) * Interval;
                xmax = (int)Math.Ceiling((double)xmax / Interval) * Interval;
                ymin = (int)Math.Floor((double)ymin / Interval) * Interval;
                ymax = (int)Math.Ceiling((double)ymax / Interval) * Interval;

                // Text height
                PromptDoubleOptions thOpts = new PromptDoubleOptions("\nYazı yüksekliği: ");
                thOpts.AllowNegative   = false;
                thOpts.AllowZero       = false;
                thOpts.AllowNone       = false;
                thOpts.DefaultValue    = Properties.Settings.Default.Command_COORDGRID_TextHeight;
                thOpts.UseDefaultValue = true;
                PromptDoubleResult thRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetDouble(thOpts);
                if (thRes.Status == PromptStatus.OK)
                {
                    TextHeight = thRes.Value;
                }
                else
                {
                    return;
                }

                // Save settings
                Properties.Settings.Default.Command_COORDGRID_TextHeight = TextHeight;
                Properties.Settings.Default.Command_COORDGRID_Interval   = Interval;
                Properties.Settings.Default.Save();

                // Print grid
                NumberFormatInfo nfi = (NumberFormatInfo)CultureInfo.InvariantCulture.NumberFormat.Clone();
                nfi.NumberGroupSeparator = " ";
                nfi.NumberDecimalDigits  = 0;

                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))
                        {
                            BlockTableRecord blockDef = (BlockTableRecord)tr.GetObject(blockId, OpenMode.ForRead);

                            for (int x = xmin; x <= xmax; x += Interval)
                            {
                                for (int y = ymin; y <= ymax; y += Interval)
                                {
                                    Point3d v = new Point3d(x, y, 0);
                                    if (!PolylineContains(points, v))
                                    {
                                        continue;
                                    }

                                    BlockReference blockRef = AcadUtility.AcadEntity.CreateBlockReference(db, blockId, v, TextHeight, 0);

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

                                    // Set attributes
                                    foreach (ObjectId id in blockDef)
                                    {
                                        AttributeDefinition attDef = tr.GetObject(id, OpenMode.ForRead) as AttributeDefinition;
                                        if (attDef != null)
                                        {
                                            using (AttributeReference attRef = new AttributeReference())
                                            {
                                                attRef.SetDatabaseDefaults(db);
                                                attRef.SetAttributeFromBlock(attDef, blockRef.BlockTransform);
                                                blockRef.AttributeCollection.AppendAttribute(attRef);
                                                tr.AddNewlyCreatedDBObject(attRef, true);
                                                attRef.TextString = attDef.Tag == "X" ? x.ToString("n", nfi) : y.ToString("n", nfi);
                                                attRef.AdjustAlignment(db);
                                            }
                                        }
                                    }
                                }
                            }

                            tr.Commit();
                        }
            }
        }
Exemplo n.º 3
0
 private static void handle_promptAngleResult(object sender, PromptDoubleResultEventArgs e)
 {
     useThisAngleResult = e.Result;
 }
Exemplo n.º 4
0
        public void fCreateLevel()
        {
            Editor ed = acApp.DocumentManager.MdiActiveDocument.Editor;

            try
            {
                // Get the current document and database, and start a transaction
                Document acDoc   = Application.DocumentManager.MdiActiveDocument;
                Database acCurDb = acDoc.Database;

                PromptDoubleOptions levelO = new PromptDoubleOptions("\nEnter level number:");
                levelO.DefaultValue = 0;
                PromptDoubleResult level = ed.GetDouble(levelO);

                using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
                {
                    // This example returns the layer table for the current database
                    LayerTable acLyrTbl;
                    acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId,
                                                 OpenMode.ForWrite) as LayerTable;

                    // Step through the Layer table and print each layer name
                    foreach (ObjectId acObjId in acLyrTbl)
                    {
                        LayerTableRecord acLyrTblRec;
                        acLyrTblRec = acTrans.GetObject(acObjId, OpenMode.ForWrite) as LayerTableRecord;

                        if (acLyrTblRec.Name.Contains("!FDS_") && acLyrTblRec.Name.Contains("("))
                        {
                            // Tutaj dodaj nowa warstwe ...

                            Regex regEx = new Regex(@"(.+)\(", RegexOptions.IgnoreCase);
                            Match match = regEx.Match(acLyrTblRec.Name);
                            if (match.Success)
                            {
                                System.Text.RegularExpressions.Group group = match.Groups[1];

                                LayerTableRecord acLyrTblRecNew = new LayerTableRecord();

                                // Assign the layer the ACI color 1 and a name
                                acLyrTblRecNew.Name  = group.ToString() + "(" + level.Value.ToString() + ")";
                                acLyrTblRecNew.Color = acLyrTblRec.Color;

                                // Append the new layer to the Layer table and the transaction
                                if (!acLyrTbl.Has(acLyrTblRecNew.Name))
                                {
                                    acLyrTbl.Add(acLyrTblRecNew);
                                    acTrans.AddNewlyCreatedDBObject(acLyrTblRecNew, true);
                                }
                            }

                            //acLyrTblRec.IsOff = true;
                        }
                    }
                    acTrans.Commit();
                }
                return;
            }
            catch (System.Exception e)
            {
                ed.WriteMessage("\nProgram exception: " + e.ToString());
                return;
            }
        }
        public void ImportFromKinect()
        {
            Document doc =
                Autodesk.AutoCAD.ApplicationServices.
                Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;

            // Get some user input for the number of snapshots...

            PromptIntegerOptions pio =
                new PromptIntegerOptions("\nNumber of captures");

            pio.AllowZero       = false;
            pio.DefaultValue    = _numShots;
            pio.UseDefaultValue = true;
            pio.UpperLimit      = 20;
            pio.LowerLimit      = 1;

            PromptIntegerResult pir = ed.GetInteger(pio);

            if (pir.Status != PromptStatus.OK)
            {
                return;
            }

            _numShots = pir.Value;

            // ... and the delay between them

            PromptDoubleOptions pdo =
                new PromptDoubleOptions("\nNumber of seconds delay");

            pdo.AllowZero           = false;
            pdo.AllowNegative       = false;
            pdo.AllowArbitraryInput = false;
            pdo.DefaultValue        = _delay;
            pdo.UseDefaultValue     = true;

            PromptDoubleResult pdr = ed.GetDouble(pdo);

            if (pdr.Status != PromptStatus.OK)
            {
                return;
            }

            _delay = pdr.Value;

            Transaction tr =
                doc.TransactionManager.StartTransaction();

            KinectDelayJig kj = new KinectDelayJig(_numShots, _delay);

            if (!kj.StartSensor())
            {
                ed.WriteMessage(
                    "\nUnable to start Kinect sensor - " +
                    "are you sure it's plugged in?"
                    );
                return;
            }

            PromptResult pr = ed.Drag(kj);

            if (pr.Status == PromptStatus.OK)
            {
                kj.StartTimer();
                pr = ed.Drag(kj);
            }
            kj.StopSensor();

            if (pr.Status != PromptStatus.OK && !kj.Finished)
            {
                tr.Dispose();
                return;
            }

            tr.Commit();

            // Manually dispose to avoid scoping issues with
            // other variables

            tr.Dispose();

            kj.WriteAndImportPointCloud(doc, kj.Vectors);
        }
Exemplo n.º 6
0
        public void DA_ElvtDenote()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor   ed  = doc.Editor;
            Database db  = doc.Database;
            //提示用户选择基准点
            PromptPointOptions ptOpt = new PromptPointOptions("\n请选择基准点或[上一个(P)/UCS(U)]<P>");

            ptOpt.Keywords.Add("P");                      //添加“上一个”关键字
            ptOpt.Keywords.Add("U");                      //添加“UCS”关键字
            ptOpt.Keywords.Default        = "P";          //默认关键字为“P”,即“上一个”
            ptOpt.AppendKeywordsToMessage = false;        //提示列表中不显示关键字
            PromptPointResult ptRes = ed.GetPoint(ptOpt); //获取基准点

            //如果即未选择点也未输入关键字,则发出错误信息,并返回
            if (ptRes.Status != PromptStatus.OK && ptRes.Status != PromptStatus.Keyword)
            {
                ed.WriteMessage("\n请选取基准点或输入关键字!");
                return;
            }
            //如果选取了基准点
            else if (ptRes.Status == PromptStatus.OK)
            {
                PromptDoubleOptions elvOpt = new PromptDoubleOptions("\n请输入该基准点标高");
                PromptDoubleResult  elvRes = ed.GetDouble(elvOpt);
                while (elvRes.Status != PromptStatus.OK)
                {
                    elvRes = ed.GetDouble(elvOpt);
                }
                baseElevation = ptRes.Value.Y - elvRes.Value;
            }
            else if (ptRes.Status == PromptStatus.Keyword)
            {
                switch (ptRes.StringResult)
                {
                case "P":
                    break;

                case "U":
                    baseElevation = 0;
                    break;
                }
            }
            PromptDoubleOptions douOpt = new PromptDoubleOptions($"\n请输入标注比例<{scaleFactor}>"); //提示输入标注比例

            douOpt.AllowNegative = false;                                                      //不允许负值
            douOpt.AllowZero     = false;                                                      //不允许0
            douOpt.AllowNone     = true;                                                       //允许回车
            PromptDoubleResult douRes = ed.GetDouble(douOpt);

            //输入正确时,设置标注比例
            if (douRes.Status == PromptStatus.OK)
            {
                scaleFactor = douRes.Value;
            }
            //输入回车时保留现比例
            else if (douRes.Status == PromptStatus.None)
            {
            }
            else
            {
                ed.WriteMessage("\n请输入正确比例!");
                return;
            }
            //提示用户选择标注点
            PromptPointOptions pteOpt = new PromptPointOptions("\n选择标注点");
            PromptPointResult  pteRes = ed.GetPoint(pteOpt);

            while (pteRes.Status == PromptStatus.OK)
            {
                //CreateElevationBlock();
                AddElevationAtt();
                InsertElevation(baseElevation, scaleFactor, pteRes.Value);
                pteRes = ed.GetPoint(pteOpt);
            }
            return;
        }
Exemplo n.º 7
0
        public ObjectId CreateCeDic()            //创建存储于NameObjectsDictionary的DataTable用于保存程序设置
                                                 //弯管类型存储在(0,0),半径在(0,1),半径倍率在(0,2),字高在(0,3),是否显示节点坐标(0,4)
        {
            const string dicname = "GCLCurveElementsConfig";
            ObjectId     DicId   = ObjectId.Null;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                try
                {
                    DBDictionary dd = (DBDictionary)trans.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForRead);
                    if (dd.Contains(dicname))
                    {
                        DicId = dd.GetAt(dicname);
                    }
                    else
                    {
                        DataTable dt = new DataTable();
                        dt.TableName = dicname;
                        dt.AppendColumn(CellType.Integer, "Type");
                        dt.AppendColumn(CellType.Double, "Diameter");
                        dt.AppendColumn(CellType.Double, "DiameterMultiple");
                        dt.AppendColumn(CellType.Double, "TextH");
                        DataCellCollection Row              = new DataCellCollection();
                        DataCell           Type             = new DataCell();
                        DataCell           Diameter         = new DataCell();
                        DataCell           DiameterMultiple = new DataCell();
                        DataCell           TextH            = new DataCell();

                        PromptKeywordOptions keyopts   = new PromptKeywordOptions("\n输入弯管的类型[冷弯(C)/热煨(H)/弹性敷设(E)]:", "C H E");
                        PromptResult         keyresult = ed.GetKeywords(keyopts);
                        if (keyresult.Status == PromptStatus.OK)
                        {
                            switch (keyresult.StringResult)
                            {
                            case "C":
                                Type.SetInteger((int)TypeOfCurveElements.cold);
                                break;

                            case "H":
                                Type.SetInteger((int)TypeOfCurveElements.hot);
                                break;

                            case "E":
                                Type.SetInteger((int)TypeOfCurveElements.elastic);
                                break;
                            }
                            PromptDoubleOptions doubleopts = new PromptDoubleOptions("\n输入弯管外径(mm):");
                            doubleopts.AllowNegative = false;
                            doubleopts.AllowZero     = false;

                            PromptDoubleResult doubleresult = ed.GetDouble(doubleopts);
                            if (doubleresult.Status == PromptStatus.OK)
                            {
                                Diameter.SetDouble(doubleresult.Value);

                                doubleopts.Message = "\n输入管径倍率:";
                                doubleresult       = ed.GetDouble(doubleopts);
                                if (doubleresult.Status == PromptStatus.OK)
                                {
                                    DiameterMultiple.SetDouble(doubleresult.Value);

                                    doubleopts.Message = "\n输入字高:";
                                    doubleresult       = ed.GetDouble(doubleopts);
                                    if (doubleresult.Status == PromptStatus.OK)
                                    {
                                        TextH.SetDouble(doubleresult.Value);
                                        Row.Add(Type);
                                        Row.Add(Diameter);
                                        Row.Add(DiameterMultiple);
                                        Row.Add(TextH);
                                        dt.AppendRow(Row, true);

                                        dd.UpgradeOpen();
                                        DicId = dd.SetAt(dicname, dt);
                                        trans.AddNewlyCreatedDBObject(dt, true);
                                    }
                                }
                            }
                        }
                    }


                    trans.Commit();
                }
                catch (Autodesk.AutoCAD.Runtime.Exception EX)
                {
                    ed.WriteMessage("\n出错了!" + EX.ToString());
                }
            }
            return(DicId);
        }
Exemplo n.º 8
0
        public void fCreateFdsLayer()
        {
            Editor ed = acApp.DocumentManager.MdiActiveDocument.Editor;

            try
            {
                while (true)
                {
                    PromptKeywordOptions typeOptions = new PromptKeywordOptions("\nChoose type");
                    typeOptions.Keywords.Add("Obst");
                    typeOptions.Keywords.Add("Vent");
                    typeOptions.Keywords.Add("Jetf");
                    typeOptions.Keywords.Add("Fire");
                    typeOptions.Keywords.Add("Devc");
                    typeOptions.Keywords.Add("Slcf");
                    typeOptions.AllowNone        = false;
                    typeOptions.Keywords.Default = "Obst";
                    PromptResult type = ed.GetKeywords(typeOptions);
                    if (type.Status != PromptStatus.OK || type.Status == PromptStatus.Cancel)
                    {
                        goto End;
                    }

                    PromptDoubleOptions levelOption = new PromptDoubleOptions("Enter level");
                    levelOption.AllowNone    = false;
                    levelOption.DefaultValue = levelOld;
                    PromptDoubleResult level = ed.GetDouble(levelOption);
                    if (level.Status != PromptStatus.OK || level.Status == PromptStatus.Cancel)
                    {
                        goto End;
                    }
                    if (level.Status == PromptStatus.OK)
                    {
                        levelOld = level.Value;
                    }

                    if (type.Status != PromptStatus.OK || type.Status == PromptStatus.Cancel)
                    {
                        goto End;
                    }
                    if (type.Status == PromptStatus.OK)
                    {
                        if (type.StringResult == "Obst")
                        {
                            while (true)
                            {
                                string name = getName();
                                if (name != "")
                                {
                                    CreateLayer("!FDS_OBST[" + name + "](" + level.Value.ToString() + ")", Color.FromColorIndex(ColorMethod.ByAci, 123));
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                        else if (type.StringResult == "Vent")
                        {
                            while (true)
                            {
                                string name = getName();
                                if (name != "")
                                {
                                    CreateLayer("!FDS_VENT[" + name + "](" + level.Value.ToString() + ")", Color.FromColorIndex(ColorMethod.ByAci, 6));
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                        else if (type.StringResult == "Jetf")
                        {
                            while (true)
                            {
                                string name = getName();
                                if (name != "")
                                {
                                    CreateLayer("!FDS_JETF[" + name + "](" + level.Value.ToString() + ")", Color.FromColorIndex(ColorMethod.ByAci, 54));
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                        else if (type.StringResult == "Fire")
                        {
                            while (true)
                            {
                                string name = getName();
                                if (name != "")
                                {
                                    CreateLayer("!FDS_FIRE[" + name + "](" + level.Value.ToString() + ")", Color.FromColorIndex(ColorMethod.ByAci, 1));
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                        else if (type.StringResult == "Devc")
                        {
                            while (true)
                            {
                                string name = getName();
                                if (name != "")
                                {
                                    CreateLayer("!FDS_DEVC[" + name + "](" + level.Value.ToString() + ")", Color.FromColorIndex(ColorMethod.ByAci, 7));
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                        else if (type.StringResult == "Slcf")
                        {
                            while (true)
                            {
                                string name = getName();
                                if (name != "")
                                {
                                    CreateLayer("!FDS_SLCF[" + name + "](" + level.Value.ToString() + ")", Color.FromColorIndex(ColorMethod.ByAci, 242));
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
                End :;
            }
            catch (System.Exception e)
            {
                ed.WriteMessage("\nProgram exception: " + e.ToString());
                return;
            }
        }
Exemplo n.º 9
0
        public void DrawingAmounts()
        {
            Document doc      = Application.DocumentManager.MdiActiveDocument;
            Database db       = doc.Database;
            Editor   ed       = doc.Editor;
            int      drwStyle = 0;                                               //张拉方式,0为两端张拉,-1为左端张拉,1为右端张拉

            using (Transaction trans = db.TransactionManager.StartTransaction()) //开始事务处理
            {
                //1.选择钢束线
                PromptEntityOptions tdLineOpt = new PromptEntityOptions("\n选择钢束或[张拉方式(D)/管道偏差系数(K)/摩阻系数(U)/张拉控制应力(C)]");
                tdLineOpt.SetRejectMessage("\n钢束应为多段线");
                tdLineOpt.AddAllowedClass(typeof(Polyline), true);//仅能选择多段线
                tdLineOpt.Keywords.Add("D");
                tdLineOpt.Keywords.Add("K");
                tdLineOpt.Keywords.Add("U");
                tdLineOpt.Keywords.Add("C");
                tdLineOpt.AppendKeywordsToMessage = false; //提示信息中不显示关键字
                for (;;)                                   //无限循环,直到选中钢束线为止
                {
                    PromptEntityResult tdLineRes = ed.GetEntity(tdLineOpt);
                    //2.各关键字下分别设置钢束张拉参数
                    if (tdLineRes.Status == PromptStatus.Keyword)
                    {
                        switch (tdLineRes.StringResult)
                        {
                        case "D":
                            PromptIntegerOptions drwOpt = new PromptIntegerOptions($"\n输入张拉方式[两端张拉(0)/左端张拉[-1]/右端张拉[1]<{drwStyle}>");
                            drwOpt.AllowNone = true;
                            PromptIntegerResult drwRes = ed.GetInteger(drwOpt);
                            if (drwRes.Value == 0)
                            {
                                drwStyle = 0;
                            }
                            else if (drwRes.Value == -1)
                            {
                                drwStyle = -1;
                            }
                            else if (drwRes.Value == 1)
                            {
                                drwStyle = 1;
                            }
                            break;

                        case "K":
                            PromptDoubleOptions kiiOpt = new PromptDoubleOptions($"\n设置管道偏差系数(1/m)<{kii}>");
                            kiiOpt.AllowNone     = true;
                            kiiOpt.AllowNegative = false;
                            kiiOpt.AllowZero     = false;
                            PromptDoubleResult kiiRes = ed.GetDouble(kiiOpt);
                            if (kiiRes.Status == PromptStatus.OK)
                            {
                                kii = kiiRes.Value;
                            }
                            break;

                        case "U":
                            PromptDoubleOptions miuOpt = new PromptDoubleOptions($"\n设置摩阻系数<{miu}>");
                            miuOpt.AllowNone     = true;
                            miuOpt.AllowNegative = false;
                            miuOpt.AllowZero     = false;
                            PromptDoubleResult miuRes = ed.GetDouble(miuOpt);
                            if (miuRes.Status == PromptStatus.OK)
                            {
                                miu = miuRes.Value;
                            }
                            break;

                        case "C":
                            PromptDoubleOptions ctrOpt = new PromptDoubleOptions($"\n设置张拉控制应力(MPa)<{ctrlStress}>");
                            ctrOpt.AllowNone = true;
                            PromptDoubleResult ctrRes = ed.GetDouble(ctrOpt);
                            if (ctrRes.Status == PromptStatus.OK)
                            {
                                ctrlStress = ctrRes.Value;
                            }
                            break;
                        }
                    }
                    //3.输出引伸量
                    else if (tdLineRes.Status == PromptStatus.OK)
                    {
                        ObjectId tdLineId = tdLineRes.ObjectId;
                        Polyline tdLine   = trans.GetObject(tdLineId, OpenMode.ForRead) as Polyline;
                        if (drwStyle == 0)//两端张拉
                        {
                            double[] drawAmounts = tdLine.BothDrawAmount(ctrlStress, kii, miu, Ep);
                            ed.WriteMessage("\n左侧引伸量:" + drawAmounts[0].ToString("F0") + "; " +
                                            "右侧引伸量:" + drawAmounts[1].ToString("F0") + "。");
                        }
                        else if (drwStyle == -1)//左侧张拉
                        {
                            double drawAmount = tdLine.SingleDrawAmount(ctrlStress, kii, miu, -1, Ep);
                            ed.WriteMessage("\n左侧引伸量:" + drawAmount.ToString("F0") + "。");
                        }
                        else if (drwStyle == 1)//右侧张拉
                        {
                            double drawAmount = tdLine.SingleDrawAmount(ctrlStress, kii, miu, 1, Ep);
                            ed.WriteMessage("\n右侧引伸量:" + drawAmount.ToString("F0") + "。");
                        }
                        break;
                    }
                    else
                    {
                        ed.WriteMessage("输入有误!");
                        return;
                    }
                }
                trans.Commit();//执行事务处理
            }
        }
Exemplo n.º 10
0
        public void ChangeConfig(ObjectId tableID)           //修改程序设置信息
        {
            DataCellCollection Row              = new DataCellCollection();
            DataCell           Type             = new DataCell();
            DataCell           Diameter         = new DataCell();
            DataCell           DiameterMultiple = new DataCell();
            DataCell           TextH            = new DataCell();

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                try
                {
                    DataTable dt = (DataTable)trans.GetObject(tableID, OpenMode.ForWrite);



                    PromptKeywordOptions keyopts = new PromptKeywordOptions("\n输入弯管的类型[冷弯(C)/热煨(H)/弹性敷设(E)]:", "C H E");
                    keyopts.AllowNone = true;

                    switch ((int)dt.GetCellAt(0, 0).Value)
                    {
                    case 1:
                        keyopts.Keywords.Default = "C";
                        break;

                    case 2:
                        keyopts.Keywords.Default = "H";
                        break;

                    case 3:
                        keyopts.Keywords.Default = "E";
                        break;
                    }

                    PromptResult keyresult = ed.GetKeywords(keyopts);
                    if (keyresult.Status == PromptStatus.OK || keyresult.Status == PromptStatus.None)
                    {
                        switch (keyresult.StringResult)
                        {
                        case "C":
                            Type.SetInteger((int)TypeOfCurveElements.cold);
                            break;

                        case "H":
                            Type.SetInteger((int)TypeOfCurveElements.hot);
                            break;

                        case "E":
                            Type.SetInteger((int)TypeOfCurveElements.elastic);
                            break;
                        }
                        PromptDoubleOptions doubleopts = new PromptDoubleOptions("\n输入弯管外径(mm):");
                        doubleopts.AllowNone       = true;
                        doubleopts.AllowNegative   = false;
                        doubleopts.AllowZero       = false;
                        doubleopts.UseDefaultValue = true;
                        doubleopts.DefaultValue    = (double)dt.GetCellAt(0, 1).Value;

                        PromptDoubleResult doubleresult = ed.GetDouble(doubleopts);
                        if (doubleresult.Status == PromptStatus.OK || doubleresult.Status == PromptStatus.None)
                        {
                            Diameter.SetDouble(doubleresult.Value);

                            doubleopts.Message      = "\n输入管径倍率:";
                            doubleopts.DefaultValue = (double)dt.GetCellAt(0, 2).Value;
                            doubleresult            = ed.GetDouble(doubleopts);
                            if (doubleresult.Status == PromptStatus.OK || doubleresult.Status == PromptStatus.None)
                            {
                                DiameterMultiple.SetDouble(doubleresult.Value);

                                doubleopts.Message      = "\n输入字高:";
                                doubleopts.DefaultValue = (double)dt.GetCellAt(0, 3).Value;
                                doubleresult            = ed.GetDouble(doubleopts);
                                if (doubleresult.Status == PromptStatus.OK || doubleresult.Status == PromptStatus.None)
                                {
                                    TextH.SetDouble(doubleresult.Value);
                                    Row.Add(Type);
                                    Row.Add(Diameter);
                                    Row.Add(DiameterMultiple);
                                    Row.Add(TextH);
                                    dt.SetRowAt(0, Row, true);
                                }
                            }
                        }
                    }
                }
                catch (Autodesk.AutoCAD.Runtime.Exception EX)
                {
                    ed.WriteMessage("\n出错了!" + EX.ToString());
                }
                trans.Commit();
            }
        }
Exemplo n.º 11
0
        public void TendonAnnotation()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db  = doc.Database;
            Editor   ed  = doc.Editor;

            db.SetDefaultOverallParams();//设置默认总体参数,已有总体参数字典项则无动作
            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                #region 1.选择梁顶缘线
                PromptEntityOptions tpLineOpt = new PromptEntityOptions("\n选择梁顶缘线");
                tpLineOpt.SetRejectMessage("\n顶缘线应为直线、圆弧或多段线");
                tpLineOpt.AddAllowedClass(typeof(Line), true);     //可以选择直线
                tpLineOpt.AddAllowedClass(typeof(Polyline), true); //可以选择多段线
                tpLineOpt.AddAllowedClass(typeof(Arc), true);      //可以选择圆弧线
                PromptEntityResult tpLineRes = ed.GetEntity(tpLineOpt);
                if (tpLineRes.Status != PromptStatus.OK)
                {
                    return;
                }
                ObjectId tpLineId = tpLineRes.ObjectId;
                Curve    tpLine   = trans.GetObject(tpLineId, OpenMode.ForRead) as Curve;
                #endregion
                #region 2.选择钢束线
                PromptEntityOptions tdLineOpt = new PromptEntityOptions("\n选择钢束");
                tdLineOpt.SetRejectMessage("\n钢束应为多段线");
                tdLineOpt.AddAllowedClass(typeof(Polyline), true);//仅能选择多段线
                PromptEntityResult tdLineRes = ed.GetEntity(tdLineOpt);
                if (tdLineRes.Status != PromptStatus.OK)
                {
                    return;
                }
                ObjectId tdLineId = tdLineRes.ObjectId;
                Polyline tdLine   = trans.GetObject(tdLineId, OpenMode.ForRead) as Polyline;

                //判断钢束线是否在顶缘线以内,否则报错返回
                if (tdLine.StartPoint.X < tpLine.StartPoint.X || tdLine.EndPoint.X > tpLine.EndPoint.X)
                {
                    Application.ShowAlertDialog("钢束线超出顶缘线,请检查!");
                    return;
                }
                tdLine.SetDefaultTendonParams();//设置钢束默认参数,如已有Xrecord信息则无动作
                #endregion
                #region 3.设置绘图参数(包括张拉方式和工作长度设置)
                //3.1 尺寸标注绘图位置及张拉方式和工作长度设置
                Point3d            pos    = new Point3d();//初始化标注点
                PromptPointOptions posOpt = new PromptPointOptions("\n设置标注线位置或设置[张拉方式(D)/工作长度(W)]");
                posOpt.Keywords.Add("D");
                posOpt.Keywords.Add("W");
                posOpt.AppendKeywordsToMessage = false;                                                      //提示信息中不显示关键字
                //获取钢束张拉方式
                int tdDrawStyle = 0;                                                                         //默认为两端张拉
                if (!tdLine.ExtensionDictionary.IsNull && tdLine.ObjectId.GetXrecord("tdDrawStyle") != null) //如果钢束线有扩展记录则取扩展记录数据
                {
                    tdDrawStyle = (Int16)tdLine.ObjectId.GetXrecord("tdDrawStyle")[0].Value;
                }
                //获取工作长度信息
                DBDictionary dicts = db.NamedObjectsDictionaryId.GetObject(OpenMode.ForWrite) as DBDictionary;
                if (dicts.Contains("DA_Tendons"))//如果字典中含DA_Tendons的字典项
                {
                    ObjectId       tdsDictId = dicts.GetAt("DA_Tendons");
                    DBDictionary   tdsDict   = tdsDictId.GetObject(OpenMode.ForRead) as DBDictionary; //获取DA_Tendons字典
                    ObjectId       xrecId    = tdsDict.GetAt("workLen");                              //获取字典中的工作长度项
                    Xrecord        xrec      = xrecId.GetObject(OpenMode.ForRead) as Xrecord;         //获取工作长度项中的Xrecird
                    TypedValueList vls       = xrec.Data;                                             //获取Xrecord中的TypedValueList数据
                    workLen = (double)vls[0].Value;                                                   //根据TypedValueList数据中的数值更新工作长度workLen
                }
                for (;;)
                {
                    PromptPointResult posRes = ed.GetPoint(posOpt);
                    if (posRes.Status == PromptStatus.Keyword)
                    {
                        switch (posRes.StringResult)
                        {
                        case "D":                    //选择修改张拉方式
                            PromptIntegerOptions drwOpt = new PromptIntegerOptions($"\n输入张拉方式[两端张拉(0)/左端张拉[-1]/右端张拉[1]<{tdDrawStyle}>");
                            drwOpt.AllowNone = true; //允许ESC退出
                            PromptIntegerResult drwRes = ed.GetInteger(drwOpt);
                            if (drwRes.Value == 0)
                            {
                                tdDrawStyle = 0;
                            }
                            else if (drwRes.Value == -1)
                            {
                                tdDrawStyle = -1;
                            }
                            else if (drwRes.Value == 1)
                            {
                                tdDrawStyle = 1;
                            }
                            TypedValueList values = new TypedValueList();    //根据输入更新钢束线的Xrecord记录
                            values.Add(DxfCode.Int16, tdDrawStyle);
                            tdLine.ObjectId.SetXrecord("tdDrawStyle", values);
                            break;

                        case "W":                    //修改工作长度
                            PromptDoubleOptions wklOpt = new PromptDoubleOptions($"\n输入工作长度<{workLen.ToString("F0")}>");
                            wklOpt.AllowNone = true; //允许ESC退出
                            PromptDoubleResult wklRes = ed.GetDouble(wklOpt);
                            if (wklRes.Status == PromptStatus.OK)
                            {
                                workLen = wklRes.Value;
                                ObjectId       tdsDictId = dicts.GetAt("DA_Tendons");//更新DA_Tendons字典中的钢束总体参数
                                DBDictionary   tdsDict   = tdsDictId.GetObject(OpenMode.ForRead) as DBDictionary;
                                ObjectId       xrecId    = tdsDict.GetAt("workLen");
                                Xrecord        xrec      = xrecId.GetObject(OpenMode.ForWrite) as Xrecord;
                                TypedValueList vls       = new TypedValueList();
                                vls.Add(DxfCode.Real, workLen);
                                xrec.Data = vls;
                                xrec.DowngradeOpen();
                            }
                            break;
                        }
                    }
                    else if (posRes.Status == PromptStatus.OK)
                    {
                        pos = posRes.Value;
                        break;
                    }
                }
                //3.2 绘图比例
                PromptDoubleOptions scaleOpt = new PromptDoubleOptions($"\n设置绘图比例<{scale}>");
                scaleOpt.AllowNone     = true;                        //允许回车,则采用前次比例
                scaleOpt.AllowNegative = false;                       //不允许负值
                scaleOpt.AllowZero     = false;                       //不允许零值
                PromptDoubleResult scaleRes = ed.GetDouble(scaleOpt); //获取比例
                if (scaleRes.Status != PromptStatus.OK && scaleRes.Status != PromptStatus.None)
                {
                    return;
                }
                else if (scaleRes.Status == PromptStatus.OK)
                {
                    scale = scaleRes.Value;
                }
                #endregion
                #region 4.建立各类标注
                List <Point3d>   ptsH = new List <Point3d>();   //创建水平标注点集
                List <Dimension> dims = new List <Dimension>(); //创建标注集,存放各类标注
                for (int i = 0; i < tdLine.NumberOfVertices - 1; i++)
                {
                    //4.1 水平点集
                    ptsH.Add(tdLine.GetPoint3dAt(i));

                    //4.2 每段钢束线的长度
                    //4.3 直线标注角度
                    //4.4 圆弧线标注半径
                    if (tdLine.GetSegmentType(i) == SegmentType.Line)
                    {
                        LineSegment3d lineSeg = tdLine.GetLineSegmentAt(i);
                        //4.2 每段钢束线的长度
                        db.LineLengthDim(lineSeg, scale);
                        //4.3 直线标注角度
                        if (tdLine.StartPoint.X < tdLine.EndPoint.X)
                        {
                            db.LineAngelDim(lineSeg, !(i == tdLine.NumberOfVertices - 2), scale);
                        }
                        else
                        {
                            db.LineAngelDim(lineSeg, (i == tdLine.NumberOfVertices - 2), scale);
                        }
                    }
                    else if (tdLine.GetSegmentType(i) == SegmentType.Arc)
                    {
                        CircularArc3d arcSeg = tdLine.GetArcSegmentAt(i);
                        //4.2 每段钢束线的长度
                        db.ArcLengthDim(arcSeg, scale);
                        //4.3 圆弧标注半径
                        db.ArrowRadiusDim(arcSeg, scale);
                    }
                    //4.5 竖直距离标注
                    Ray vRay = new Ray();//建立竖直射线
                    vRay.BasePoint = tdLine.GetPoint3dAt(i);
                    vRay.UnitDir   = new Vector3d(0, 1, 0);
                    Point3dCollection ptIntersects = new Point3dCollection();
                    tpLine.IntersectWith(vRay, Intersect.OnBothOperands, ptIntersects, IntPtr.Zero, IntPtr.Zero);
                    Point3d          ptIntersect = ptIntersects[0];
                    RotatedDimension dimV        = new RotatedDimension();
                    dimV.XLine1Point    = tdLine.GetPoint3dAt(i); //第一条尺寸边线
                    dimV.XLine2Point    = ptIntersect;            //第二条尺寸边线
                    dimV.DimLinePoint   = tdLine.GetPoint3dAt(i); //尺寸线位置
                    dimV.Rotation       = Math.PI / 2;            //标注旋转90度
                    dimV.DimensionStyle = db.Dimstyle;            //尺寸样式为当前样式
                    dimV.Dimscale       = scale;                  //设置尺寸全局比例
                    dims.Add(dimV);
                }
                //4.1 节点间距点集缺钢束最后一个点、梁顶缘线端点
                ptsH.Add(tdLine.EndPoint);
                ptsH.Add(tpLine.StartPoint);
                ptsH.Add(tpLine.EndPoint);
                db.ContinuedHorizontalDims(ptsH, pos, scale);//建立水平连续标注

                //4.5 竖直距离标注缺最后一个点
                Ray vRayLast = new Ray();//建立竖直射线
                vRayLast.BasePoint = tdLine.GetPoint3dAt(tdLine.NumberOfVertices - 1);
                vRayLast.UnitDir   = new Vector3d(0, 1, 0);
                Point3dCollection ptIntersectsLast = new Point3dCollection();
                tpLine.IntersectWith(vRayLast, Intersect.OnBothOperands, ptIntersectsLast, IntPtr.Zero, IntPtr.Zero);
                Point3d          ptIntersectLast = ptIntersectsLast[0];
                RotatedDimension dimVLast        = new RotatedDimension();
                dimVLast.XLine1Point    = tdLine.GetPoint3dAt(tdLine.NumberOfVertices - 1); //第一条尺寸边线
                dimVLast.XLine2Point    = ptIntersectLast;                                  //第二条尺寸边线
                dimVLast.DimLinePoint   = tdLine.GetPoint3dAt(tdLine.NumberOfVertices - 1); //尺寸线位置
                dimVLast.Rotation       = Math.PI / 2;                                      //标注旋转90度
                dimVLast.DimensionStyle = db.Dimstyle;                                      //尺寸样式为当前样式
                dimVLast.Dimscale       = scale;                                            //设置尺寸全局比例
                dims.Add(dimVLast);
                #endregion
                #region 5 绘制张拉端
                //5.1 获取张拉端几何特征
                //获取钢束线真实的起点和终点
                Point3d tdStart = (tdLine.StartPoint.X < tdLine.EndPoint.X) ? tdLine.StartPoint : tdLine.EndPoint;
                Point3d tdEnd   = (tdLine.StartPoint.X < tdLine.EndPoint.X) ? tdLine.EndPoint : tdLine.StartPoint;
                //获取钢束线真实的起终点角度
                double iclStart = (tdLine.StartPoint.X < tdLine.EndPoint.X) ?
                                  tdLine.GetLineSegmentAt(0).GetAngleOfLineSeg() : tdLine.GetLineSegmentAt(tdLine.NumberOfVertices - 2).GetAngleOfLineSeg();
                double iclEnd = (tdLine.StartPoint.X < tdLine.EndPoint.X) ?
                                tdLine.GetLineSegmentAt(tdLine.NumberOfVertices - 2).GetAngleOfLineSeg() : tdLine.GetLineSegmentAt(0).GetAngleOfLineSeg();
                //初始化张拉端图元
                Polyline leftDraw  = new Polyline();
                Polyline rightDraw = new Polyline();
                MText    lengthL   = new MText();
                MText    lengthR   = new MText();
                //5.2 左侧张拉端
                //5.2.1 两侧张拉或左侧张拉时左端绘制工作长度线
                if (tdDrawStyle == 0 || tdDrawStyle == -1)
                {
                    //创建张拉端几何点
                    Point3d tdDrawL = GeTools.PolarPoint(tdStart, iclStart, -workLen);
                    //创建张拉段
                    leftDraw = new Polyline();
                    leftDraw.AddVertexAt(0, tdStart.ToPoint2d(), 0, 0, 0);
                    leftDraw.AddVertexAt(1, tdDrawL.ToPoint2d(), 0, 0, 0);
                    leftDraw.Layer = tdLine.Layer;//张拉段与钢束线应该在同一层
                    //标注左侧张拉段
                    lengthL = new MText();
                    //长度
                    lengthL.Contents = "工作长度800";
                    //文字高度
                    lengthL.TextHeight = 3 * scale;
                    //样式为当前样式
                    lengthL.TextStyleId = db.Textstyle;
                    //旋转角度同直线段倾角
                    lengthL.Rotation = iclStart;
                    //对齐位置为右上
                    lengthL.Attachment = AttachmentPoint.TopRight;
                    //位置为中点垂线以下0.5个单位
                    lengthL.Location = GeTools.PolarPoint(GeTools.MidPoint(leftDraw.StartPoint,
                                                                           leftDraw.EndPoint), iclStart - Math.PI / 2, 0.5 * scale);
                }
                //5.2.2 右侧张拉时绘制P锚标识
                else
                {
                    //创建P锚起终点
                    Point3d tdDrawL1 = GeTools.PolarPoint(tdStart, iclStart + Math.PI / 2, 0.75 * scale);
                    Point3d tdDrawL2 = GeTools.PolarPoint(tdStart, iclStart + Math.PI / 2, -0.75 * scale);
                    //创建P锚标志
                    leftDraw = new Polyline();
                    leftDraw.AddVertexAt(0, tdDrawL1.ToPoint2d(), 0, 0.35 * scale, 0.35 * scale);
                    leftDraw.AddVertexAt(1, tdDrawL2.ToPoint2d(), 0, 0.35 * scale, 0.35 * scale);
                    leftDraw.Layer = tdLine.Layer;//张拉段与钢束线应该在同一层
                    //标注左侧P锚
                    lengthL = new MText();
                    //长度
                    lengthL.Contents = "P锚";
                    //文字高度
                    lengthL.TextHeight = 3 * scale;
                    //样式为当前样式
                    lengthL.TextStyleId = db.Textstyle;
                    //旋转角度同直线段倾角
                    lengthL.Rotation = iclStart;
                    //对齐位置为右中
                    lengthL.Attachment = AttachmentPoint.MiddleRight;
                    //位置为P锚标志右侧0.5个单位
                    lengthL.Location = GeTools.PolarPoint(GeTools.MidPoint(leftDraw.StartPoint,
                                                                           leftDraw.EndPoint), iclStart, -2 * scale);
                }
                //5.3 右侧张拉端绘制
                //5.3.1 两侧张拉或右侧张拉时右端绘制工作长度线
                if (tdDrawStyle == 0 || tdDrawStyle == 1)
                {
                    //创建张拉端几何点
                    Point3d tdDrawR = GeTools.PolarPoint(tdEnd, iclEnd, 800);
                    //创建张拉段
                    rightDraw = new Polyline();
                    rightDraw.AddVertexAt(0, tdEnd.ToPoint2d(), 0, 0, 0);
                    rightDraw.AddVertexAt(1, tdDrawR.ToPoint2d(), 0, 0, 0);
                    rightDraw.Layer = tdLine.Layer;//张拉段与钢束线应该在同一层
                    //标注右侧张拉段
                    lengthR = new MText();
                    //长度
                    lengthR.Contents = "工作长度800";
                    //文字高度
                    lengthR.TextHeight = 3 * scale;
                    //样式为当前样式
                    lengthR.TextStyleId = db.Textstyle;
                    //旋转角度同直线段倾角
                    lengthR.Rotation = iclEnd;
                    //对齐位置为左上
                    lengthR.Attachment = AttachmentPoint.TopLeft;
                    //位置为中点垂线以下0.5个单位
                    lengthR.Location = GeTools.PolarPoint(GeTools.MidPoint(rightDraw.StartPoint,
                                                                           rightDraw.EndPoint), iclEnd - Math.PI / 2, 0.5 * scale);
                }
                //5.2.2 左侧张拉时绘制P锚标识
                else//绘制P锚
                {
                    //创建P锚起终点
                    Point3d tdDrawR1 = GeTools.PolarPoint(tdEnd, iclEnd + Math.PI / 2, 0.75 * scale);
                    Point3d tdDrawR2 = GeTools.PolarPoint(tdEnd, iclEnd + Math.PI / 2, -0.75 * scale);
                    //创建P锚标志
                    rightDraw = new Polyline();
                    rightDraw.AddVertexAt(0, tdDrawR1.ToPoint2d(), 0, 0.35 * scale, 0.35 * scale);
                    rightDraw.AddVertexAt(1, tdDrawR2.ToPoint2d(), 0, 0.35 * scale, 0.35 * scale);
                    rightDraw.Layer = tdLine.Layer;//张拉段与钢束线应该在同一层
                    //标注左侧P锚
                    lengthR = new MText();
                    //长度
                    lengthR.Contents = "P锚";
                    //文字高度
                    lengthR.TextHeight = 3 * scale;
                    //样式为当前样式
                    lengthR.TextStyleId = db.Textstyle;
                    //旋转角度同直线段倾角
                    lengthR.Rotation = iclEnd;
                    //对齐位置为左中
                    lengthR.Attachment = AttachmentPoint.MiddleLeft;
                    //位置为P锚标志右侧0.5个单位
                    lengthR.Location = GeTools.PolarPoint(GeTools.MidPoint(rightDraw.StartPoint,
                                                                           rightDraw.EndPoint), iclEnd, 2 * scale);
                }
                #endregion
                #region 6 在截面顶缘标识“梁顶缘线”
                Point3d midPt     = GeTools.MidPoint(tpLine.StartPoint, tpLine.EndPoint);  //顶缘线起终点中点
                Point3d midPtInTp = tpLine.GetClosestPointTo(midPt, Vector3d.YAxis, true); //顶缘线上靠近中点的点
                MText   tpAnno    = new MText();
                tpAnno.Contents = "梁顶缘线";
                //文字高度
                tpAnno.TextHeight = 3 * scale;
                //样式为当前样式
                tpAnno.TextStyleId = db.Textstyle;
                //对齐位置为右上
                tpAnno.Attachment = AttachmentPoint.BottomLeft;
                //位置为中点以上0.5个单位
                tpAnno.Location = GeTools.PolarPoint(midPtInTp, Math.PI / 2, 0.5 * scale);
                #endregion
                db.AddToModelSpace(dims.ToArray());                        //添加各类标注
                db.AddToModelSpace(leftDraw, rightDraw, lengthL, lengthR); //添加张拉段线
                db.AddToModelSpace(tpAnno);                                //添加梁顶缘线标识
                trans.Commit();
            }
        }
Exemplo n.º 12
0
 // Sampler函数用于检测用户的输入.
 protected override SamplerStatus Sampler(JigPrompts prompts)
 {
     if (mPromptCounter == 0)
     {
         // 定义一个点拖动交互类.
         JigPromptPointOptions optJigPoint = new JigPromptPointOptions("\n请指定椭圆弧轴上一点");
         // 设置拖拽的光标类型.
         optJigPoint.Cursor = CursorType.RubberBand;
         // 设置拖动光标基点.
         optJigPoint.BasePoint    = mCenterPt;
         optJigPoint.UseBasePoint = true;
         // 用AcquirePoint函数得到用户输入的点.
         PromptPointResult resJigPoint = prompts.AcquirePoint(optJigPoint);
         Point3d           curPt       = resJigPoint.Value;
         if (curPt != mMajorPt)
         {
             //
             mMajorPt = curPt;
         }
         else
         {
             return(SamplerStatus.NoChange);
         }
         if (resJigPoint.Status == PromptStatus.Cancel)
         {
             return(SamplerStatus.Cancel);
         }
         else
         {
             return(SamplerStatus.OK);
         }
     }
     else if (mPromptCounter == 1)
     {
         // 定义一个距离拖动交互类.
         JigPromptDistanceOptions optJigDis = new JigPromptDistanceOptions("\n请指定另一条半轴的长度");
         // 设置对拖拽的约束:禁止输入零和负值.
         optJigDis.UserInputControls = UserInputControls.NoZeroResponseAccepted | UserInputControls.NoNegativeResponseAccepted;
         // 设置拖拽的光标类型.
         optJigDis.Cursor = CursorType.RubberBand;
         // 设置拖动光标基点.
         optJigDis.BasePoint    = mCenterPt;
         optJigDis.UseBasePoint = true;
         // 用AcquireDistance函数得到用户输入的距离值.
         PromptDoubleResult resJigDis        = prompts.AcquireDistance(optJigDis);
         double             mRadiusRatioTemp = resJigDis.Value;
         if (mRadiusRatioTemp != mRadiusRatio)
         {
             // 保存当前距离值.
             mRadiusRatio = mRadiusRatioTemp;
         }
         else
         {
             return(SamplerStatus.NoChange);
         }
         if (resJigDis.Status == PromptStatus.Cancel)
         {
             return(SamplerStatus.Cancel);
         }
         else
         {
             return(SamplerStatus.OK);
         }
     }
     else if (mPromptCounter == 2)
     {
         // 设置椭圆弧0度基准角.
         double   baseAng;
         Vector2d mMajorAxis2d = new Vector2d(mMajorAxis.X, mMajorAxis.Y);
         if (radiusRatio < 1)
         {
             baseAng = mMajorAxis2d.Angle;
         }
         else
         {
             baseAng = mMajorAxis2d.Angle + 0.5 * Math.PI;
         }
         // 设置系统变量“ANGBASE”.
         Application.SetSystemVariable("ANGBASE", baseAng);
         // 定义一个角度拖动交互类.
         JigPromptAngleOptions optJigAngle1 = new JigPromptAngleOptions("\n请指定椭圆弧的起始角度");
         // 设置拖拽的光标类型.
         optJigAngle1.Cursor = CursorType.RubberBand;
         // 设置拖动光标基点.
         optJigAngle1.BasePoint    = mCenterPt;
         optJigAngle1.UseBasePoint = true;
         // 用AcquireAngle函数得到用户输入的角度值.
         PromptDoubleResult resJigAngle1 = prompts.AcquireAngle(optJigAngle1);
         ang1 = resJigAngle1.Value;
         if (startAng != ang1)
         {
             // 保存当前角度值.
             startAng = ang1;
         }
         else
         {
             return(SamplerStatus.NoChange);
         }
         if (resJigAngle1.Status == PromptStatus.Cancel)
         {
             return(SamplerStatus.Cancel);
         }
         else
         {
             return(SamplerStatus.OK);
         }
     }
     else if (mPromptCounter == 3)
     {
         // 定义一个角度拖动交互类.
         JigPromptAngleOptions optJigAngle2 = new JigPromptAngleOptions("\n请指定椭圆弧的终止角度");
         // 设置拖拽的光标类型.
         optJigAngle2.Cursor = CursorType.RubberBand;
         // 设置拖动光标基点.
         optJigAngle2.BasePoint    = mCenterPt;
         optJigAngle2.UseBasePoint = true;
         // 用AcquireAngle函数得到用户输入的角度值.
         PromptDoubleResult resJigAngle2 = prompts.AcquireAngle(optJigAngle2);
         ang2 = resJigAngle2.Value;
         if (endAng != ang2)
         {
             // 保存当前角度值.
             endAng = ang2;
         }
         else
         {
             return(SamplerStatus.NoChange);
         }
         if (resJigAngle2.Status == PromptStatus.Cancel)
         {
             return(SamplerStatus.Cancel);
         }
         else
         {
             return(SamplerStatus.OK);
         }
     }
     else
     {
         return(SamplerStatus.NoChange);
     }
 }
Exemplo n.º 13
0
        public void StretchPolylineEdge()
        {
            Document doc = GetDocument();
            Database db  = doc.Database;
            Editor   ed  = doc.Editor;

            double requiredArea = 0.0;

            try
            {
                using (Transaction trans = db.TransactionManager.StartTransaction())
                {
                    PromptDoubleOptions pdo = new PromptDoubleOptions(
                        "\nSpecify the required area: ")
                    {
                        AllowNegative   = false,
                        AllowNone       = false,
                        AllowZero       = false,
                        DefaultValue    = defaultArea,
                        UseDefaultValue = defaultArea == 0 ? false : true
                    };
                    PromptDoubleResult pdr = ed.GetDouble(pdo);
                    if (pdr.Status != PromptStatus.OK)
                    {
                        return;
                    }

                    requiredArea = defaultArea = pdr.Value;

                    PromptEntityOptions peo = new PromptEntityOptions("\nSelect a polyline: ")
                    {
                        AllowNone = false
                    };
                    peo.SetRejectMessage("\n>>>this is not a polyline, Select a polyline: ");
                    peo.AddAllowedClass(typeof(Polyline), true);

                    //ed.TurnForcedPickOn();
                    //ed.PointMonitor += Ed_PointMonitor;

                    PromptEntityResult per = ed.GetEntity(peo);
                    if (per.Status != PromptStatus.OK)
                    {
                        return;
                    }
                    var pline = trans.GetObject(per.ObjectId, OpenMode.ForRead) as Polyline;
                    if (!pline.Closed)
                    {
                        ed.WriteMessage("\nThe selected polyline is not closed");
                        return;
                    }
                    var area   = pline.GetArea();
                    var pickPt = pline.GetClosestPointTo(per.PickedPoint, true);

                    int par  = (int)pline.GetParameterAtPoint(pickPt);
                    int pre1 = par > 0 ? par - 1 : (int)pline.EndParam - 1;
                    int pos1 = par + 1 == (int)pline.EndParam ? 0 : par + 1;
                    int pos2 = pos1 == (int)pline.EndParam ? 1 : pos1 + 1;
                    // get the the surrounding points
                    var    p1 = pline.GetPointAtParameter(pre1).GetPoint2d();
                    var    p2 = pline.GetPointAtParameter(par).GetPoint2d();
                    var    p3 = pline.GetPointAtParameter(pos1).GetPoint2d();
                    var    p4 = pline.GetPointAtParameter(pos2).GetPoint2d();
                    double l1 = p2.GetDistanceTo(p3);

                    double dA    = requiredArea - Math.Abs(area);
                    double ang1  = p1.GetVectorTo(p2).Angle;
                    double ang2  = p4.GetVectorTo(p3).Angle;
                    double ang   = p2.GetVectorTo(p3).Angle;
                    double dAng1 = (area > 0) ? ang - ang1 : ang1 - ang;
                    double dAng2 = (area > 0) ? ang - ang2 : ang2 - ang;
                    double f     = 0.5 * (1.0 / Math.Tan(dAng2) - 1.0 / Math.Tan(dAng1));
                    double h;
                    if (Math.Abs(ang1 - ang2) < 0.00001)
                    {
                        h = dA / l1;
                    }
                    else
                    {
                        h = (-l1 + Math.Sqrt(l1 * l1 + 4 * dA * f)) / (2.0 * f);
                    }
                    var pt2 = p2.Polar(ang1, h / Math.Sin(dAng1));
                    var pt3 = p3.Polar(ang2, h / Math.Sin(dAng2));

                    pline.UpgradeOpen();
                    pline.SetPointAt(par, pt2);
                    pline.SetPointAt(pos1, pt3);
                    trans.Commit();
                }
            }
            catch (Autodesk.AutoCAD.Runtime.Exception ex)
            {
                ed.WriteMessage(ex.Message);
            }
        }
        public void StretchPolylineEdge_V2()
        {
            Document doc = GetDocument();
            Database db  = doc.Database;
            Editor   ed  = doc.Editor;

            ObjectId           currentId       = ObjectId.Null;
            int                currentParam    = -1;
            Polyline           currentPolyline = null;
            DBObjectCollection transientColl   = null;
            double             requiredArea    = 0.0;
            bool               isNotEnoughArea = false;
            Point3d?           currPoint       = null;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                try
                {
                    PromptDoubleOptions pdo = new PromptDoubleOptions(
                        "\nSpecify the required area: ")
                    {
                        AllowNegative   = false,
                        AllowNone       = false,
                        AllowZero       = false,
                        DefaultValue    = defaultArea,
                        UseDefaultValue = defaultArea == 0 ? false : true
                    };
                    PromptDoubleResult pdr = ed.GetDouble(pdo);
                    if (pdr.Status != PromptStatus.OK)
                    {
                        return;
                    }
                    requiredArea = defaultArea = pdr.Value;

                    ed.TurnForcedPickOn();
                    ed.PointMonitor += Ed_PointMonitor;
                    Polyline pline = SelectPolyline(ed, trans,
                                                    "\nSelect a closed polyline: ", "\n>>>Select a closed polyline: ", true,
                                                    out Point3d pickPt);
                    if (pline == null)
                    {
                        return;
                    }

                    var pts = GetStretchPoints(pline, pickPt, out int par);
                    if (pts == null)
                    {
                        ed.WriteMessage("\n not enough area...");
                        return;
                    }
                    pline.UpgradeOpen();
                    pline.SetPointAt(par, pts[1]);
                    pline.SetPointAt(pline.ParameterAfter(par), pts[2]);
                    trans.Commit();
                }
                catch (Autodesk.AutoCAD.Runtime.Exception ex)
                {
                    ed.WriteMessage(ex.Message + ex.StackTrace);
                }
                finally
                {
                    ed.PointMonitor -= Ed_PointMonitor;
                    if (currentPolyline != null)
                    {
                        EraseTransient();
                        currentPolyline = null;
                    }
                }
            }



            Polyline CreateTransient(Transaction tr, ObjectId id, PointMonitorEventArgs e
                                     , out int par)
            {
                var rawPoint = e.Context.RawPoint;
                var pline    = tr.GetObject(id, OpenMode.ForRead) as Polyline;
                var pickPt   = pline.GetClosestPointTo(rawPoint, true);
                var res      = GetStretchPoints(pline, pickPt, out par);

                transientColl = new DBObjectCollection();
                if (res != null)
                {
                    isNotEnoughArea = false;
                    Polyline drawable = new Polyline();
                    drawable.AddVertexAt(0, res[0], 0, 0, 0);
                    drawable.AddVertexAt(1, res[1], 0, 0, 0);
                    drawable.AddVertexAt(2, res[2], 0, 0, 0);
                    drawable.AddVertexAt(3, res[3], 0, 0, 0);

                    drawable.ColorIndex = 3;

                    transientColl.Add(drawable);
                }
                else
                {
                    isNotEnoughArea = true;
                    Point2d pixels    = e.Context.DrawContext.Viewport.GetNumPixelsInUnitSquare(rawPoint);
                    int     glyphSize = CustomObjectSnapMode.GlyphSize;
                    glyphHeight = glyphSize / pixels.Y * 1.0;

                    radius = glyphHeight / 2.0;
                    center = e.Context.RawPoint + new Vector3d(3 * radius, 3 * radius, 0);

                    Point2d  p1  = (center + new Vector3d(-radius, -radius, 0)).GetPoint2d();
                    Point2d  p2  = (center + new Vector3d(+radius, +radius, 0)).GetPoint2d();
                    Point2d  p3  = (center + new Vector3d(-radius, +radius, 0)).GetPoint2d();
                    Point2d  p4  = (center + new Vector3d(+radius, -radius, 0)).GetPoint2d();
                    Polyline pl1 = new Polyline
                    {
                        ColorIndex = 1
                    };
                    pl1.AddVertexAt(0, p1, 0, 0, 0);
                    pl1.AddVertexAt(1, p2, 0, 0, 0);


                    Polyline pl2 = new Polyline()
                    {
                        ColorIndex = 1
                    };
                    pl2.AddVertexAt(0, p3, 0, 0, 0);
                    pl2.AddVertexAt(1, p4, 0, 0, 0);

                    transientColl.Add(pl1);
                    transientColl.Add(pl2);
                }

                for (int i = 0; i < transientColl.Count; i++)
                {
                    GI.TransientManager.CurrentTransientManager.AddTransient(
                        transientColl[i], GI.TransientDrawingMode.Contrast,
                        128, new IntegerCollection());
                }
                return(pline);
            }

            void UpdateTransients(Point3d lastPt, Point3d currPt)
            {
                if (transientColl == null)
                {
                    return;
                }
                if (isNotEnoughArea)
                {
                    Matrix3d mat = Matrix3d.Displacement(lastPt.GetVectorTo(currPt));
                    foreach (Entity e in transientColl)
                    {
                        e.TransformBy(mat);
                        GI.TransientManager.CurrentTransientManager.UpdateTransient(e,
                                                                                    new IntegerCollection());
                    }
                }
            }

            void EraseTransient()
            {
                if (transientColl == null)
                {
                    return;
                }
                GI.TransientManager.CurrentTransientManager.EraseTransients(
                    GI.TransientDrawingMode.Contrast,
                    128, new IntegerCollection());
                foreach (GI.Drawable drawable in transientColl)
                {
                    drawable.Dispose();
                }
                transientColl.Clear();
                transientColl = null;
            }

            void Ed_PointMonitor(object sender, PointMonitorEventArgs e)
            {
                try
                {
                    var fsPaths = e.Context.GetPickedEntities();
                    // nothing under the mouse cursor.
                    if (fsPaths == null || fsPaths.Length == 0)
                    {
                        if (currentPolyline != null)
                        {
                            EraseTransient();
                            currentPolyline = null;
                        }
                        return;
                    }

                    var rawPoint = e.Context.RawPoint;
                    var oIds     = fsPaths[0].GetObjectIds();
                    var id       = oIds[oIds.GetUpperBound(0)];

                    if (currPoint.HasValue)
                    {
                        UpdateTransients(currPoint.Value, rawPoint);
                    }
                    currPoint = rawPoint;

                    using (Transaction tr = db.TransactionManager.StartTransaction())
                    {
                        var pline    = tr.GetObject(id, OpenMode.ForRead) as Polyline;
                        var pickedPt = pline.GetClosestPointTo(rawPoint, true);
                        var par      = (int)pline.GetParameterAtPoint(pickedPt);
                        if (currentPolyline != pline || currentParam != par)
                        {
                            EraseTransient();
                            currentPolyline = CreateTransient(tr, id, e, out currentParam);
                        }
                        //else if (currentPolyline == pline && currentParam == par)
                        //{

                        //}
                    }
                }
                catch (Autodesk.AutoCAD.Runtime.Exception ex)
                {
                    ed.WriteMessage(ex.Message);
                }
            }

            Point2d[] GetStretchPoints(
                Polyline pline, Point3d pickPt, out int par)
            {
                var area = pline.GetArea();

                par = (int)pline.GetParameterAtPoint(pickPt);
                int pre1 = par > 0 ? par - 1 : (int)pline.EndParam - 1;
                int pos1 = par + 1 == (int)pline.EndParam ? 0 : par + 1;
                int pos2 = pos1 == (int)pline.EndParam ? 1 : pos1 + 1;
                // get the the surrounding points
                var    p1 = pline.GetPointAtParameter(pre1).GetPoint2d();
                var    p2 = pline.GetPointAtParameter(par).GetPoint2d();
                var    p3 = pline.GetPointAtParameter(pos1).GetPoint2d();
                var    p4 = pline.GetPointAtParameter(pos2).GetPoint2d();
                double l1 = p2.GetDistanceTo(p3);

                double dA    = requiredArea - Math.Abs(area);
                double ang1  = p1.GetVectorTo(p2).Angle;
                double ang2  = p4.GetVectorTo(p3).Angle;
                double ang   = p2.GetVectorTo(p3).Angle;
                double dAng1 = (area > 0) ? ang - ang1 : ang1 - ang;
                double dAng2 = (area > 0) ? ang - ang2 : ang2 - ang;
                double f     = 0.5 * (1.0 / Math.Tan(dAng2) - 1.0 / Math.Tan(dAng1));
                double v     = l1 * l1 + 4 * dA * f;

                if (v < 0)
                {
                    return(null);
                }
                double h;

                if (Math.Abs(ang1 - ang2) < 0.00001)
                {
                    h = dA / l1;
                }
                else
                {
                    h = (-l1 + Math.Sqrt(v)) / (2.0 * f);
                }
                var pt2 = p2.Polar(ang1, h / Math.Sin(dAng1));
                var pt3 = p3.Polar(ang2, h / Math.Sin(dAng2));

                return(new Point2d[] { p2, pt2, pt3, p3 });
            }
        }
Exemplo n.º 15
0
        public override void Add()
        {
            Document doc = AcAp.DocumentManager.MdiActiveDocument;
            Database db  = doc.Database;
            Editor   ed  = doc.Editor;

            var intensity1 = ed.GetString(new PromptStringOptions("Nhap gia tri luc cua diem dau tien"));

            if (intensity1.Status != PromptStatus.OK)
            {
                ed.WriteMessage("\nDa huy lenh them luc.");
                return;
            }

            var intensity2 = ed.GetString(new PromptStringOptions("Nhap gia tri luc cua diem sau"));

            if (intensity2.Status != PromptStatus.OK)
            {
                ed.WriteMessage("\nDa huy lenh them luc.");
                return;
            }

            PromptEntityResult objectId = ed.GetEntity("\nChon vat ma luc phan bo tac dong vao");

            if (objectId.Status != PromptStatus.OK)
            {
                ed.WriteMessage("\nDa huy lenh them luc phan bo.");
                return;
            }

            PromptPointResult point1 = ed.GetPoint(new PromptPointOptions("\nChon cac diem dat luc dau tien"));

            if (point1.Status != PromptStatus.OK)
            {
                ed.WriteMessage("\nDa huy lenh them luc phan bo.");
                return;
            }

            PromptPointResult point2 = ed.GetPoint(new PromptPointOptions("\nChon cac diem dat luc thu hai"));

            if (point2.Status != PromptStatus.OK)
            {
                ed.WriteMessage("\nDa huy lenh them luc phan bo.");
                return;
            }

            PromptAngleOptions pdo = new PromptAngleOptions("\nNhap goc nghieng:");

            pdo.AllowArbitraryInput = true;
            pdo.AllowNone           = true;
            pdo.AllowZero           = true;
            pdo.DefaultValue        = 0;
            pdo.UseDefaultValue     = true;
            PromptDoubleResult angle = ed.GetAngle(pdo);

            if (angle.Status != PromptStatus.OK)
            {
                ed.WriteMessage("\nDa huy lenh them luc phan bo. Vi khong lay duoc goc.");
                return;
            }

            string partDwg = @"Drawings\DistributedLoad.dwg";

            ////////////////////////
            Point3d point  = new Point3d((point1.Value.X + point2.Value.X) / 2, (point1.Value.Y + point2.Value.Y) / 2, 0);
            double  length = Math.Sqrt(Math.Pow(point1.Value.X - point2.Value.X, 2) + Math.Pow(point1.Value.Y - point2.Value.Y, 1));

            if (Math.Round(length, Common.numberOfMathRound) == 0)
            {
                ed.WriteMessage("\nDa huy lenh them luc phân bo. Vì kich thuoc khong the trung nhau.");
                return;
            }
            Scale3d scale = new Scale3d(Common.scale, length / Common.lengthOfDistributedLoad, 1);

            if (Common.InsertDrawing(partDwg, scale, point, angle.Value, out ObjectId idDistributedLoad) == false)
            {
                ed.WriteMessage("\nDa huy lenh them luc phân bo. Vi khong the ve duoc ban ve.");
                return;
            }

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                Common.AddRegAppTableRecord("Data_MechanicalCalculation");
                TypedValue   typedValue = new TypedValue(1000, intensity1 + "," + intensity2 + "," + objectId.ToString() + "," + point1.Value.X + "," + point1.Value.Y + "," + point2.Value.X + "," + point2.Value.Y);
                ResultBuffer rb         = new ResultBuffer(new TypedValue(1001, "Data_MechanicalCalculation"), typedValue);
                tr.GetObject(idDistributedLoad, OpenMode.ForWrite).XData = rb;
                rb.Dispose();
                tr.Commit();
            }
        }
Exemplo n.º 16
0
        public void fHideLevel()
        {
            Editor ed = acApp.DocumentManager.MdiActiveDocument.Editor;

            try
            {
                // Get the current document and database, and start a transaction
                Document acDoc   = Application.DocumentManager.MdiActiveDocument;
                Database acCurDb = acDoc.Database;

                while (true)
                {
                    PromptDoubleOptions levelO = new PromptDoubleOptions("\nEnter level number:");
                    levelO.DefaultValue = 0;
                    PromptDoubleResult level = ed.GetDouble(levelO);
                    if (level.Status != PromptStatus.OK || level.Status == PromptStatus.Cancel)
                    {
                        goto End;
                    }
                    if (level.Status == PromptStatus.OK)
                    {
                        using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
                        {
                            // This example returns the layer table for the current database
                            LayerTable acLyrTbl;
                            acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId,
                                                         OpenMode.ForRead) as LayerTable;

                            // Step through the Layer table and print each layer name
                            foreach (ObjectId acObjId in acLyrTbl)
                            {
                                LayerTableRecord acLyrTblRec;
                                acLyrTblRec = acTrans.GetObject(acObjId, OpenMode.ForWrite) as LayerTableRecord;

                                if (acLyrTblRec.Name.Contains("!FDS_") && acLyrTblRec.Name.Contains("("))
                                {
                                    Regex regEx = new Regex(@"\((.+)\)", RegexOptions.IgnoreCase);
                                    Match match = regEx.Match(acLyrTblRec.Name);
                                    if (match.Success)
                                    {
                                        double levelLayer;
                                        System.Text.RegularExpressions.Group group = match.Groups[1];
                                        Double.TryParse(group.ToString(), out levelLayer);

                                        if (level.Value == levelLayer)
                                        {
                                            acLyrTblRec.IsOff = true;
                                        }
                                    }
                                }
                            }
                            acTrans.Commit();
                        }
                    }
                }
                End :;
                return;
            }
            catch (System.Exception e)
            {
                ed.WriteMessage("\nProgram exception: " + e.ToString());
                return;
            }
        }
Exemplo n.º 17
0
        RTD(string nameApp)
        {
            resultsRTd resRTd = new resultsRTd {
                opt1 = "D", opt2 = "R", valD = 0.0, valE = 0.0, valZ = 0.0, valS = 0.0
            };

            bool escape = false;

            List <ObjectId> idPnts        = new List <ObjectId>();
            ObjectId        idCogoPntBASE = CgPnt.selectCogoPointByNode("\nSelect Base Point: ", osMode: 8);

            if (idCogoPntBASE == ObjectId.Null)
            {
                Application.ShowAlertDialog("CogoPoint not found.  Exiting......");
                return;
            }

            BaseObjs.updateGraphics();
            Point3d pnt3dBASE = idCogoPntBASE.getCogoPntCoordinates();

            idPnts.Add(idCogoPntBASE);

            string pntDesc = idCogoPntBASE.getCogoPntDesc();

            if (pntDesc == "")
            {
                pntDesc = "CPNT-ON";
            }

            string prompt = "\nPick Point for Direction: ";

            PromptStatus ps;
            Point3d      pnt3dTAR = UserInput.getPoint(prompt, pnt3dBASE, out escape, out ps, osMode: 641);

            if (escape || pnt3dTAR == Pub.pnt3dO)
            {
                return;
            }

            double angle = 0;

            resRTd.opt1 = Dict.getCmdDefault("cmdRTd", "cmdDefault");

            if (resRTd.opt1 == string.Empty)
            {
                resRTd.opt1 = "D";
            }

            angle = Measure.getAzRadians(pnt3dBASE, pnt3dTAR);

            try
            {
                prompt = string.Format("\nDistance / target Elevation / Z value difference <{0}>: [D/E/Z]: ", resRTd.opt1);
                escape = UserInput.getUserInputKeyword(resRTd.opt1, out resRTd.opt1, prompt, "D E Z");
                if (escape)
                {
                    return;
                }
                if (resRTd.opt1 != "D" && resRTd.opt1 != "E" && resRTd.opt1 != "Z")
                {
                    return;
                }
            }
            catch (System.Exception ex)
            {
                BaseObjs.writeDebug(ex.Message + " cmdRTD.cs: line: 88");
            }

            if (resRTd.opt1 == string.Empty)
            {
                return;
            }
            bool tryParse = false;

            switch (resRTd.opt1)
            {
            case "D":
                resRTd.valD = Pub.Dist;
                if (resRTd.valD == 0)
                {
                    tryParse = double.TryParse(Dict.getCmdDefault("cmdRTD", "Distance"), out resRTd.valD);
                }

                if (!tryParse)
                {
                    resRTd.valD = 0.0;
                }
                ;

                try
                {
                    escape = UserInput.getUserInput("\nEnter Distance [pos(+) value = target direction, neg(-) value = target direction + 180 degrees:", out resRTd.valD, resRTd.valD);
                    if (escape)
                    {
                        return;
                    }
                }
                catch (System.Exception ex)
                {
                    BaseObjs.writeDebug(ex.Message + " cmdRTD.cs: line: 112");
                }

                Pub.Dist = resRTd.valD;

                resRTd.valS = Pub.Slope;
                if (resRTd.valS == 0.0)
                {
                    tryParse = double.TryParse(Dict.getCmdDefault("cmdRTd", "Slope"), out resRTd.valS);
                }

                escape = UserInput.getUserInput("\nRate of Grade: ", out resRTd.valS, resRTd.valS);
                if (escape)
                {
                    return;
                }

                Pub.Slope = resRTd.valS;

                break;

            case "E":
                resRTd.valE = Pub.Elev;
                if (resRTd.valE == 0)
                {
                    resRTd.valE = double.Parse(Dict.getCmdDefault("cmdRTd", "Elevation"));
                }

                PromptDoubleOptions pdo = new PromptDoubleOptions("\nEnter Target Elevation / ESC to select point for Elevation: ");

                pdo.AllowArbitraryInput = true;
                pdo.AllowNone           = true;
                pdo.UseDefaultValue     = true;
                pdo.DefaultValue        = resRTd.valE;

                PromptDoubleResult pdr = BaseObjs._editor.GetDouble(pdo);

                switch (pdr.Status)
                {
                case PromptStatus.Cancel:
                    ObjectId idCgPnt = ObjectId.Null;
                    Point3d  pnt3d   = Pub.pnt3dO;
                    tryParse = double.TryParse(UserInput.getPoint("\nSelect Cogo Point with desired elevation: ",
                                                                  out idCgPnt, out pnt3d, pnt3d, osMode: 8, round: false), out resRTd.valE);
                    if (!tryParse)
                    {
                        break;
                    }
                    break;

                case PromptStatus.Error:
                    break;

                case PromptStatus.Other:
                    break;

                case PromptStatus.OK:
                    resRTd.valE = pdr.Value;
                    break;

                case PromptStatus.None:
                    break;
                }

                Pub.Elev = resRTd.valE;

                prompt = string.Format("\nDistance / Rate of grade <{0}>: [D/R]: ", resRTd.opt2);
                escape = UserInput.getUserInputKeyword(resRTd.opt2, out resRTd.opt2, prompt, "D R");
                if (escape)
                {
                    return;
                }

                switch (resRTd.opt2)
                {
                case "D":
                    resRTd.valD = Pub.Dist;
                    if (resRTd.valD == 0)
                    {
                        tryParse = double.TryParse(Dict.getCmdDefault("cmdRTD", "Distance"), out resRTd.valD);
                    }

                    if (!tryParse)
                    {
                        resRTd.valD = 0.0;
                    }
                    ;

                    try
                    {
                        escape = UserInput.getUserInput("\nEnter Distance [pos(+) value = target direction, neg(-) value = target direction + 180 degrees:", out resRTd.valD, resRTd.valD);
                        if (escape)
                        {
                            return;
                        }
                    }
                    catch (System.Exception ex)
                    {
                        BaseObjs.writeDebug(ex.Message + " cmdRTD.cs: line: 189");
                    }
                    Pub.Dist = resRTd.valD;

                    break;

                case "R":
                    resRTd.valS = Pub.Slope;
                    if (resRTd.valS == 0.0)
                    {
                        tryParse = double.TryParse(Dict.getCmdDefault("cmdRTd", "Slope"), out resRTd.valS);
                    }

                    escape = UserInput.getUserInput("\nRate of Grade: ", out resRTd.valS, resRTd.valS);
                    if (escape)
                    {
                        return;
                    }

                    Pub.Slope = resRTd.valS;
                    break;
                }

                break;

            case "Z":
                resRTd.valZ = Pub.dZ;

                escape = UserInput.getUserInput("\nZ Value Difference", out resRTd.valZ, resRTd.valZ);

                if (escape)
                {
                    return;
                }

                prompt = string.Format("\nDistance / Rate of grade <{0}>: [D/R]: ", resRTd.opt2);
                escape = UserInput.getUserInputKeyword(resRTd.opt2, out resRTd.opt2, prompt, "D R");
                if (escape)
                {
                    return;
                }

                switch (resRTd.opt2)
                {
                case "D":
                    resRTd.valD = Pub.Dist;
                    if (resRTd.valD == 00)
                    {
                        tryParse = double.TryParse(Dict.getCmdDefault("cmdRTD", "Distance"), out resRTd.valD);
                    }
                    if (!tryParse)
                    {
                        resRTd.valD = 0.0;
                    }
                    try
                    {
                        escape = UserInput.getUserInput("\nEnter Distance [pos(+) value = target direction, neg(-) value = target direction + 180 degrees:", out resRTd.valD, resRTd.valD);
                        if (escape)
                        {
                            return;
                        }
                    }
                    catch (System.Exception ex)
                    {
                        BaseObjs.writeDebug(ex.Message + " cmdRTD.cs: line: 236");
                    }
                    Pub.Dist = resRTd.valD;

                    break;

                case "R":
                    resRTd.valS = Pub.Slope;
                    if (resRTd.valS == 0.0)
                    {
                        tryParse = double.TryParse(Dict.getCmdDefault("cmdRTd", "Slope"), out resRTd.valS);
                    }

                    escape = UserInput.getUserInput("\nRate of Grade: ", out resRTd.valS, resRTd.valS);
                    if (escape)
                    {
                        return;
                    }
                    Pub.Slope = resRTd.valS;
                    break;
                }
                break;
            }


            switch (resRTd.opt1)
            {
            case "D":
                pnt3dTAR = new Point3d(pnt3dBASE.X + System.Math.Cos(angle) * resRTd.valD,
                                       pnt3dBASE.Y + System.Math.Sin(angle) * resRTd.valD,
                                       pnt3dBASE.Z + resRTd.valS * System.Math.Abs(resRTd.valD));
                break;

            case "E":

                switch (resRTd.opt2)
                {
                case "D":
                    pnt3dTAR = pnt3dBASE.traverse(angle, resRTd.valD, 0);
                    pnt3dTAR = new Point3d(pnt3dTAR.X, pnt3dTAR.Y, resRTd.valE);
                    break;

                case "R":
                    double distance = System.Math.Abs((resRTd.valE - pnt3dBASE.Z) / resRTd.valS);
                    pnt3dTAR = new Point3d(pnt3dBASE.X + System.Math.Cos(angle) * distance,
                                           pnt3dBASE.Y + System.Math.Sin(angle) * distance,
                                           resRTd.valE);
                    break;
                }
                break;

            case "Z":
                switch (resRTd.opt2)
                {
                case "D":
                    pnt3dTAR = new Point3d(pnt3dBASE.X + System.Math.Cos(angle) * resRTd.valD,
                                           pnt3dBASE.Y + System.Math.Sin(angle) * resRTd.valD,
                                           pnt3dBASE.Z + resRTd.valZ);
                    break;

                case "R":
                    double distance = System.Math.Abs(resRTd.valZ / resRTd.valS);
                    pnt3dTAR = new Point3d(pnt3dBASE.X + System.Math.Cos(angle) * distance,
                                           pnt3dBASE.Y + System.Math.Sin(angle) * distance,
                                           pnt3dBASE.Z + resRTd.valZ);
                    break;
                }
                break;
            }

            uint     pntNum;
            ObjectId idCogoPntTAR = pnt3dTAR.setPoint(out pntNum, pntDesc);
            ObjectId idPoly3d     = ObjectId.Null;

            idPnts.Add(idCogoPntTAR);

            List <Handle> hPnts = new List <Handle>();

            hPnts.Add(idPnts[0].getHandle());
            hPnts.Add(idPnts[1].getHandle());

            ObjectId idPoly = ObjectId.Null;

            using (BaseObjs._acadDoc.LockDocument())
            {
                idPoly3d = BrkLine.makeBreakline(nameApp, "cmdRTd", out idPoly, idPnts);
            }

            Grading_Palette.gPalette.pGrading.cmdRTd_Default   = resRTd.opt1;
            Grading_Palette.gPalette.pGrading.cmdRTd_Distance  = resRTd.valD.ToString();
            Grading_Palette.gPalette.pGrading.cmdRTd_Elevation = resRTd.valE.ToString();
            Grading_Palette.gPalette.pGrading.cmdRTd_Slope     = resRTd.valS.ToString();

            Dict.setCmdDefault("cmdRTd", "cmdDefault", resRTd.opt1);
            Dict.setCmdDefault("cmdRTd", "Distance", resRTd.valD.ToString());
            Dict.setCmdDefault("cmdRTd", "Elevation", resRTd.valE.ToString());
            Dict.setCmdDefault("cmdRTD", "Slope", resRTd.valS.ToString());

            bool       exists          = false;
            PointGroup pntGroup        = CgPnt_Group.addPntGroup(pntDesc, out exists);
            ObjectId   idPntLabelStyle = Pnt_Style.getPntLabelStyle(CgPnts.setup(pntDesc));

            if (!exists)
            {
                try
                {
                    using (Transaction tr = BaseObjs.startTransactionDb())
                    {
                        pntGroup.UpgradeOpen();
                        pntGroup.PointLabelStyleId = idPntLabelStyle;

                        StandardPointGroupQuery query = new StandardPointGroupQuery();
                        query.IncludeRawDescriptions = pntDesc;
                        pntGroup.SetQuery(query);
                        tr.Commit();
                    }
                }
                catch (System.Exception ex)
                {
                    BaseObjs.writeDebug(ex.Message + " cmdRTD.cs: line: 343");
                }
            }
        }
Exemplo n.º 18
0
 private static void handle_promptAngleResult(object sender, PromptDoubleResultEventArgs e)
 {
     useThisAngleResult = e.Result;
 }
Exemplo n.º 19
0
        public static void DoIt()
        {
            Document            doc       = Application.DocumentManager.MdiActiveDocument;
            Editor              ed        = doc.Editor;
            PromptDoubleOptions optDouble = new PromptDoubleOptions("\n请输入箭头长度:");

            optDouble.AllowNone       = true;
            optDouble.AllowZero       = false;
            optDouble.DefaultValue    = CurrArrowLength;
            optDouble.UseDefaultValue = true;
            PromptDoubleResult resDouble = ed.GetDouble(optDouble);

            if (resDouble.Status == PromptStatus.OK)
            {
                //改变箭头长度设定值
                CurrArrowLength = resDouble.Value;
                PromptPointResult resStartPoint = ed.GetPoint("\n请输入起点:");
                if (resStartPoint.Status == PromptStatus.OK)
                {
                    PromptPointOptions optEndPoint = new PromptPointOptions("\n请输入终点:");
                    optEndPoint.BasePoint    = resStartPoint.Value;
                    optEndPoint.UseBasePoint = true;
                    PromptPointResult resEndPoint = ed.GetPoint(optEndPoint);
                    if (resEndPoint.Status == PromptStatus.OK)
                    {
                        Point3d  startpnt = resStartPoint.Value;
                        Point3d  endpnt   = resEndPoint.Value;
                        Database db       = doc.Database;
                        using (Transaction tr = db.TransactionManager.StartTransaction())
                        {
                            BlockTableRecord btr =
                                (BlockTableRecord)tr.GetObject(
                                    db.CurrentSpaceId,
                                    OpenMode.ForWrite,
                                    false);
                            Line line = new Line(startpnt, endpnt);
                            btr.AppendEntity(line);
                            tr.AddNewlyCreatedDBObject(line, true);
                            RegAppTable rat =
                                (RegAppTable)tr.GetObject(
                                    db.RegAppTableId,
                                    OpenMode.ForRead,
                                    false);
                            if (!rat.Has(RegAppName))
                            {
                                rat.UpgradeOpen();
                                RegAppTableRecord regapp = new RegAppTableRecord();
                                regapp.Name = RegAppName;
                                rat.Add(regapp);
                                tr.AddNewlyCreatedDBObject(regapp, true);
                            }
                            Point3d midpnt = (startpnt + endpnt.GetAsVector()) / 2;
                            LArrow  la     = new LArrow(line);
                            //附着当前设定的箭头长度
                            la.ArrowLength = CurrArrowLength;
                            la.Scale       = 0.5;
                            la.SaveExtendedData();
                            tr.Commit();
                        }
                    }
                }
            }
        }