Exemplo n.º 1
0
 /// <summary>
 /// Задание параметров точки класса DBPoint.
 /// </summary>
 /// <param name="acadPoint">Редактируемая точка</param>
 public void Update(ref AcadDS.DBPoint acadPoint)
 {
     if (acadPoint != null)
     {
         acadPoint.Position = new Point3d(Position.X, Position.Y, Height);
     }
 }
Exemplo n.º 2
0
        [CommandMethod("convacadpts")] //Comanda pentru convertirea punctelor autocad in puncte COGO de civil3d
        public void ConvAcadPts()
        {
            CivilDocument civDoc = CivilApplication.ActiveDocument;
            Database      db     = HostApplicationServices.WorkingDatabase;
            Editor        ed     = Application.DocumentManager.MdiActiveDocument.Editor;

            //Selectia punctelor autocad
            PromptSelectionOptions PrSelOpt = new PromptSelectionOptions();

            PrSelOpt.MessageForAdding  = "\nSelect points to add: ";
            PrSelOpt.MessageForRemoval = "\nSelect points to remove: ";

            TypedValue[]    tvs = { new TypedValue((int)DxfCode.Start, "POINT") };
            SelectionFilter sf  = new SelectionFilter(tvs);

            PromptSelectionResult PrSelRes = ed.GetSelection(PrSelOpt, sf);

            if (PrSelRes.Status != PromptStatus.OK)
            {
                ed.WriteMessage("\nInvalid Selection! Aborting.");
                return;
            }

            //Solicitarea descrierii punctelor COGO
            string descriere = ed.GetString("\nSpecify points description: ").StringResult;

            //Creearea puntelor COGO
            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                CogoPointCollection cogoPoints = civDoc.CogoPoints;
                foreach (SelectedObject selObj in PrSelRes.Value)
                {
                    Autodesk.AutoCAD.DatabaseServices.DBPoint punctAcad = (Autodesk.AutoCAD.DatabaseServices.DBPoint)trans.GetObject(selObj.ObjectId, OpenMode.ForRead);
                    ObjectId  pointId = cogoPoints.Add(punctAcad.Position);
                    CogoPoint cogo    = pointId.GetObject(OpenMode.ForWrite) as CogoPoint;
                    cogo.RawDescription = descriere;
                }
                trans.Commit();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Загружает в документ новые параметры слоев и фигур.
        /// </summary>
        public void Update()
        {
            // Получаем текущий документ, доступ к командной строке и БД.
            Document doc = AcadAS.Application.DocumentManager.MdiActiveDocument;
            Editor   ed  = doc.Editor;
            Database db  = doc.Database;

            // Блокируем документ для редактирования из вне.
            using (DocumentLock lc = doc.LockDocument())
            {
                // Начинаем транзакцию.
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    try
                    {
                        // Создаем список имен слоев.
                        string[] layerNames = new string[Layers.Count];
                        int      i          = 0;
                        foreach (Layer layer in Layers)
                        {
                            layerNames[i] = layer.Name;
                            i++;
                        }

                        i = 0;
                        // Получаем таблицу слоев.
                        LayerTable lt = (LayerTable)tr.GetObject(db.LayerTableId, OpenMode.ForWrite);
                        // Задаем временные имена слоев для избежания конфликтов переименовывания.
                        foreach (ObjectId ltrId in lt)
                        {
                            LayerTableRecord ltr = (LayerTableRecord)tr.GetObject(ltrId, OpenMode.ForWrite);
                            if (ltr.Name != "0")
                            {
                                ltr.Name = "_temp_" + ltr.Name + "_temp_";
                            }
                        }

                        foreach (Layer layer in Layers)
                        {
                            // Проверяем новое имя слоя на дублирование и присваиваем слоям документа новые параметры.
                            if (Array.IndexOf(layerNames, layer.Name) == Array.LastIndexOf(layerNames, layer.Name))
                            {
                                LayerTableRecord acadLayer = (LayerTableRecord)tr.GetObject(layer.Id, OpenMode.ForWrite);
                                layer.Update(ref acadLayer);
                            }
                            else if (Array.IndexOf(layerNames, layer.Name) == i)
                            {
                                MessageBox.Show("Дублирование имени слоя \"" + layer.Name + "\".");
                            }
                            i++;

                            // Присваиваем фигурам документа новые параметры.
                            foreach (Model.Point point in layer.Points)
                            {
                                AcadDS.DBPoint acadPoint = (AcadDS.DBPoint)tr.GetObject(point.Id, OpenMode.ForWrite);
                                point.Update(ref acadPoint);
                            }

                            foreach (Model.Line line in layer.Lines)
                            {
                                AcadDS.Line acadLine = (AcadDS.Line)tr.GetObject(line.Id, OpenMode.ForWrite);
                                line.Update(ref acadLine);
                            }

                            foreach (Model.Circle circle in layer.Circles)
                            {
                                AcadDS.Circle acadCircle = (AcadDS.Circle)tr.GetObject(circle.Id, OpenMode.ForWrite);
                                circle.Update(ref acadCircle);
                            }
                        }

                        // Если не все слои переименовались удаляем добавочный преффик и суффикс.
                        foreach (ObjectId ltrId in lt)
                        {
                            LayerTableRecord ltr = (LayerTableRecord)tr.GetObject(ltrId, OpenMode.ForWrite);
                            ltr.Name = ltr.Name.Replace("_temp_", "");
                        }
                    }
                    catch (Autodesk.AutoCAD.Runtime.Exception e)
                    {
                        ed.WriteMessage("error. {0}: {1}", e.Message);
                    }
                    tr.Commit();
                    tr.Dispose();
                }
                //lc.Dispose();
            }
            // Обновляем экземпляр класса после изменения документа.
            Reload();
        }