Exemplo n.º 1
0
        public void BlkAttsBrush()
        {
            Document      doc     = AcadApp.DocumentManager.MdiActiveDocument;
            Editor        ed      = doc.Editor;
            Database      db      = doc.Database;
            AttsSelection attsSel = new AttsSelection();

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                //提示用户选择数据源块参照
                PromptEntityOptions orgOpt = new PromptEntityOptions("选择源格式块");
                orgOpt.SetRejectMessage("选择的不是块!");
                orgOpt.AddAllowedClass(typeof(BlockReference), true); //只能选择块参照
                PromptEntityResult orgRes = ed.GetEntity(orgOpt);
                if (orgRes.Status == PromptStatus.OK)                 //选择正确
                {
                    orgBlkRef = orgRes.ObjectId.GetObject(OpenMode.ForRead) as BlockReference;
                    if (orgBlkRef.AttributeCollection.Count == 0)
                    {
                        ed.WriteMessage("所选对象不包含属性!");
                        return;
                    }
                    else
                    {
                        atts = new Dictionary <string, string>();                 //初始化属性集字典
                        foreach (ObjectId attId in orgBlkRef.AttributeCollection) //获得源块属性值
                        {
                            AttributeReference attRef = attId.GetObject(OpenMode.ForRead) as AttributeReference;
                            atts.Add(attRef.Tag.ToUpper(), attRef.TextString);
                            attsSel.checkedListBoxAtts.Items.Add(attRef.Tag);
                        }
                    }
                }
                trans.Commit();
            }
            AcadApp.ShowModalDialog(attsSel);
        }
Exemplo n.º 2
0
        SnoopEntityByHandle()
        {
            ObjectId           id     = ObjectId.Null;
            ObjectIdCollection selSet = new ObjectIdCollection();

            Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;

            Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            PromptStringOptions options = new PromptStringOptions("Handle of database object");

            String str = ed.GetString(options).StringResult;

            if (str != String.Empty)
            {
                Handle h = Utils.Db.StringToHandle(str);

                try {
                    id = Utils.Db.HandleToObjectId(db, h);

                    selSet.Add(id);

                    using (TransactionHelper trHlp = new TransactionHelper()) {
                        trHlp.Start();

                        Snoop.Forms.DBObjects dbox = new Snoop.Forms.DBObjects(selSet, trHlp);
                        dbox.Text = "Selected Entities";
                        AcadApp.ShowModalDialog(dbox);

                        trHlp.Commit();
                    }
                }
                catch (Autodesk.AutoCAD.Runtime.Exception x) {
                    AcadUi.PrintToCmdLine(string.Format("\nERROR: {0}", ((ErrorStatus)x.ErrorStatus).ToString()));
                }
            }
        }
Exemplo n.º 3
0
        SnoopNestedEntity()
        {
            Editor             ed     = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            ObjectIdCollection selSet = new ObjectIdCollection();

            while (true)
            {
                PromptNestedEntityOptions prOptNent = new PromptNestedEntityOptions("\nSelect nested entities or: ");
                prOptNent.AppendKeywordsToMessage = true;
                prOptNent.Keywords.Add("Done");

                PromptNestedEntityResult res = ed.GetNestedEntity(prOptNent);
                if (res.Status == PromptStatus.OK)
                {
                    selSet.Add(res.ObjectId);
                }
                else if (res.Status == PromptStatus.Keyword)
                {
                    break;
                }
                else
                {
                    return;
                }
            }

            using (TransactionHelper trHlp = new TransactionHelper()) {
                trHlp.Start();

                Snoop.Forms.DBObjects dbox = new Snoop.Forms.DBObjects(selSet, trHlp);
                dbox.Text = "Selected Entities";
                AcadApp.ShowModalDialog(dbox);

                trHlp.Commit();
            }
        }
Exemplo n.º 4
0
        public static void ExportPointGroups()
        {
            Document      acDoc = AcApp.DocumentManager.MdiActiveDocument;
            Database      acDb  = acDoc.Database;
            Editor        acEd  = acDoc.Editor;
            CivilDocument cApp  = Autodesk.Civil.ApplicationServices.CivilApplication.ActiveDocument;

            PointGroupCollection pointGroups;
            ExportPoints         form;

            #region Job Number
            var jobNumber = Path.GetFileNameWithoutExtension(acDoc.Name);
            if (jobNumber.Length > 9)
            {
                jobNumber = jobNumber.Remove(9);
            }
            if (!JobNumber.TryParse(jobNumber))
            {
                acEd.WriteMessage("Job number could not be determined." + Environment.NewLine);
                return;
            }
            string path = JobNumber.GetPath(jobNumber);
            if (!Directory.Exists(path))
            {
                acEd.WriteMessage("Project folder could not be determined." + Environment.NewLine);
            }
            #endregion

            using (Transaction tr = acDb.TransactionManager.StartTransaction())
            {
                pointGroups = cApp.PointGroups;
                form        = new ExportPoints(pointGroups, path);
                var fResult = AcApp.ShowModalDialog(form);

                if (fResult == DialogResult.Cancel)
                {
                    acEd.WriteMessage("\nExport operation cancelled."); return;
                }
                acEd.WriteMessage("\nExport operation continued.");

                if (!Directory.Exists(form.FolderPath))
                {
                    Directory.CreateDirectory(form.FolderPath);
                }

                string file = form.FolderPath + "\\" + form.FileName.Trim();
                acEd.WriteMessage($"\nWriting {form.PointGroup} points to {file}");

                switch (form.PointGroup.ToLower())
                {
                case "!all points":
                {
                    foreach (ObjectId pointId in cApp.CogoPoints)
                    {
                        CogoPoint point    = (CogoPoint)pointId.GetObject(OpenMode.ForRead);
                        string    pointTxt = $"{point.PointNumber},{Math.Round(point.Northing, 4)},{Math.Round(point.Easting, 4)},{Math.Round(point.Elevation,4)},{point.RawDescription}{Environment.NewLine}";
                        File.AppendAllText(file, pointTxt);
                    }
                    break;
                }

                case "!comp points":
                {
                    foreach (ObjectId pointId in cApp.CogoPoints)
                    {
                        CogoPoint point   = (CogoPoint)pointId.GetObject(OpenMode.ForRead);
                        int       pnumber = Convert.ToInt32(point.PointNumber);
                        if (pnumber >= 1000 && pnumber < 10000)
                        {
                            string pointTxt = $"{point.PointNumber},{Math.Round(point.Northing, 4)},{Math.Round(point.Easting, 4)},{Math.Round(point.Elevation, 4)},{point.RawDescription}{Environment.NewLine}";
                            File.AppendAllText(file, pointTxt);
                        }
                    }
                    break;
                }

                case "!control points":
                {
                    foreach (ObjectId pointId in cApp.CogoPoints)
                    {
                        CogoPoint point       = (CogoPoint)pointId.GetObject(OpenMode.ForRead);
                        string    description = point.RawDescription;
                        if (controlCodes.Any(s => description.Contains(s)))
                        {
                            string pointTxt = $"{point.PointNumber},{Math.Round(point.Northing, 4)},{Math.Round(point.Easting, 4)},{Math.Round(point.Elevation, 4)},{point.RawDescription}{Environment.NewLine}";
                            File.AppendAllText(file, pointTxt);
                        }
                    }
                    break;
                }

                default:
                {
                    foreach (ObjectId pgId in pointGroups)
                    {
                        PointGroup group = (PointGroup)pgId.GetObject(OpenMode.ForRead);
                        if (group.Name.ToLower() == form.PointGroup.ToLower())
                        {
                            var cogoPoints = group.GetCogoPoints();
                            acEd.WriteMessage($"\nPoint Group {form.PointGroup} contains {cogoPoints.Count} points");
                            foreach (CogoPoint point in cogoPoints)
                            {
                                string pointTxt = $"{point.PointNumber},{Math.Round(point.Northing, 4)},{Math.Round(point.Easting, 4)},{Math.Round(point.Elevation, 4)},{point.RawDescription}{Environment.NewLine}";
                                File.AppendAllText(file, pointTxt);
                            }
                        }
                    }

                    break;
                }
                }
                acEd.WriteMessage($"\nPoints exported successfully.");
                form.Dispose();
                tr.Commit();
            };
        }
Exemplo n.º 5
0
 public static DialogResult ShowModalDialog(Form form)
 {
     return(Application.ShowModalDialog(form));
 }
Exemplo n.º 6
0
        TestTabForm()
        {
            TestTabForm dbox = new TestTabForm();

            AcadApp.ShowModalDialog(dbox);
        }
Exemplo n.º 7
0
 Events()
 {
     MgdDbg.Reactors.Forms.EventsForm dbox = new MgdDbg.Reactors.Forms.EventsForm();
     AcadApp.ShowModalDialog(dbox);
 }
Exemplo n.º 8
0
 SnoopEd()
 {
     Snoop.Forms.Editor dbox = new Snoop.Forms.Editor();
     AcadApp.ShowModalDialog(dbox);
 }
Exemplo n.º 9
0
 public void showBlockTree()
 {
     BlockTreeView.TreeViewForm tfm = new BlockTreeView.TreeViewForm();
     AcAp.ShowModalDialog(tfm);
 }
Exemplo n.º 10
0
        public void frmIncrementV2()
        {
            doc = Application.DocumentManager.MdiActiveDocument;
            db  = doc.Database;
            ed  = doc.Editor;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTableRecord[] blockWithAttribute = db.GetBlocksWithAttribute();
                BlockTableRecord   selectedItem       = (BlockTableRecord)this.dlg.cbxBlock.SelectedItem;
                int selectedindex = this.dlg.cbxAttrib.SelectedIndex;
                this.dlg.cbxBlock.DataSource = blockWithAttribute;
                if (!blockWithAttribute.Contains <BlockTableRecord>(selectedItem))
                {
                    this.dlg.cbxBlock.Text = "";
                    this.dlg.cbxAttrib.Items.Clear();
                }
                else
                {
                    this.dlg.cbxBlock.SelectedItem   = selectedItem;
                    this.dlg.cbxAttrib.SelectedIndex = selectedindex;
                }
                selectedItem  = (BlockTableRecord)this.dlg.cbxSelBlk.SelectedItem;
                selectedindex = this.dlg.cbxSelTag.SelectedIndex;
                this.dlg.cbxSelBlk.DataSource = blockWithAttribute;
                if (blockWithAttribute == null || blockWithAttribute.Length == 0)
                {
                    this.dlg.cbxSelTag.Items.Clear();
                }
                else if (!blockWithAttribute.Contains <BlockTableRecord>(selectedItem))
                {
                    this.dlg.cbxSelBlk.SelectedIndex = 0;
                }
                else
                {
                    this.dlg.cbxSelBlk.SelectedItem  = selectedItem;
                    this.dlg.cbxAttrib.SelectedIndex = selectedindex;
                }

                if (AcAp.ShowModalDialog(this.dlg) == System.Windows.Forms.DialogResult.OK)
                {
                    string prefix = this.dlg.txtPrefix.Text;
                    string suffix = this.dlg.txtSuffix.Text;
                    switch (this.dlg.Tab)
                    {
                    case 0:
                    {
                        this.IncrementAttribute((BlockTableRecord)this.dlg.cbxBlock.SelectedItem, this.dlg.cbxAttrib.SelectedIndex, prefix, suffix);
                    }
                    break;

                    case 1:
                    {
                        this.IncrementText(this.dlg.cbxStyles.Text, this.dlg.cbxAlignment.Text, prefix, suffix);
                    }
                    break;

                    case 2:
                    {
                    }
                    break;

                    default:
                    {
                    }
                    break;
                    }
                }
                tr.Commit();
            }
        }
Exemplo n.º 11
0
        static public void ExportPDF()
        {
            var        doc        = AcApp.DocumentManager.MdiActiveDocument;
            var        ed         = doc.Editor;
            ExportForm exportForm = new ExportForm();
            var        result     = AcApp.ShowModalDialog(exportForm);

            if (result == DialogResult.Cancel)
            {
                ed.WriteMessage($"{Environment.NewLine}The operation has been canceled by the user.");
                return;
            }
            int layoutCount = exportForm.SelectedLayouts.Count;

            ed.WriteMessage($"{Environment.NewLine}Number of selected layouts: {layoutCount}");
            if (layoutCount == 0)
            {
                ed.WriteMessage($"{Environment.NewLine}No layouts were detected.");
                return;
            }
            else if (layoutCount == 1)
            {
                if (PlotFactory.ProcessPlotState == ProcessPlotState.NotPlotting)
                {
                    // First we preview...
                    PreviewEndPlotStatus stat;
                    PlotEngine           pre = PlotFactory.CreatePreviewEngine((int)PreviewEngineFlags.Plot);
                    using (pre)
                    {
                        stat = PlotOrPreview(pre, true, exportForm.SelectedLayouts[0].BlockTableRecordId, "", "");
                    }
                    if (stat == PreviewEndPlotStatus.Plot)
                    {
                        // And if the user asks, we plot...
                        var jobNumber = Path.GetFileNameWithoutExtension(doc.Name);
                        if (jobNumber.Length > 9)
                        {
                            jobNumber = jobNumber.Remove(9);
                        }
                        if (!JobNumber.TryParse(jobNumber))
                        {
                            ed.WriteMessage("Job number could not be determined." + Environment.NewLine);
                            return;
                        }
                        string path = JobNumber.GetPath(jobNumber);
                        if (Directory.Exists(path))
                        {
                            if (!Directory.Exists(path + "\\Submittals"))
                            {
                                Directory.CreateDirectory(path + "\\Submittals");
                            }
                            PlotEngine ple = PlotFactory.CreatePublishEngine();
                            PlotOrPreview(ple, false, exportForm.SelectedLayouts[0].BlockTableRecordId, path + "\\Submittals", jobNumber);
                            ed.WriteMessage($"{Environment.NewLine}Plot created.");
                        }
                        else
                        {
                            ed.WriteMessage("Project folder could not be determined." + Environment.NewLine);
                        }
                    }
                }
                else
                {
                    ed.WriteMessage(
                        "\nAnother plot is in progress."
                        );
                }
            }
            else
            {
                ObjectIdCollection layouts = new ObjectIdCollection();
                foreach (Layout layout in exportForm.SelectedLayouts)
                {
                    layouts.Add(layout.BlockTableRecordId);
                }
                if (PlotFactory.ProcessPlotState == ProcessPlotState.NotPlotting)
                {
                    int  layoutNum      = 0;
                    bool isFinished     = false;
                    bool isReadyForPlot = false;
                    while (!isFinished)
                    {
                        // Create the preview engine with the appropriate
                        // buttons enabled - this depends on which
                        // layout in the list is being previewed
                        PreviewEngineFlags flags = PreviewEngineFlags.Plot;
                        if (layoutNum > 0)
                        {
                            flags |= PreviewEngineFlags.PreviousSheet;
                        }
                        if (layoutNum < layouts.Count - 1)
                        {
                            flags |= PreviewEngineFlags.NextSheet;
                        }
                        using (PlotEngine pre = PlotFactory.CreatePreviewEngine((int)flags))
                        {
                            PreviewEndPlotStatus stat =
                                MultiplePlotOrPreview(
                                    pre,
                                    true,
                                    layouts,
                                    layoutNum,
                                    "",
                                    ""
                                    );
                            // We're not checking the list bounds for
                            // next/previous as the buttons are only shown
                            // when they can be used
                            if (stat == PreviewEndPlotStatus.Next)
                            {
                                layoutNum++;
                            }
                            else if (stat == PreviewEndPlotStatus.Previous)
                            {
                                layoutNum--;
                            }
                            else if (stat == PreviewEndPlotStatus.Normal || stat == PreviewEndPlotStatus.Cancel)
                            {
                                isFinished = true;
                            }
                            else if (stat == PreviewEndPlotStatus.Plot)
                            {
                                isFinished     = true;
                                isReadyForPlot = true;
                            }
                        }
                    }
                    // If the plot button was used to exit the preview...
                    if (isReadyForPlot)
                    {
                        var jobNumber = Path.GetFileNameWithoutExtension(doc.Name);
                        if (jobNumber.Length > 9)
                        {
                            jobNumber = jobNumber.Remove(9);
                        }
                        if (!JobNumber.TryParse(jobNumber))
                        {
                            ed.WriteMessage("Job number could not be determined." + Environment.NewLine);
                            return;
                        }
                        string path = JobNumber.GetPath(jobNumber);
                        if (Directory.Exists(path))
                        {
                            if (!Directory.Exists(path + "\\Submittals"))
                            {
                                Directory.CreateDirectory(path + "\\Submittals");
                            }
                            using (PlotEngine ple = PlotFactory.CreatePublishEngine())
                            {
                                PreviewEndPlotStatus stat = MultiplePlotOrPreview(ple, false, layouts, -1, path + "\\Submittals", jobNumber);
                            }
                        }
                    }
                }
                else
                {
                    ed.WriteMessage(
                        "\nAnother plot is in progress."
                        );
                }
            }
            exportForm.Dispose();
        }
Exemplo n.º 12
0
        public void AKR_AlbumPanels()
        {
            CommandStart.Start(doc =>
            {
                CheckAcadVer2016();

                string commandName = "AlbumPanels";
                if (string.Equals(_lastStartCommandName, commandName))
                {
                    if ((DateTime.Now - _lastStartCommandDateTime).Seconds < 5)
                    {
                        doc.Editor.WriteMessage("Между запусками команды прошло меньше 5 секунд. Отмена.");
                        return;
                    }
                }

                if (!File.Exists(doc.Name))
                {
                    doc.Editor.WriteMessage("\nНужно сохранить текущий чертеж.");
                    return;
                }

                if (_album == null)
                {
                    doc.Editor.WriteMessage("\nСначала нужно выполнить команду PaintPanels для покраски плитки.");
                }
                else
                {
                    Inspector.Clear();
                    _album.ChecksBeforeCreateAlbum();
                    // После покраски панелей, пользователь мог изменить панели на чертеже, а в альбом это не попадет.
                    // Нужно или выполнить перекраску панелей перед созданием альбома
                    // Или проверить список панелей в _albom и список панелей на чертеже, и выдать сообщение если есть изменения.
                    _album.CheckPanelsInDrawingAndMemory();

                    // Переименование марок пользователем.
                    // Вывод списка панелей для возможности переименования марок АР пользователем
                    FormRenameMarkAR formRenameMarkAR = new FormRenameMarkAR(_album);
                    if (AcAp.ShowModalDialog(formRenameMarkAR) == DialogResult.OK)
                    {
                        var renamedMarksAR = formRenameMarkAR.RenamedMarksAr();
                        // сохранить в словарь
                        Lib.DictNOD.SaveRenamedMarkArToDict(renamedMarksAR);

                        // Переименовать марки АР
                        renamedMarksAR.ForEach(r => r.MarkAR.MarkPainting = r.MarkPainting);

                        // Создание альбома
                        _album.CreateAlbum();

                        if (Inspector.HasErrors)
                        {
                            Inspector.Show();
                        }
                        doc.Editor.Regen();
                        doc.Editor.WriteMessage("\nАльбом панелей выполнен успешно:" + _album.AlbumDir);
                        Logger.Log.Info("Альбом панелей выполнен успешно: {0}", _album.AlbumDir);
                    }
                    else
                    {
                        doc.Editor.WriteMessage("\nОтменено пользователем.");
                    }
                }
                _lastStartCommandName     = commandName;
                _lastStartCommandDateTime = DateTime.Now;
            });
        }
Exemplo n.º 13
0
 public void AddCar()
 {
     AcadApp.ShowModalDialog(new CarTool());
 }
Exemplo n.º 14
0
        public void datablk()
        {
            formTest ftest = new formTest();

            AcAp.ShowModalDialog(ftest);
        }
Exemplo n.º 15
0
 public DialogResult ShowDialog(Form dialog)
 {
     return(Application.ShowModalDialog(dialog));
 }
Exemplo n.º 16
0
 /// <summary> 以非模态、不阻塞的方式显示窗口 </summary>
 public new DialogResult ShowDialog()
 {
     this.Opacity = 1;
     return(Application.ShowModalDialog(null, this));
     //
 }
Exemplo n.º 17
0
        public void ListBlockRef()
        {
            mainform frmBrefColl = new mainform();

            AcAp.ShowModalDialog(frmBrefColl);
        }