Esempio n. 1
0
        /// <summary>
        /// Commits the changes made to the summary info.
        /// </summary>
        internal void Commit()
        {
            if (Changed)
            {
                var builder = new DatabaseSummaryInfoBuilder(database.SummaryInfo);

                if (customPropertiesChanged)
                {
                    builder.CustomPropertyTable.Clear();

                    foreach (var kvp in customProperties)
                    {
                        builder.CustomPropertyTable[kvp.Key] = kvp.Value;
                    }
                }

                if (authorChanged)
                {
                    builder.Author = author;
                }

                if (commentsChanged)
                {
                    builder.Comments = comments;
                }

                if (hyperlinkBaseChanged)
                {
                    builder.HyperlinkBase = hyperlinkBase;
                }

                if (keywordsChanged)
                {
                    builder.Keywords = keywords;
                }

                if (lastSavedByChanged)
                {
                    builder.LastSavedBy = lastSavedBy;
                }

                if (revisionNumberChanged)
                {
                    builder.RevisionNumber = revisionNumber;
                }

                if (subjectChanged)
                {
                    builder.Subject = subject;
                }

                if (titleChanged)
                {
                    builder.Title = title;
                }

                database.SummaryInfo = builder.ToDatabaseSummaryInfo();
            }
        }
 private void button1_Click(object sender, EventArgs e)
 {
     if (!string.IsNullOrWhiteSpace(this.textBox1.Text) && !string.IsNullOrWhiteSpace(this.textBox4.Text))
     {
         this.CurPanel.DrawingNo = this.textBox1.Text;
         this.CurPanel.Date      = String.Format("{0:00}", DateTime.Now.Day) + "/" + String.Format("{0:00}", DateTime.Now.Month) + "/" + String.Format("{0:0000}", DateTime.Now.Year);
         this.CurPanel.Alt       = this.textBox4.Text;
         using (Services svcs = new Services())
         {
             Database db = new Database(false, true);
             db.ReadDwgFile(this.CurDocFileName, System.IO.FileShare.Read, false, null);
             using (Transaction trans = db.TransactionManager.StartTransaction())
             {
                 List <string> properties        = typeof(PanelInfor).GetProperties().Select(p => p.Name).ToList();
                 Dictionary <string, string> dic = new Dictionary <string, string>();
                 foreach (var item in properties)
                 {
                     dic.Add(item, typeof(PanelInfor).GetProperty(item).GetValue(this.CurPanel, null).ToString());
                 }
                 if (db.HasSummaryInfo())
                 {
                     var info = new DatabaseSummaryInfoBuilder();
                     foreach (KeyValuePair <string, string> item in dic)
                     {
                         info.CustomPropertyTable.Add(item.Key, item.Value);
                     }
                     db.SummaryInfo = info.ToDatabaseSummaryInfo();
                 }
                 else
                 {
                     AddCustomInfo(dic, db);
                 }
                 trans.Commit();
             }
             //var newfn = this.CurDocFileName.Replace(".dwg", "-" + DateTime.Now.Year + DateTime.Now.Month + DateTime.Now.Day + ".dwg");
             db.Save();
             db.CloseInput(true);
             MyHelper.MyOpenFolder(Path.GetDirectoryName(this.CurDocFileName), Path.GetFileName(this.CurDocFileName));
         }
         MessageBox.Show("Panel Inforamtion Update Complate!");
     }
     else
     {
         if (!string.IsNullOrWhiteSpace(this.textBox1.Text))
         {
             this.textBox1.Focus(); MessageBox.Show("please input correct drawing Number");
         }
         if (!string.IsNullOrWhiteSpace(this.textBox4.Text))
         {
             this.textBox4.Focus(); MessageBox.Show("Please Input Hull Drawing Alteration");
         }
     }
 }
Esempio n. 3
0
        public void SetOnActiveDocument()
        {
            var activeDocument = AcadApp.DocumentManager.MdiActiveDocument;
            var database       = activeDocument.Database;

            var summaryBuilder = new DatabaseSummaryInfoBuilder(database.SummaryInfo);

            summaryBuilder.CustomPropertyTable[DocumentIdKey] = DocumentId;

            using (activeDocument.LockDocument())
            {
                database.SummaryInfo = summaryBuilder.ToDatabaseSummaryInfo();
            }
        }
        /// <summary>
        /// 向图纸中添加图纸属性
        /// </summary>
        /// <param name="dic"></param>
        /// <param name="db">图形数据</param>
        private void AddCustomInfo(Dictionary <string, string> dic, Database db)
        {
            if (db.HasSummaryInfo())
            {
                return;
            }
            var info = new DatabaseSummaryInfoBuilder(db.SummaryInfo);

            foreach (KeyValuePair <string, string> item in dic)
            {
                info.CustomPropertyTable.Add(item.Key, item.Value);
            }
            db.SummaryInfo = info.ToDatabaseSummaryInfo();
        }
Esempio n. 5
0
        public static void SetCustomProperty(string key, string value)
        {
            DatabaseSummaryInfoBuilder infoBuilder = new DatabaseSummaryInfoBuilder(Database.SummaryInfo);
            IDictionary custProps = infoBuilder.CustomPropertyTable;

            if (custProps.Contains(key))
            {
                custProps[key] = value;
            }
            else
            {
                custProps.Add(key, value);
            }
            Database.SummaryInfo = infoBuilder.ToDatabaseSummaryInfo();
        }
 private void button1_Click(object sender, EventArgs e)
 {
     if (!this.textBox1.Text.IsNullOrWhiteSpace() && this.textBox4.Text.IsNumeric())
     {
         this.CurPanel.DrawingNo = this.textBox1.Text;
         this.CurPanel.Date      = String.Format("{0:00}", DateTime.Now.Day) + "/" + String.Format("{0:00}", DateTime.Now.Month) + "/" + String.Format("{0:0000}", DateTime.Now.Year);
         this.CurPanel.Alt       = this.textBox4.Text;
         using (DocumentLock doclock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument())
         {
             var           db                = HostApplicationServices.WorkingDatabase;
             List <string> properties        = typeof(PanelInfor).GetProperties().Select(p => p.Name).ToList();
             Dictionary <string, string> dic = new Dictionary <string, string>();
             foreach (var item in properties)
             {
                 dic.Add(item, typeof(PanelInfor).GetProperty(item).GetValue(this.CurPanel).ToString());
             }
             if (db.HasSummaryInfo())
             {
                 var info = new DatabaseSummaryInfoBuilder();
                 foreach (KeyValuePair <string, string> item in dic)
                 {
                     info.CustomPropertyTable.Add(item.Key, item.Value);
                 }
                 db.SummaryInfo = info.ToDatabaseSummaryInfo();
             }
             else
             {
                 AddCustomInfo(dic);
             }
             Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.Regen();
             Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("Panel Inforamtion Update Complate!");
         }
     }
     else
     {
         if (this.textBox1.Text.IsNullOrWhiteSpace())
         {
             this.textBox1.Focus(); Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("please input correct drawing Number");
         }
         if (!this.textBox4.Text.IsNumeric())
         {
             this.textBox4.Focus(); Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("Please Input Hull Drawing Alteration");
         }
     }
 }
Esempio n. 7
0
        static int Main(string[] args)
        {
            int nRes = 0; // Return value for main

            /**********************************************************************/
            /* Set command line defaults                                          */
            /**********************************************************************/
            SaveType   fileType    = SaveType.Save12;
            DwgVersion outVer      = DwgVersion.AC1021;
            bool       disableWait = false;

            /**********************************************************************/
            /* Initialize Teigha                                                  */
            /**********************************************************************/
            using (Services svcs = new Services())
            {
                /**********************************************************************/
                /* Display the Product and Version that created the executable        */
                /**********************************************************************/
                Console.WriteLine("\nOdWriteEx developed using %ls ver %ls");

                /**********************************************************************/
                /* Parse Command Line inputs                                          */
                /**********************************************************************/
                bool bInvalidArgs = (args.Length < 2);
                if (bInvalidArgs)
                {
                    bInvalidArgs = true;
                    nRes         = 1;
                }

                /**********************************************************************/
                /* Set file version                                                   */
                /**********************************************************************/
                if (args.Length >= 2)
                {
                    string argv2 = args[1];
                    switch (argv2)
                    {
                    case "ACAD12":
                        outVer = DwgVersion.vAC12;
                        break;

                    case "ACAD13":
                        outVer = DwgVersion.vAC13;
                        break;

                    case "ACAD14":
                        outVer = DwgVersion.vAC14;
                        break;

                    case "ACAD2000":
                        outVer = DwgVersion.vAC15;
                        break;

                    case "ACAD2004":
                        outVer = DwgVersion.vAC18;
                        break;

                    case "ACAD2007":
                        outVer = DwgVersion.vAC21;
                        break;

                    case "ACAD2010":
                        outVer = DwgVersion.vAC24;
                        break;

                    default:
                        bInvalidArgs = true;
                        nRes         = 1;
                        break;
                    }
                }

                /**********************************************************************/
                /* Set file type                                                      */
                /**********************************************************************/
                if (args.Length >= 3)
                {
                    string argv3 = args[2];
                    switch (argv3)
                    {
                    case "DWG":
                        fileType = SaveType.Save12;
                        break;

                    case "DXF":
                        fileType = SaveType.Save13;
                        break;

                    default:
                        bInvalidArgs = true;
                        nRes         = 1;
                        break;
                    }
                }

                /**********************************************************************/
                /* Disable prompt of pressing ENTER                                   */
                /**********************************************************************/
                if (args.Length >= 4)
                {
                    string argv4 = args[3];
                    if (argv4 == "-NoWait")
                    {
                        disableWait = true;
                    }
                }

                if (bInvalidArgs)
                {
                    Console.WriteLine("\n\n\tusage: OdWriteEx <filename> [OutVer] [OutType] [-NoWait]");
                    Console.WriteLine("\n\tOutVer can be any of ACAD12, ACAD13, ACAD14, ACAD2000, ACAD2004, ACAD2007, ACAD2010\n");
                    Console.WriteLine("\n\tOutType can be any of DWG, DXF\n");
                    Console.WriteLine("\n\t-NoWait disables prompt of pressing ENTER at the end of execution.\n");
                    return(nRes);
                }

                /**********************************************************************/
                /* Load and Release RecomputeDimBlock                                 */
                /**********************************************************************/
                //::odrxDynamicLinker()->loadApp(TD_T("RecomputeDimBlock")).release();
                //::odrxDynamicLinker()->loadApp(TD_T("ExFieldEvaluator")).release();

                /**********************************************************************/
                /* Find the folder of the output file                                 */
                /**********************************************************************/
                string outputFolder = args[0];
                outputFolder = Path.GetDirectoryName(outputFolder);
                FileStreamBuf fileBuf = new FileStreamBuf(args[0], false, FileShareMode.DenyNo, FileCreationDisposition.CreateAlways);

                try
                {
                    /********************************************************************/
                    /* Create a default OdDbDatabase object                             */
                    /********************************************************************/
                    using (Database pDb = new Database())
                    {
                        DatabaseSummaryInfo        pSumInfo = pDb.SummaryInfo;
                        DatabaseSummaryInfoBuilder builder  = new DatabaseSummaryInfoBuilder(pSumInfo);
                        builder.Title    = "Title";
                        builder.Author   = "Author";
                        builder.Comments = "Comments";
                        builder.Comments = "File was created by OdWriteEx";
                        pDb.SummaryInfo  = builder.ToDatabaseSummaryInfo();

                        /********************************************************************/
                        /* Fill the database                                                */
                        /********************************************************************/
                        HostApplicationServices.WorkingDatabase = pDb;
                        DbFiller filler = new DbFiller();
                        filler.fillDatabase(pDb);

                        /********************************************************************/
                        /* Audit the database                                               */
                        /********************************************************************/
                        using (AuditInfo aiAppAudit = new CustomAuditInfo(outputFolder + "AuditReport.txt"))
                        {
                            aiAppAudit.FixErrors = true;
                            Console.WriteLine("\n\n");
                            pDb.Audit(aiAppAudit);
                        }
                        #region TODO block
                        //{
                        //  OdSecurityParams securityParams;
                        //  securityParams.password = "******";
                        //  securityParams.nFlags = 1;
                        //  securityParams.nProvType = 0xd;

                        //  // L"Microsoft Base DSS and Diffie-Hellman Cryptographic Provider"
                        //  static wchar_t pn[] =
                        //  {
                        //    0x4D, 0x69, 0x63, 0x72, 0x6F,
                        //    0x73, 0x6F, 0x66, 0x74, 0x20,
                        //    0x42, 0x61, 0x73, 0x65, 0x20,
                        //    0x44, 0x53, 0x53, 0x20, 0x61,
                        //    0x6E, 0x64, 0x20, 0x44, 0x69,
                        //    0x66, 0x66, 0x69, 0x65, 0x2D,
                        //    0x48, 0x65, 0x6C, 0x6C, 0x6D,
                        //    0x61, 0x6E, 0x20, 0x43, 0x72,
                        //    0x79, 0x70, 0x74, 0x6F, 0x67,
                        //    0x72, 0x61, 0x70, 0x68, 0x69,
                        //    0x63, 0x20, 0x50, 0x72, 0x6F,
                        //    0x76, 0x69, 0x64, 0x65, 0x72,
                        //    0x00
                        //  };
                        //  securityParams.provName = pn;

                        //  /************************************************************************/
                        //  /* Uncomment the following line to add the password TD_T("Teigha") to the  */
                        //  /* R18+ file to be created                                              */
                        //  /************************************************************************/
                        //  //pDb->setSecurityParams(securityParams);
                        //}
                        #endregion
                        /********************************************************************/
                        /* Write the database                                               */
                        /********************************************************************/
                        pDb.SaveAs(fileBuf, fileType, outVer, true, 16);

                        /*if (SaveType.Save12 == fileType)
                         * {
                         * pDb.SaveAs(args[0], outVer);
                         * }
                         * else
                         * pDb.DxfOut(args[0], 16, outVer);//16 - default*/
                        Console.WriteLine("\nDatabase has been saved as {0}", pDb.Filename);
                    }
                }
                catch (System.Exception e)
                {
                    Console.WriteLine("\n\nError: {0}", e.Message);
                    nRes = -1;
                }
            }

            if (nRes != 0)
            {
                Console.WriteLine("\n\nPress ENTER to continue...");
                if (!disableWait)
                {
                    Console.ReadLine();
                }
            }
            Console.WriteLine("\n\n");
            return(nRes);
        }