Beispiel #1
1
        public static void SelectSample(Boolean isAllEnt, out String layerName, out Autodesk.AutoCAD.Colors.Color color, out String lineType)
        {
            layerName = null;
            color = new Autodesk.AutoCAD.Colors.Color();
            lineType = null;
            try
            {
                Autodesk.AutoCAD.EditorInput.PromptEntityOptions edOpt = new Autodesk.AutoCAD.EditorInput.PromptEntityOptions("\nВыберите объект аналог: ");
                if (isAllEnt)
                {
                    edOpt.SetRejectMessage("Объект не Arc,Circle,Line,Polyline.\n");
                    edOpt.AddAllowedClass(typeof(Autodesk.AutoCAD.DatabaseServices.Circle), false);
                    edOpt.AddAllowedClass(typeof(Autodesk.AutoCAD.DatabaseServices.Line), false);
                    edOpt.AddAllowedClass(typeof(Autodesk.AutoCAD.DatabaseServices.Polyline), false);
                    edOpt.AddAllowedClass(typeof(Autodesk.AutoCAD.DatabaseServices.Arc), false);
                }
                else
                {
                    edOpt.SetRejectMessage("Объект не полилиния.\n");
                    edOpt.AddAllowedClass(typeof(Autodesk.AutoCAD.DatabaseServices.Polyline), false);
                }
                edOpt.AllowNone = false;
                edOpt.AllowObjectOnLockedLayer = false;

                Autodesk.AutoCAD.EditorInput.PromptEntityResult edRes = AcadApp.AcaEd.GetEntity(edOpt);
                if (edRes.Status == Autodesk.AutoCAD.EditorInput.PromptStatus.OK)
                {
                    using (var trans = AcadApp.StartTransaction())
                    {
                        try
                        {
                            Curve selCurve;
                            selCurve = (Curve)trans.GetObject(edRes.ObjectId, OpenMode.ForRead);
                            layerName = selCurve.Layer;
                            color = selCurve.Color;
                            lineType = selCurve.Linetype;
                            AcadApp.AcaEd.WriteMessage("OK.\n");
                        }
                        catch (System.Exception ex)
                        {
                            AcadApp.AcaEd.WriteMessage("\nERROR: AcadApp.SelectSample()::PROCESS " + ex + "\n");
                        }
                    } //using trans
                }
            }
            catch (System.Exception ex)
            {
                AcadApp.AcaEd.WriteMessage("\nERROR: AcadApp.SelectSample()::EXTERNAL " + ex + "\n");
            }
            return;
        }
Beispiel #2
0
        static public void mainTheodoliteStrokeParser()
        {
            // Получение текущего документа и базы данных
            App.Document acDoc = App.Application.DocumentManager.MdiActiveDocument;
            if (acDoc == null)
            {
                return;
            }

            SettingsParser settings = SettingsParser.getInstance();

            if (settings.Update())
            {
                return;
            }


            Ed.Editor acEd = acDoc.Editor;

            //тут запросить масштаб
            //Предполагается всего 4 вида стандартных масштабов - 1:500, 1:1000, 1:2000, 1:5000.
            Ed.PromptKeywordOptions pKeyOpts = new Ed.PromptKeywordOptions("");
            pKeyOpts.Message = "\nEnter an option: 1/";

            foreach (Scale i in settings.ScaleList)
            {
                pKeyOpts.Keywords.Add(i.Number.ToString());
            }

            pKeyOpts.AllowNone = false;
            pKeyOpts.AppendKeywordsToMessage = true;

            Ed.PromptResult pKeyRes = acDoc.Editor.GetKeywords(pKeyOpts);
            if (pKeyRes.Status != Ed.PromptStatus.OK)
            {
                return;
            }

            settings._Scale = settings.ScaleList.FirstOrDefault(s => s.Number == int.Parse(pKeyRes.StringResult));
            Model.Init();

            bool goOn = true; //Продолжать ли выбор

            do
            {
                Ed.PromptEntityOptions opt = new Ed.PromptEntityOptions("\n Select polyline: ");
                opt.AllowNone = false;
                opt.AllowObjectOnLockedLayer = false;
                opt.SetRejectMessage("\nNot a pline try again: ");
                opt.AddAllowedClass(typeof(Db.Polyline), true);

                Ed.PromptEntityResult res = acEd.GetEntity(opt);

                goOn = (res.Status == Ed.PromptStatus.OK) ? Model.GetData(res.ObjectId) : false;
            } while (goOn);

            Model.OutPutData();
        }
Beispiel #3
0
        public static void PlotRegion()
        {
            Ap.Document doc = cad.DocumentManager.MdiActiveDocument;
            if (doc == null || doc.IsDisposed)
            {
                return;
            }

            Ed.Editor   ed = doc.Editor;
            Db.Database db = doc.Database;

            using (doc.LockDocument())
            {
                Ed.PromptEntityOptions peo = new Ed.PromptEntityOptions(
                    "\nSelect a region"
                    );

                peo.SetRejectMessage("\nIt is not a region."
                                     );
                peo.AddAllowedClass(typeof(Db.Region), false);

                Ed.PromptEntityResult per = ed.GetEntity(peo);

                if (per.Status != Ed.PromptStatus.OK)
                {
                    ed.WriteMessage("\nCommand canceled.\n");
                    return;
                }

                Db.ObjectId regionId = per.ObjectId;

                Microsoft.Win32.SaveFileDialog saveFileDialog = new Microsoft.Win32
                                                                .SaveFileDialog();
                saveFileDialog.Title =
                    "PDF file name";
                saveFileDialog.Filter = "PDF-files|*.pdf";
                bool?result = saveFileDialog.ShowDialog();

                if (!result.HasValue || !result.Value)
                {
                    ed.WriteMessage("\nCommand canceled.");
                    return;
                }

                String pdfFileName = saveFileDialog.FileName;

                PlotRegion(regionId, "DWG To PDF.pc3",
                           "ISO_A4_(210.00_x_297.00_MM)", pdfFileName);

                ed.WriteMessage("\nThe \"{0}\" file created.\n", pdfFileName);
            }
        }
        public static void DOinBlock()
        {
            App.Document dwg = App.Application.DocumentManager.MdiActiveDocument;
            Ed.Editor    ed  = dwg.Editor;

            //Ask user to select a block. In real world, I use code
            //to select all targeting blocks by its name, so that
            //user does not have to select block manually
            Ed.PromptEntityOptions opt = new Ed.PromptEntityOptions("\nSelect a block:");
            opt.SetRejectMessage("\nInvalid: not a block.");
            opt.AddAllowedClass(typeof(Db.BlockReference), true);
            Ed.PromptEntityResult res = ed.GetEntity(opt);

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

            SetDrawOrderInBlock(dwg, res.ObjectId);
            ed.Regen();

            Autodesk.AutoCAD.Internal.Utils.PostCommandPrompt();
        }
Beispiel #5
0
        public void StructurePipesLabels()
        {
            Ed.Editor         ed     = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            Civ.CivilDocument civDoc = Autodesk.Civil.ApplicationServices.CivilApplication.ActiveDocument;
            // Document AcadDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;

            // Check that there's a pipe network to parse
            if (civDoc.GetPipeNetworkIds() == null)
            {
                ed.WriteMessage("There are no pipe networks to export.  Open a document that contains at least one pipe network");
                return;
            }


            // Iterate through each pipe network
            using (Db.Transaction ts = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction()) {
                Dictionary <string, char> dictPipe = new Dictionary <string, char>(); // track data parts column

                Ed.PromptEntityOptions opt = new Ed.PromptEntityOptions("\nSelect an Structure");
                opt.SetRejectMessage("\nObject must be an Structure.\n");
                opt.AddAllowedClass(typeof(CivDb.Structure), false);
                Db.ObjectId structureID = ed.GetEntity(opt).ObjectId;

                try {
                    //////Db.ObjectId oNetworkId = civDoc.GetPipeNetworkIds()[0];
                    //////CivDb.Network oNetwork = ts.GetObject(oNetworkId, Db.OpenMode.ForWrite) as CivDb.Network;

                    //// Get pipes:
                    //ObjectIdCollection oPipeIds = oNetwork.GetPipeIds();
                    //int pipeCount = oPipeIds.Count;

                    //// we can edit the slope, so make that column yellow
                    //Range colRange = xlWsPipes.get_Range("D1", "D" + ( pipeCount + 1 ));
                    //colRange.Interior.ColorIndex = 6;
                    //colRange.Interior.Pattern = XlPattern.xlPatternSolid;
                    //colRange.Interior.PatternColorIndex = XlColorIndex.xlColorIndexAutomatic;

                    //foreach ( ObjectId oid in oPipeIds ) {

                    //    Pipe oPipe = ts.GetObject(oid, OpenMode.ForRead) as Pipe;
                    //    ed.WriteMessage("   " + oPipe.Name);
                    //    col = 'B';
                    //    row++;
                    //    aRange = xlWsPipes.get_Range("A" + row, System.Type.Missing);
                    //    aRange.Value2 = oPipe.Handle.Value.ToString();
                    //    aRange = xlWsPipes.get_Range("B" + row, System.Type.Missing);
                    //    aRange.Value2 = oPipe.StartPoint.X + "," + oPipe.StartPoint.Y + "," + oPipe.StartPoint.Z;
                    //    aRange = xlWsPipes.get_Range("C" + row, System.Type.Missing);
                    //    aRange.Value2 = oPipe.EndPoint.X + "," + oPipe.EndPoint.Y + "," + oPipe.EndPoint.Z;

                    //    // This only gives the absolute value of the slope:
                    //    // aRange = xlWsPipes.get_Range("D" + row, System.Type.Missing);
                    //    // aRange.Value2 = oPipe.Slope;
                    //    // This gives a signed value:
                    //    aRange = xlWsPipes.get_Range("D" + row, System.Type.Missing);
                    //    aRange.Value2 = ( oPipe.EndPoint.Z - oPipe.StartPoint.Z ) / oPipe.Length2DCenterToCenter;

                    //    // Get the catalog data to use later
                    //    ObjectId partsListId = doc.Styles.PartsListSet["Standard"];
                    //    PartsList oPartsList = ts.GetObject(partsListId, OpenMode.ForRead) as PartsList;
                    //    ObjectIdCollection oPipeFamilyIdCollection = oPartsList.GetPartFamilyIdsByDomain(DomainType.Pipe);

                    //    foreach ( PartDataField oPartDataField in oPipe.PartData.GetAllDataFields() ) {
                    //        // Make sure the data has a column in Excel, if not, add the column
                    //        if ( !dictPipe.ContainsKey(oPartDataField.ContextString) ) {
                    //            char nextCol = ( char )( ( int )'E' + dictPipe.Count );
                    //            aRange = xlWsPipes.get_Range("" + nextCol + "1", System.Type.Missing);
                    //            aRange.Value2 = oPartDataField.ContextString + "(" + oPartDataField.Name + ")";
                    //            dictPipe.Add(oPartDataField.ContextString, nextCol);

                    //            // We can edit inner diameter or width, so make those yellow
                    //            if ( ( oPartDataField.ContextString == "PipeInnerDiameter" ) || ( oPartDataField.ContextString == "PipeInnerWidth" ) ) {
                    //                colRange = xlWsPipes.get_Range("" + nextCol + "1", "" + nextCol + ( pipeCount + 1 ));
                    //                colRange.Interior.ColorIndex = 6;
                    //                colRange.Interior.Pattern = XlPattern.xlPatternSolid;
                    //                colRange.Interior.PatternColorIndex = XlColorIndex.xlColorIndexAutomatic;
                    //            }

                    //            // Check the part catalog data to see if this part data is user-modifiable
                    //            foreach ( ObjectId oPipeFamliyId in oPipeFamilyIdCollection ) {
                    //                PartFamily oPartFamily = ts.GetObject(oPipeFamliyId, OpenMode.ForRead) as PartFamily;
                    //                SizeFilterField oSizeFilterField = null;

                    //                try {
                    //                    oSizeFilterField = oPartFamily.PartSizeFilter[oPartDataField.Name];
                    //                } catch ( System.Exception e ) { }

                    //                /* You can also iterate through all defined size filter fields this way:
                    //                 SizeFilterRecord oSizeFilterRecord = oPartFamily.PartSizeFilter;
                    //                 for ( int i = 0; i < oSizeFilterRecord.ParamCount; i++ ) {
                    //                     oSizeFilterField = oSizeFilterRecord[i];
                    //                  } */

                    //                if ( oSizeFilterField != null ) {
                    //                         // Check whether it can be modified:
                    //                         if ( oSizeFilterField.DataSource == PartDataSourceType.Optional ) {
                    //                             colRange = xlWsPipes.get_Range("" + nextCol + "1", "" + nextCol + ( pipeCount + 1 ));
                    //                             colRange.Interior.ColorIndex = 4;
                    //                             colRange.Interior.Pattern = XlPattern.xlPatternSolid;
                    //                             colRange.Interior.PatternColorIndex = XlColorIndex.xlColorIndexAutomatic;
                    //                         }

                    //                         break;
                    //                     }

                    //            }
                    //        }
                    //        char iColumnPipes = dictPipe[oPartDataField.ContextString];
                    //        aRange = aRange = xlWsPipes.get_Range("" + iColumnPipes + row, System.Type.Missing);
                    //        aRange.Value2 = oPartDataField.Value;

                    //    }
                    //}

                    // Now export the structures

                    Dictionary <string, char> dictStructures = new Dictionary <string, char>(); // track data parts column

                    // Get structures:

                    //Db.ObjectIdCollection oStructureIds = oNetwork.GetStructureIds();
                    //foreach ( Db.ObjectId oid in structureID ) {
                    CivDb.Structure    oStructure    = ts.GetObject(structureID, Db.OpenMode.ForRead) as CivDb.Structure;
                    CivDb.Network      oNetwork      = ts.GetObject(oStructure.NetworkId, Db.OpenMode.ForWrite) as CivDb.Network;
                    string[]           connPipeNames = oStructure.GetConnectedPipeNames();
                    PipeData.BIVPipe   pipe          = new PipeData.BIVPipe();
                    List <Db.ObjectId> pipeIds       = pipe.GetPipeIdByName(connPipeNames);
                    ed.WriteMessage("\nК колодцу присоеденены следующие трубы: ");
                    foreach (Db.ObjectId pipeId in pipeIds)
                    {
                        CivDb.Pipe oPipe = ts.GetObject(pipeId, Db.OpenMode.ForRead) as CivDb.Pipe;
                        ed.WriteMessage("{0} | {1:0.000}   |||   ", oPipe.Name, oStructure.get_PipeCenterDepth(new int()));
                    }
                    //col = 'B';
                    //row++;
                    //aRange = xlWsStructures.get_Range("" + col + row, System.Type.Missing);
                    //aRange.Value2 = oStructure.Handle.Value;
                    //aRange = xlWsStructures.get_Range("" + ++col + row, System.Type.Missing);
                    //aRange.Value2 = oStructure.Position.X + "," + oStructure.Position.Y + "," + oStructure.Position.Z;

                    //foreach ( CivDb.PartDataField oPartDataField in oStructure.PartData.GetAllDataFields() ) {
                    //    // Make sure the data has a column in Excel, if not, add the column
                    //    if ( !dictStructures.ContainsKey(oPartDataField.ContextString) ) {
                    //        char nextCol = ( char )( ( int )'D' + dictStructures.Count );
                    //        //aRange = xlWsStructures.get_Range("" + nextCol + "1", System.Type.Missing);
                    //        //aRange.Value2 = oPartDataField.ContextString;
                    //        dictStructures.Add(oPartDataField.ContextString, nextCol);

                    //    }
                    //    char iColumnStructure = dictStructures[oPartDataField.ContextString];
                    //ed.WriteMessage("\npartDataField.Name: " + oPartDataField.Name + "   ===   ColumnStructure to string: " + iColumnStructure + "   ===   PartDataField.Value: " + oPartDataField.Value.ToString() + "\n");
                    //    //aRange = aRange = xlWsStructures.get_Range("" + iColumnStructure + row, System.Type.Missing);
                    //    //aRange.Value2 = oPartDataField.Value;
                    //}
                    //}
                } catch (Autodesk.AutoCAD.Runtime.Exception ex) {
                    ed.WriteMessage("StructurePipesData: " + ex.Message);
                    return;
                }
            }
        }