コード例 #1
0
        public static void ViewContourElevation()
        {
            var pt1 = Interaction.GetPoint("\n截线起点");

            if (pt1.IsNull())
            {
                return;
            }
            var pt2 = Interaction.GetLineEndPoint("\n截线终点", pt1);

            if (pt2.IsNull())
            {
                return;
            }
            var line  = NoDraw.Line(pt1, pt2);
            var ids   = QuickSelection.SelectAll().QWhere(x => x.GetCode() == "730101" || x.GetCode() == "730102").ToList();
            var temps = new List <ObjectId>();

            ids.QForEach <Curve>(cv =>
            {
                if (cv != null)
                {
                    var points = new Point3dCollection();
                    Algorithms.IntersectWith3264(line, cv, Intersect.OnBothOperands, points);
                    var text = cv.ObjectId.GetData(DictName.CmDrawing, KeyName.Elevation);
                    points.Cast <Point3d>().ForEach(p =>
                    {
                        temps.Add(Draw.Text(text, 2.5, p));
                    });
                }
            });
            Interaction.GetString("\n按ESC退出");
            temps.QForEach(x => x.Erase());
        }
コード例 #2
0
        public static void DeleteAll()
        {
            DeleteToolObject();
            App.LockAndExecute(() =>
            {
                ClearHighlighted();
                var layerTable = HostApplicationServices.WorkingDatabase.LayerTableId.QOpenForRead <SymbolTable>();
                HostApplicationServices.WorkingDatabase.Clayer = layerTable["0"];
                DeleteByLayer(layerTable, ProcessLayerName);
                DeleteByLayer(layerTable, HatchLayerName);
                DeleteByLayer(layerTable, GashLayerName);
                DeleteByLayer(layerTable, ExtraObjectsLayerName);
            });

            void DeleteByLayer(SymbolTable layerTable, string layerName)
            {
                if (layerTable.Has(layerName))
                {
                    var ids = QuickSelection.SelectAll(FilterList.Create().Layer(layerName));
                    if (ids.Any())
                    {
                        ids.QForEach(entity => entity.Erase());
                    }
                    layerTable[layerName].Erase();
                }
            }
        }
コード例 #3
0
        public static void ConvertPoint()
        {
            var entityID = "250";

            DbHelper.AffirmRegApp(AppName.CassCode);
            var ids = QuickSelection.SelectAll("INSERT").QWhere(x => x.GetFirstXData(AppName.CassCode) == "202101").ToArray();

            ids.SetStyles(entityID);
        }
コード例 #4
0
        //public static void HideExtraObjects(IEnumerable<Curve> curves)
        //{
        //    curves.ForEach(p => p.Visible = !p.Visible);
        //    DeleteToolObject();
        //    Editor.UpdateScreen();
        //    //Interaction.SetActiveDocFocus();
        //}

        public static void DeleteByLayer(string layerName)
        {
            App.LockAndExecute(() =>
            {
                var ids = QuickSelection.SelectAll(FilterList.Create().Layer(layerName));
                if (ids.Any())
                {
                    ids.QForEach(entity => entity.Erase());
                }
            });
        }
コード例 #5
0
        public static void CreateHidden()
        {
            if (QuickSelection.SelectAll("INSERT").QCount(x => (x as BlockReference).Name == Consts.Hidden) == 0)
            {
                Services.LoadDwg("Res.dwg");
                ObjectId id = Draw.Insert(Consts.Hidden, Point3d.Origin);
            }

            // 创建默认打断样式
            CustomDictionary.SetValue(DictName.GlobalStyles, TjCode.SeperationBreak, "5");
            CustomDictionary.SetValue(DictName.GlobalStyles, TjCode.BusStop, "30|5|5|5");
        }
コード例 #6
0
        public static void ConvertContour()
        {
            var intermediateContourID = "252";
            var indexContourID        = "253";

            DbHelper.AffirmRegApp(AppName.CassCode);
            var ids1 = QuickSelection.SelectAll().QWhere(x => x is Curve && x.GetFirstXData(AppName.CassCode) == "186301").ToArray();
            var ids2 = QuickSelection.SelectAll().QWhere(x => x is Curve && x.GetFirstXData(AppName.CassCode) == "186302").ToArray();

            ids1.SetStyles(intermediateContourID);
            ids2.SetStyles(indexContourID);
        }
コード例 #7
0
        // 点击确定按钮
        private void btnOk_Click(object sender, EventArgs e)
        {
            string[] list = new string[clb.CheckedItems.Count];
            // 将列表复选框的所有选中项 复制到 数组中
            clb.CheckedItems.CopyTo(list, 0);
            FilterList filterList = FilterList.Create().Layer(list);
            var        ids        = QuickSelection.SelectAll(filterList).ToArray();

            // 通过 ids 设置对象为选中状态
            InteractionUtil.SetPickSet(ids);
            // 关闭对话框
            DialogResult = DialogResult.OK;
            Close();
        }
コード例 #8
0
        public static void ToggleSmart()
        {
            smartVisible = !smartVisible;
            var ids = QuickSelection.SelectAll("INSERT").Where(x => TongJiCode.GetCode(x) == TjCode.SeperationBreak || TongJiCode.GetCode(x) == TjCode.BusStop);

            using (Transaction trans = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
            {
                foreach (var id in ids)
                {
                    Entity ent = trans.GetObject(id, OpenMode.ForWrite) as Entity;
                    ent.Visible = smartVisible;
                }
                trans.Commit();
            }
        }
コード例 #9
0
        public static void ConvertCass()
        {
            var choices = EntityManager.Entities.Select(x => string.Format("{0}.{1}.{2}", x.Key, x.Value.EntityCode, x.Value.EntityName)).ToArray();
            var selects = Gui.GetChoices("选择类型", choices);

            if (selects.Length == 0)
            {
                return;
            }
            DbHelper.AffirmRegApp(AppName.CassCode);
            foreach (var select in selects)
            {
                var code     = select.Split('.')[0];
                var entityID = select.Split('.')[1];
                var ids      = QuickSelection.SelectAll().QWhere(x => x.GetFirstXData(AppName.CassCode) == code).ToArray();
                ids.SetStyles(entityID);
            }
        }
コード例 #10
0
        /// <summary>
        /// 清理具有Generated标记的图元
        /// </summary>
        public static void EraseGenerated()
        {
            var readyToErase = QuickSelection.SelectAll("*LINE,ARC").Where(x => CADBase.GetFirstXData(x, AppName.Generated) == "true").ToList();

            readyToErase.ForEach(x => x.Erase());
        }
コード例 #11
0
        public static Map ExportCiml()
        {
            var map    = new Map();
            var layer1 = new VectorLayer("elevation_points", VectorLayer.GEOTYPE_POINT);
            var layer2 = new VectorLayer("contours", VectorLayer.GEOTYPE_LINEAR);
            var layer3 = new VectorLayer("points", VectorLayer.GEOTYPE_POINT);
            var layer4 = new VectorLayer("lines", VectorLayer.GEOTYPE_LINEAR);
            var layer5 = new VectorLayer("regions", VectorLayer.GEOTYPE_REGION);

            var ids = QuickSelection.SelectAll().QWhere(x => x.GetCode() != null).ToList();

            ids.QForEach <Entity>(ent =>
            {
                var code = ent.GetCode();
                var def  = EntityManager.Entities.FirstOrDefault(x => x.Value.EntityCode == code).Value;
                if (def != null)
                {
                    var points = new List <Dreambuild.Geometry.Point2D>();
                    if (ent is BlockReference)
                    {
                        var pos = (ent as BlockReference).Position;
                        points.Add(new Dreambuild.Geometry.Point2D(pos.X, pos.Y));
                    }
                    else if (ent is Polyline)
                    {
                        var pts = (ent as Polyline).GetPoints().ToList();
                        pts.ForEach(pt => points.Add(new Dreambuild.Geometry.Point2D(pt.X, pt.Y)));
                    }
                    else if (ent is Polyline2d)
                    {
                        var poly = new Polyline();
                        poly.ConvertFrom(ent, true);
                        var pts = poly.GetPoints().ToList();
                        pts.ForEach(pt => points.Add(new Dreambuild.Geometry.Point2D(pt.X, pt.Y)));
                    }
                    var feature      = new Feature(points);
                    feature["code"]  = code;
                    feature["name"]  = ent.GetFirstXData(Consts.AppNameForName);
                    feature["layer"] = def.Layer;
                    feature["color"] = def.ColorIndex.ToString();

                    if (def.EntityType == "Block")
                    {
                        feature["block"] = def.BlockName;
                        if (code == "110102" || code == "110202" || code == "110302")
                        {
                            feature["height"] = (ent as BlockReference).GetBlockAttributes()["height"];
                            layer1.Features.Add(feature);
                        }
                        else
                        {
                            layer3.Features.Add(feature);
                        }
                    }
                    else if (def.EntityType == "Line")
                    {
                        feature["linetype"] = def.Linetype;
                        feature["cwidth"]   = def.ConstantWidth.ToString();
                        if (code == "730101" || code == "730102")
                        {
                            feature["height"] = ent.Id.GetData(DictName.CmDrawing, KeyName.Elevation);
                            layer2.Features.Add(feature);
                        }
                        else
                        {
                            layer4.Features.Add(feature);
                        }
                    }
                    else if (def.EntityType == "Region")
                    {
                        feature["linetype"] = def.Linetype;
                        feature["cwidth"]   = def.ConstantWidth.ToString();
                        layer5.Features.Add(feature);
                    }
                }
            });

            map.Layers.AddRange(new List <ILayer> {
                layer1, layer2, layer3, layer4, layer5
            });
            return(map);
        }
コード例 #12
0
 /// <summary>
 /// 清理具有Generated标记的图元
 /// </summary>
 public static void EraseGenerated()
 {
     QuickSelection.SelectAll("*LINE,ARC").QWhere(x => x.HasTag(TagName.Generated)).QForEach(x => x.Erase());
 }
コード例 #13
0
        public void exportleo()
        {
            DocumentCollection docCol = Application.DocumentManager;
            Database           db     = docCol.MdiActiveDocument.Database;
            Editor             editor = docCol.MdiActiveDocument.Editor;
            Document           doc    = docCol.MdiActiveDocument;


            using (Transaction tx = db.TransactionManager.StartTransaction())
            {
                var plines = QuickSelection.SelectAll("LWPOLYLINE").QWhere(x => x.Layer == "RØR INSTRUMENT SIGNAL").ToList();

                editor.WriteMessage($"\nPlines collected {plines.Count}");

                plines.QOpenForWrite <Polyline>(listToExplode =>
                {
                    foreach (var poly in listToExplode)
                    {
                        Modify.Explode(poly.ObjectId);
                    }
                });

                var rumPolyIds = QuickSelection.SelectAll("LWPOLYLINE").QWhere(x => x.Layer == "RUM DELER").ToList();

                editor.WriteMessage($"\nCollected {rumPolyIds.Count} rum polylines.");

                rumPolyIds.QOpenForWrite <Polyline>(listToClean =>
                {
                    foreach (var poly in listToClean)
                    {
                        Algorithms.PolyClean_RemoveDuplicatedVertex(poly);
                    }
                });

                List <(string Tag, string RoomNr)> tagRoomlist = new List <(string Tag, string RoomNr)>();

                int i = 0;

                List <BlockReference> AllBlocks = new List <BlockReference>();

                var rumPolys = rumPolyIds.QOpenForRead <Polyline>();

                foreach (Polyline pline in rumPolys)
                {
                    i++;
                    editor.WriteMessage($"\nProcessing polyline number {i}.");

                    List <BlockReference> blocks = new List <BlockReference>();

                    PromptSelectionResult selection =
                        editor.SelectByPolyline(pline, ExtensionMethods.PolygonSelectionMode.Window, new TypedValue(0, "INSERT"));

                    if (selection.Status == PromptStatus.OK)
                    {
                        SelectionSet set = selection.Value;
                        foreach (SelectedObject selObj in set)
                        {
                            if (selObj != null)
                            {
                                BlockReference block = tx.GetObject(selObj.ObjectId, OpenMode.ForRead) as BlockReference;
                                blocks.Add(block);
                                AllBlocks.Add(block);
                            }
                        }
                    }
                    else
                    {
                        editor.WriteMessage($"\nPolyline number {i} failed the selection!");
                    }

                    BlockReference roomNumberBlock = blocks.Where(x => x.Name == "rumnummer").FirstOrDefault();
                    if (roomNumberBlock == null)
                    {
                        continue;
                    }
                    string roomNumber = roomNumberBlock.GetBlockAttribute("ROOMNO");
                    editor.WriteMessage($"\nRoom nr.: {roomNumber}");

                    foreach (BlockReference br in blocks)
                    {
                        string tagValue = string.Empty;
                        var    attrs    = br.GetBlockAttributes();
                        if (attrs.ContainsKey("TEXT1"))
                        {
                            tagValue = attrs["TEXT1"];
                        }
                        else if (attrs.ContainsKey("TAG"))
                        {
                            tagValue = attrs["TAG"];
                        }
                        else
                        {
                            continue;
                        }

                        if (!string.IsNullOrEmpty(roomNumber))
                        {
                            tagRoomlist.Add((tagValue, roomNumber));
                        }
                    }
                }

                //Sort the pairs list
                tagRoomlist = tagRoomlist.OrderBy(x => x.Tag).ToList();

                //Export to excel
                xel.Application excel = new xel.Application();
                if (null == excel)
                {
                    throw new System.Exception("Failed to start EXCEL!");
                }
                excel.Visible = true;
                xel.Workbook  workbook = excel.Workbooks.Add(Missing.Value);
                xel.Worksheet worksheet;
                worksheet      = excel.ActiveSheet as xel.Worksheet;
                worksheet.Name = "LeoExport";
                worksheet.Columns.ColumnWidth = 15;

                int row = 1;
                int col = 1;

                foreach (var pair in tagRoomlist)
                {
                    worksheet.Rows[row].Cells[col]     = pair.Tag;
                    worksheet.Rows[row].Cells[col + 1] = pair.RoomNr;
                    //worksheet.Cells[row, col] = pair.Item1;
                    //worksheet.Cells[row, col+1] = pair.Item2;
                    row++;
                }
            }
        }
コード例 #14
0
        public void detectdupes()
        {
            DocumentCollection docCol = Application.DocumentManager;
            Database           db     = docCol.MdiActiveDocument.Database;
            Editor             editor = docCol.MdiActiveDocument.Editor;
            Document           doc    = docCol.MdiActiveDocument;

            var ids = QuickSelection.SelectAll("INSERT").QWhere(x => x.Layer == "SYMBOL");

            editor.WriteMessage($"\nSymbol blocks found in drawing: {ids.Count()}.");

            List <(string Tag, ObjectId id)> tagIdPairs = new List <(string Tag, ObjectId id)>();

            var blocks = ids.QOpenForRead <BlockReference>();

            //int count = 1;
            foreach (BlockReference br in blocks)
            {
                var attrs = br.GetBlockAttributes();

                if (attrs.ContainsKey("TEXT1"))
                {
                    string tagText = attrs["TEXT1"];
                    if (string.IsNullOrEmpty(tagText))
                    {
                        continue;
                    }
                    tagIdPairs.Add((tagText, br.ObjectId));
                    //editor.WriteMessage($"\n{count}: {attrs["TEXT1"]}");
                    //count++;
                }
                else if (attrs.ContainsKey("TAG"))
                {
                    string tagText = attrs["TAG"];
                    if (string.IsNullOrEmpty(tagText))
                    {
                        continue;
                    }
                    tagIdPairs.Add((tagText, br.ObjectId));
                    //editor.WriteMessage($"\n{count}: {attrs["TAG"]}");
                    //count++;
                }
                else
                {
                    //editor.WriteMessage($"\n{count}: NON-TAGGED");
                    //count++;
                }
            }

            var groupByTag = tagIdPairs.GroupBy(x => x.Tag);

            var groupsWithDuplicates = groupByTag.Where(x => x.Count() > 1);

            if (groupsWithDuplicates.Count() < 1)
            {
                editor.WriteMessage("\nNo duplicates found!");
            }
            else
            {
                var groupWithDuplicates = groupsWithDuplicates.FirstOrDefault();
                editor.WriteMessage($"\nDuplicate tag: {groupWithDuplicates.Key}.");
                List <ObjectId> duplicateIds = new List <ObjectId>(groupWithDuplicates.Count());
                foreach (var dupe in groupWithDuplicates)
                {
                    duplicateIds.Add(dupe.id);
                    //editor.WriteMessage($"\n{dupe.id.ToString()}");
                }
                Autodesk.AutoCAD.Internal.Utils.SelectObjects(duplicateIds.ToArray());
                Interaction.ZoomObjects(duplicateIds);
            }
        }