Exemple #1
0
        public void CreateFeaturelineFromCmnd()
        {
            try
            {
                Application.SetSystemVariable("PICKFIRST", 1);

                var _polyCollection = selectPolylines.
                                      GetIdsByTypeTypeValue("POLYLINE",
                                                            "LWPOLYLINE", "POLYLINE2D");
                // Get the document
                //var doc = Application.DocumentManager.MdiActiveDocument;

                //// Get the editor to make the selection
                //Editor oEd = doc.Editor;
                //oEd.Command();
                AcadUtilities.AcadUtilities.SendStringToExecute
                    ("._CreateFeatureLines\n");

                AcadUtilities.AcadUtilities.SendStringToExecute
                    ("._PGA-UnSetPickFirst\n");
            }
            catch (Exception ex)
            {
                MessengerManager.MessengerManager.LogException(ex);
            }
        }
Exemple #2
0
        public static void CopyObjectsBetweenDatabases()
        {
            ObjectIdCollection acObjIdColl = new ObjectIdCollection();
            // Get the current document and database
            Document acDoc   = Application.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;

            // Lock the current document
            using (DocumentLock acLckDocCur = acDoc.LockDocument())
            {
                // Start a transaction
                using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
                {
                    // Open the Block table record for read
                    BlockTable acBlkTbl;
                    acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
                                                 OpenMode.ForRead) as BlockTable;
                    // Open the Block table record Model space for write
                    BlockTableRecord acBlkTblRec;
                    acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
                                                    OpenMode.ForWrite) as BlockTableRecord;
                    // Create a circle that is at (0,0,0) with a radius of 5
                    Circle acCirc1 = new Circle();
                    acCirc1.Center = new Point3d(0, 0, 0);
                    acCirc1.Radius = 5;
                    // Add the new object to the block table record and the transaction
                    acBlkTblRec.AppendEntity(acCirc1);
                    acTrans.AddNewlyCreatedDBObject(acCirc1, true);
                    // Create a circle that is at (0,0,0) with a radius of 7
                    Circle acCirc2 = new Circle();
                    acCirc2.Center = new Point3d(0, 0, 0);
                    acCirc2.Radius = 7;
                    // Add the new object to the block table record and the transaction
                    acBlkTblRec.AppendEntity(acCirc2);
                    acTrans.AddNewlyCreatedDBObject(acCirc2, true);
                    // Add all the objects to copy to the new document
                    acObjIdColl = new ObjectIdCollection();
                    acObjIdColl.Add(acCirc1.ObjectId);
                    acObjIdColl.Add(acCirc2.ObjectId);
                    // Save the new objects to the database
                    acTrans.Commit();
                }
                // Unlock the document
            }
            // Change the file and path to match a drawing template on your workstation
            string sLocalRoot    = Application.GetSystemVariable("LOCALROOTPREFIX") as string;
            string sTemplatePath = sLocalRoot + "Template\\acad.dwt";
            // Create a new drawing to copy the objects to DocumentCollection
            var      acDocMgr   = Application.DocumentManager;
            Document acNewDoc   = acDocMgr.Add(sTemplatePath);
            Database acDbNewDoc = acNewDoc.Database;

            // Lock the new document
            using (DocumentLock acLckDoc = acNewDoc.LockDocument())
            {
                // Start a transaction in the new database
                using (Transaction acTrans = acDbNewDoc.TransactionManager.StartTransaction())
                {
                    // Open the Block table for read
                    BlockTable acBlkTblNewDoc;
                    acBlkTblNewDoc = acTrans.GetObject(acDbNewDoc.BlockTableId,
                                                       OpenMode.ForRead) as BlockTable;
                    // Open the Block table record Model space for read
                    BlockTableRecord acBlkTblRecNewDoc;
                    acBlkTblRecNewDoc = acTrans.GetObject(acBlkTblNewDoc[BlockTableRecord.ModelSpace],
                                                          OpenMode.ForRead) as BlockTableRecord;
                    // Clone the objects to the new database
                    IdMapping acIdMap = new IdMapping();
                    acCurDb.WblockCloneObjects(acObjIdColl, acBlkTblRecNewDoc.ObjectId, acIdMap,
                                               DuplicateRecordCloning.Ignore, false);
                    // Save the copied objects to the database
                    acTrans.Commit();
                }
                // Unlock the document
            }
            // Set the new document current

            acDocMgr.MdiActiveDocument = acNewDoc;
        }
Exemple #3
0
        public static void PurgeDgnLinetypesExt()
        {
            var doc =
                Application.DocumentManager.MdiActiveDocument;
            var ed = doc.Editor;

            var pofo = new PromptOpenFileOptions("\nSelect file to purge");

            // Use the command-line version if FILEDIA is 0 or
            // CMDACTIVE indicates we're being called from a script
            // or from LISP

            short fd = (short)Application.GetSystemVariable("FILEDIA");
            short ca = (short)Application.GetSystemVariable("CMDACTIVE");

            pofo.PreferCommandLine = (fd == 0 || (ca & 36) > 0);
            pofo.Filter            = "DWG (*.dwg)|*.dwg|All files (*.*)|*.*";

            // Ask the user to select a DWG file to purge

            var pfnr = ed.GetFileNameForOpen(pofo);

            if (pfnr.Status == PromptStatus.OK)
            {
                // Make sure the file exists
                // (it should unless entered via the command-line)

                if (!File.Exists(pfnr.StringResult))
                {
                    ed.WriteMessage(
                        "\nCould not find file: \"{0}\".",
                        pfnr.StringResult
                        );
                    return;
                }

                try
                {
                    // We'll just suffix the selected filename with "-purged"
                    // for the output location. This file will be overwritten
                    // if the command is called multiple times

                    var output =
                        Path.GetDirectoryName(pfnr.StringResult) + "\\" +
                        Path.GetFileNameWithoutExtension(pfnr.StringResult) +
                        "-purged" +
                        Path.GetExtension(pfnr.StringResult);

                    // Assume a post-R12 drawing

                    using (var db = new Autodesk.AutoCAD.DatabaseServices.Database(false, true))
                    {
                        // Read the DWG file into our Database object

                        db.ReadDwgFile(
                            pfnr.StringResult,
                            FileOpenMode.OpenForReadAndReadShare,
                            false,
                            ""
                            );

                        // No graphical changes, so we can keep the preview
                        // bitmap

                        db.RetainOriginalThumbnailBitmap = true;

                        // We'll store the current working database, to reset
                        // after the purge operation

                        var wdb = HostApplicationServices.WorkingDatabase;
                        HostApplicationServices.WorkingDatabase = db;

                        // Purge unused DGN linestyles from the drawing
                        // (returns false if nothing is erased)

                        if (PurgeDgnLinetypesInDb(db, ed))
                        {
                            // Check the version of the drawing to save back to

                            var ver =
                                (db.LastSavedAsVersion == DwgVersion.MC0To0
                                    ? DwgVersion.Current
                                    : db.LastSavedAsVersion
                                );

                            // Now we can save

                            db.SaveAs(output, ver);

                            ed.WriteMessage(
                                "\nSaved purged file to \"{0}\".",
                                output
                                );
                        }

                        // Still need to reset the working database

                        HostApplicationServices.WorkingDatabase = wdb;
                    }
                }
                catch (Autodesk.AutoCAD.Runtime.Exception ex)
                {
                    ed.WriteMessage("\nException: {0}", ex.Message);
                }
            }
        }
Exemple #4
0
 public void SetPickFirst()
 {
     Application.SetSystemVariable("PICKFIRST", 0);
 }