コード例 #1
0
 /// <summary>
 /// Initializes the object from an AutoCAD document and a Civil 3D
 /// document.
 /// </summary>
 /// <param name="acadDoc">Represented AutoCAD document.</param>
 /// <param name="civilDoc">Represented Civil 3D document.</param>
 /// <para>
 /// The class encapsulates access to the AutoCAD and Civil 3D
 /// document objects. The Document object is instantiated by the
 /// 'DocumentManager' class, which access the AutoCAD and Civil 3D
 /// document objects representing the same drawing and instantiates
 /// a new Document wrapper.
 /// </para>
 internal Document(acadappsvcs.Document acadDoc)
 {
     m_ThisAcadDocument  = acadDoc;
     m_ThisCivilDocument = CivilDocument.GetCivilDocument(
         m_ThisAcadDocument.Database);
     m_ActiveTransaction = null;
 }
コード例 #2
0
        private static void AddText(Gem.Point2d pnt, string layer, string str)
        {
            App.Document acDoc   = App.Application.DocumentManager.MdiActiveDocument;
            Db.Database  acCurDb = acDoc.Database;

            // старт транзакции
            using (Db.Transaction acTrans = acCurDb.TransactionManager.StartOpenCloseTransaction())
            {
                // Открытие таблицы Блоков для чтения
                Db.BlockTable acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, Db.OpenMode.ForRead) as Db.BlockTable;

                // Открытие записи таблицы Блоков пространства Модели для записи
                Db.BlockTableRecord acBlkTblRec = acTrans.GetObject(acBlkTbl[Db.BlockTableRecord.ModelSpace],
                                                                    Db.OpenMode.ForWrite) as Db.BlockTableRecord;

                Db.MText acMText = new Db.MText();
                acMText.SetDatabaseDefaults();
                acMText.Location = new Gem.Point3d(pnt.X, pnt.Y, 0);
                acMText.Contents = str;
                acMText.Height   = SettingsParser.getInstance()._Scale.Coord;
                acMText.Color    = Autodesk.AutoCAD.Colors.
                                   Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByLayer, 256);
                acMText.Layer = layer;
                acMText.SetDatabaseDefaults();
                // Добавление нового объекта в запись таблицы блоков и в транзакцию
                acBlkTblRec.AppendEntity(acMText);
                acTrans.AddNewlyCreatedDBObject(acMText, true);
                // Сохранение нового объекта в базе данных
                acTrans.Commit();
            }
        }
コード例 #3
0
        public void bx_OpenTamplate()
        {
            App.Document doc = App.Application.DocumentManager.MdiActiveDocument;
            if (doc == null)
            {
                return;
            }

            string strFileName = CheckLocalRepository.GetRepository();

            App.DocumentCollection acDocMgr = App.Application.DocumentManager;

            if (System.IO.File.Exists(strFileName))
            {
                //Для 2011 автокада
#if acad2011
                acDocMgr.Open(strFileName, false);
#endif
                //Для 2012 и выше
#if !acad2011
                App.DocumentCollectionExtension.Open(acDocMgr, strFileName, false);
#endif
            }
            else
            {
                acDocMgr.MdiActiveDocument.Editor.
                WriteMessage($"Файла репозитория { strFileName} не существует.");
            }
        }
コード例 #4
0
        public static Parcel ByNumber(Autodesk.AutoCAD.DynamoNodes.Document document, Site siteObject, int parcelNumber)
        {
            Autodesk.Civil.DatabaseServices.Parcel retParcel = null;
            //get the current document and database
            AcadApp.Document doc = document.AcDocument;
            Database         db  = doc.Database;

            Autodesk.Civil.DatabaseServices.Site site = (Autodesk.Civil.DatabaseServices.Site)siteObject._curCivilObject;
            Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection parcelIds = site.GetParcelIds();
            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                foreach (Autodesk.AutoCAD.DatabaseServices.ObjectId objectId in parcelIds)
                {
                    retParcel = (Autodesk.Civil.DatabaseServices.Parcel)trans.GetObject(objectId, OpenMode.ForRead);
                    if (retParcel.Number != parcelNumber)
                    {
                        retParcel = null;
                    }
                    else
                    {
                        return(new Parcel(retParcel, true));
                    }
                }
            }
            return(null);
        }
コード例 #5
0
        private static void AddCircle(Gem.Point2d pnt, string layer)
        {
            App.Document acDoc   = App.Application.DocumentManager.MdiActiveDocument;
            Db.Database  acCurDb = acDoc.Database;

            // старт транзакции
            using (Db.Transaction acTrans = acCurDb.TransactionManager.StartOpenCloseTransaction())
            {
                // Открытие таблицы Блоков для чтения
                Db.BlockTable acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
                                                           Db.OpenMode.ForRead) as Db.BlockTable;

                // Открытие записи таблицы Блоков пространства Модели для записи
                Db.BlockTableRecord acBlkTblRec = acTrans.GetObject(acBlkTbl[Db.BlockTableRecord.ModelSpace],
                                                                    Db.OpenMode.ForWrite) as Db.BlockTableRecord;

                Db.Circle acCircle = new Db.Circle();
                acCircle.SetDatabaseDefaults();
                acCircle.Center = new Gem.Point3d(pnt.X, pnt.Y, 0);
                acCircle.Radius = SettingsParser.getInstance()._Scale.Circle;
                acCircle.Layer  = layer;
                // Добавление нового объекта в запись таблицы блоков и в транзакцию
                acBlkTblRec.AppendEntity(acCircle);
                acTrans.AddNewlyCreatedDBObject(acCircle, true);
                // Сохранение нового объекта в базе данных
                acTrans.Commit();
            }
        }
コード例 #6
0
        private static void SetDrawOrderInBlock(App.Document dwg, Db.ObjectId blkId)
        {
            using (Db.Transaction tran =
                       dwg.TransactionManager.StartTransaction())
            {
                Db.BlockReference bref = (Db.BlockReference)tran.GetObject(
                    blkId, Db.OpenMode.ForRead);

                Db.BlockTableRecord bdef = (Db.BlockTableRecord)tran.GetObject(
                    bref.BlockTableRecord, Db.OpenMode.ForWrite);

                Db.DrawOrderTable doTbl = (Db.DrawOrderTable)tran.GetObject(
                    bdef.DrawOrderTableId, Db.OpenMode.ForWrite);

                Db.ObjectIdCollection col = new Db.ObjectIdCollection();
                foreach (Db.ObjectId id in bdef)
                {
                    if (id.ObjectClass == Rtm.RXObject.GetClass(typeof(Db.Wipeout)))
                    {
                        col.Add(id);
                    }
                }

                if (col.Count > 0)
                {
                    doTbl.MoveToBottom(col);
                }


                tran.Commit();
            }
        }
コード例 #7
0
        private void btnUpdateFrameSize_Click(object sender, EventArgs e)
        {
            Acad.Document acCurDoc = Acad.Application.DocumentManager.MdiActiveDocument;
            try
            {
                if (cmbDirection.SelectedIndex == -1 || cmbFrameSize.SelectedIndex == -1 || cmbItemType.SelectedIndex == -1)
                {
                    Acad.Application.ShowAlertDialog("类型、方向、图幅参数必须选择!");
                }

                DwgFrameTools dft = new DwgFrameTools(acCurDoc, XmlUtil.getXmlValue("markArea", "value") == "true");

                DwgInfo info = dft.DwgInformation;
                dft.ReplaceFrameBlock(dft.GenerateStandardDwgFileName(
                                          cmbItemType.SelectedIndex == 1,  //1——零件
                                          cmbDirection.SelectedIndex == 0, //0——横向
                                          cmbFrameSize.Text));
                DwgFrameTools dft2 = new DwgFrameTools(acCurDoc, XmlUtil.getXmlValue("markArea", "value") == "true");
                //info.Name += "new";
                //info.DwgNO = "new Dwg no";

                dft2.UpdateDwgInfo(info);
            }
            catch (System.Exception ex)
            {
                acCurDoc.Editor.WriteMessage(ex.ToString());
            }
        }
コード例 #8
0
ファイル: Setup.cs プロジェクト: 15831944/AutoIME
 public static void UnbindCommandToDoc(AcadDocument doc)
 {
     doc.CommandWillStart -= new CommandEventHandler(CommandWillStart);
     doc.CommandEnded     -= new CommandEventHandler(CommandEnded);
     doc.CommandCancelled -= new CommandEventHandler(CommandCancelled);
     doc.CommandFailed    -= new CommandEventHandler(CommandFailed);
 }
コード例 #9
0
ファイル: Document.cs プロジェクト: 15831944/EM
 internal Document(acadAppSvcs.Document acadDoc)
 {
     m_AcadDocument      = acadDoc;
     m_CivilDocument     = CivilDocument.GetCivilDocument(m_AcadDocument.Database);
     m_DocumentLock      = null;
     m_ActiveTransaction = null;
 }
コード例 #10
0
        public static void CreateAndAssignALayer(string layerName)
        {
            // Get the current document and database
            ac.Document acDoc   = ac.Application.DocumentManager.MdiActiveDocument;
            Database    acCurDb = acDoc.Database;

            // Start a transaction
            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                // Open the Layer table for read
                LayerTable acLyrTbl;
                acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId,
                                             OpenMode.ForRead) as LayerTable;

                string sLayerName = layerName;

                if (acLyrTbl.Has(sLayerName) == false)
                {
                    LayerTableRecord acLyrTblRec = new LayerTableRecord();

                    // Assign the layer the ACI color 1 and a name
                    acLyrTblRec.Color = Color.FromColorIndex(ColorMethod.ByAci, 13); // is like red.. but paler.
                    acLyrTblRec.Name  = sLayerName;

                    // Upgrade the Layer table for write
                    acLyrTbl.UpgradeOpen();

                    // Append the new layer to the Layer table and the transaction
                    acLyrTbl.Add(acLyrTblRec);
                    acTrans.AddNewlyCreatedDBObject(acLyrTblRec, true);
                }
                acTrans.Commit();
            }
        }
コード例 #11
0
 /// <summary>
 /// Добавляем ObjectData-атрибуты к примитиву чертежа
 /// </summary>
 /// <param name="wid"> ObjectId примитива </param>
 /// <param name="wr"> Данные атрибутов </param>
 /// <param name="wTbl"> Таблица ObjectData </param>
 public void AddAttr(ObjectId wid, Data.MyRecord wr, Autodesk.Gis.Map.ObjectData.Table wTbl)
 {
     AppServ.Document acDoc = AppServ.Application.DocumentManager.MdiActiveDocument;
     using (AppServ.DocumentLock acLckDoc = acDoc.LockDocument())
     {
         using (Transaction acTrans = acDoc.Database.TransactionManager.StartTransaction())
         {
             using (Record odRecord = Record.Create())
             {
                 wTbl.InitRecord(odRecord);
                 FieldDefinition fdef;
                 Data.FieldValue fval;
                 for (int i = 0; i < wTbl.FieldDefinitions.Count; i++)
                 {
                     fdef = wTbl.FieldDefinitions[i];
                     fval = wr.SearchField(fdef.Name);
                     if (fval != null)
                     {
                         if (!fval.IsGeom)
                         {
                             odRecord[i].Assign(fval.GetString());
                         }
                     }
                 }
                 wTbl.AddRecord(odRecord, wid);
                 acTrans.Commit();
             }
         }
     }
 }
コード例 #12
0
ファイル: PIPELine.cs プロジェクト: chenbin2254/ImportToCAD
        public override void DeleteCADObject(Autodesk.AutoCAD.ApplicationServices.Document doc)
        {
            string[] Layers = null;
            if (this.US_SURVEY_ID.StartsWith("WS"))
            {
                Layers = new string[] { "WSLine", "WSZJ" }
            }
            ;
            else
            {
                Layers = new string[] { "YSLine", "YSZJ" }
            };

            Autodesk.AutoCAD.Interop.AcadDocument AcadDoc = doc.AcadDocument as Autodesk.AutoCAD.Interop.AcadDocument;

            Editor ed    = doc.Editor;
            int    count = 0;

            foreach (string Layer in Layers)
            {
                TypedValue[] tvs = new TypedValue[]

                {
                    new TypedValue((int)DxfCode.LayerName, Layer)
                };
                SelectionFilter sf = new SelectionFilter(tvs);

                PromptSelectionResult psr = ed.SelectAll(sf);

                if (psr.Status == PromptStatus.OK)
                {
                    SelectionSet SS = psr.Value;

                    ObjectId[] idArray = SS.GetObjectIds();

                    for (int i = 0; i < idArray.Length; i++)
                    {
                        if (this is IPipePoint && count == 2)
                        {
                            break;
                        }
                        else if (this is IPIPELine && count == 3)
                        {
                            break;
                        }
                        //Entity ent = (Entity)Tools.GetDBObject(idArray[i]);
                        AcadEntity pAcadEntity = AcadDoc.ObjectIdToObject(idArray[i].OldIdPtr.ToInt64()) as AcadEntity;

                        string ObjectID = GetPointObjectID(pAcadEntity);
                        if (ObjectID.Equals(this.ID))
                        {
                            pAcadEntity.Delete();
                            count++;
                        }
                    }
                }
            }
            AcadDoc.Save();
        }
コード例 #13
0
ファイル: Setup.cs プロジェクト: 15831944/AutoIME
 private static void BindCommandToDoc(AcadDocument doc)
 {
     UnbindCommandToDoc(doc);
     doc.CommandWillStart += CommandWillStart;
     doc.CommandEnded     += CommandEnded;
     doc.CommandCancelled += CommandCancelled;
     doc.CommandFailed    += CommandFailed;
 }
コード例 #14
0
        static public void SpaceOnAttributeName()
        {
            // Получение текущего документа и базы данных
            App.Document acDoc   = App.Application.DocumentManager.MdiActiveDocument;
            Db.Database  acCurDb = acDoc.Database;
            Ed.Editor    acEd    = acDoc.Editor;

            // старт транзакции
            using (Db.Transaction acTrans = acCurDb.TransactionManager.StartOpenCloseTransaction())
            {
                Db.TypedValue[] acTypValAr = new Db.TypedValue[1];
                acTypValAr.SetValue(new Db.TypedValue((int)Db.DxfCode.Start, "INSERT"), 0);
                Ed.SelectionFilter acSelFtr = new Ed.SelectionFilter(acTypValAr);

                Ed.PromptSelectionResult acSSPrompt = acDoc.Editor.GetSelection(acSelFtr);
                if (acSSPrompt.Status == Ed.PromptStatus.OK)
                {
                    Ed.SelectionSet acSSet = acSSPrompt.Value;
                    foreach (Ed.SelectedObject acSSObj in acSSet)
                    {
                        if (acSSObj != null)
                        {
                            if (acSSObj.ObjectId.ObjectClass.IsDerivedFrom(Rtm.RXClass.GetClass(typeof(Db.BlockReference))))
                            {
                                Db.BlockReference acEnt = acTrans.GetObject(acSSObj.ObjectId,
                                                                            Db.OpenMode.ForRead) as Db.BlockReference;

                                Db.BlockTableRecord blr = acTrans.GetObject(acEnt.BlockTableRecord,
                                                                            Db.OpenMode.ForRead) as Db.BlockTableRecord;
                                if (acEnt.IsDynamicBlock)
                                {
                                    blr = acTrans.GetObject(acEnt.DynamicBlockTableRecord,
                                                            Db.OpenMode.ForRead) as Db.BlockTableRecord;
                                }

                                if (blr.HasAttributeDefinitions)
                                {
                                    foreach (Db.ObjectId id in blr)
                                    {
                                        if (id.ObjectClass.IsDerivedFrom(Rtm.RXClass.GetClass(typeof(Db.AttributeDefinition))))
                                        {
                                            Db.AttributeDefinition acAttrRef = acTrans.GetObject(id,
                                                                                                 Db.OpenMode.ForWrite) as Db.AttributeDefinition;

                                            if (acAttrRef != null)
                                            {
                                                acAttrRef.Tag = acAttrRef.Tag.Replace('_', ' ');
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                acTrans.Commit();
            }
        }
コード例 #15
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();
        }
コード例 #16
0
        public static void ShowFrameMenu()
        {
            AdeskAppSvr.Document doc = AdeskAppSvr.Application.DocumentManager.MdiActiveDocument;
            doc.SendStringToExecute("UCS W ", false, false, true);//make current coordinate system to be WCS
            AdeskAppSvr.DocumentLock docLock = doc.LockDocument();
            DigitalSign mDigital             = new DigitalSign();

            AdeskAppSvr.Application.ShowModalDialog(mDigital);
            docLock.Dispose();
        }
コード例 #17
0
        /// <summary>
        /// show form
        /// </summary>
        /// <param name="Sender"></param>
        /// <param name="e"></param>
        public static void ShowFrame(Object Sender, EventArgs e)
        {
            AdeskAppSvr.Document doc = AdeskAppSvr.Application.DocumentManager.MdiActiveDocument;
            doc.SendStringToExecute("UCS W ", false, false, true);//make current coordinate system to be WCS
            AdeskAppSvr.DocumentLock docLock = doc.LockDocument();
            NewForm mDigital = new NewForm();

            AdeskAppSvr.Application.ShowModalDialog(mDigital);
            docLock.Dispose();
        }
コード例 #18
0
        public static void CheckForPickfirstSelection()
        {
            AcadApp.Document acDoc   = AcadApp.Application.DocumentManager.MdiActiveDocument;
            Database         acCurDb = acDoc.Database;

            Editor acDocEd = AcadApp.Application.DocumentManager.MdiActiveDocument.Editor;

            //// Get the PickFirst selection set获取PickFirst选择集

            //PromptSelectionResult acSSPrompt;
            //acSSPrompt = acDocEd.SelectImplied();
            //SelectionSet acSSet;

            //if (acSSPrompt.Status == PromptStatus.OK) // 如果提示状态OK,说明启动命令前选择了对象;
            //{
            //    acSSet = acSSPrompt.Value;
            //    AcadApp.Application.ShowAlertDialog("Number of objects in Pickfirst selection: " + acSSet.Count.ToString());
            //}
            //else
            //{
            //    AcadApp.Application.ShowAlertDialog("Number of objects in Pickfirst selection: 0");
            //}

            // 清空选择集????
            //  //提示选择屏幕上的对象并遍历选择集
            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                PromptSelectionResult acSSPrompt = acDoc.Editor.GetSelection();// 请求从图形区域选择对象

                // 如果提示状态OK,表示已选择对象
                if (acSSPrompt.Status == PromptStatus.OK)
                {
                    SelectionSet acSSet = acSSPrompt.Value;

                    // 遍历选择集内的对象
                    foreach (SelectedObject acSSObj in acSSet)
                    {
                        // 确认返回的是合法的SelectedObject对象

                        if (acSSObj != null)
                        {
                            // 以写打开所选对象

                            Entity acEnt = acTrans.GetObject(acSSObj.ObjectId, OpenMode.ForWrite) as Entity;

                            if (acEnt != null)
                            {
                                acEnt.ColorIndex = 3; // 将对象颜色修改为绿色
                            }
                        }
                    }
                    acTrans.Commit();
                }
            }
        }
コード例 #19
0
        public static void CrateExternalBlock()
        {
            Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

            PromptSelectionOptions optSel    = new PromptSelectionOptions();
            PromptSelectionResult  ProSelRes = ed.GetSelection(optSel);

            switch (ProSelRes.Status)
            {
            case PromptStatus.OK:
                //Set Block

                //Criate blockReference
                ObjectId objBlock = criarDefiniçãoDeBloco(ProSelRes.Value.GetObjectIds());
                Database db       = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;
                using (Transaction trans = db.TransactionManager.StartTransaction())
                {
                    try
                    {
                        Database dbAux = new Database(true, false);
                        dbAux.SaveAs("C:\\teste1.dwg", DwgVersion.Current);

                        Autodesk.AutoCAD.ApplicationServices.Document Doc = null;
                        Doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open("C:\\teste1.dwg", false);

                        ObjectIdCollection ids = new ObjectIdCollection();
                        ids.Add(objBlock);
                        using (DocumentLock dl = Doc.LockDocument())
                        {
                            IdMapping im = new IdMapping();
                            db.WblockCloneObjects(
                                ids,
                                Doc.Database.BlockTableId,
                                im,
                                DuplicateRecordCloning.MangleName,
                                false
                                );
                        }

                        Doc.CloseAndSave("C:\\teste1.dwg");
                    }
                    catch (System.Exception ex)
                    {
                        trans.Abort();

                        return;
                    }
                }
                break;

            case PromptStatus.Cancel:
                //Command Canceled
                break;
            }
        }
コード例 #20
0
        public void StepthroughBlockrecord()
        {
            AcadApp.Document doc = AcadApp.Application.DocumentManager.MdiActiveDocument;
            Database         d   = doc.Database;

            using (Transaction t = d.TransactionManager.StartTransaction())
            {
                doc.Editor.WriteMessage(d.TransactionManager.NumberOfActiveTransactions.ToString()); //活动事务的个数
                doc.Editor.WriteMessage("\n" + d.TransactionManager.TopTransaction.ToString());      //最上面的或者说最新的事务
                doc.Editor.WriteMessage("\n" + t.ToString());                                        //最上面的或者说最新的事务
                //在程序执行过程中,为了回滚所作的部分修改,可以将一个事务嵌套在另一个事务中

                BlockTable acbt = t.GetObject(d.BlockTableId, OpenMode.ForRead) as BlockTable;
                //BlockTableRecord acBlkTblRec = t.GetObject(acbt[BlockTableRecord.ModelSpace], OpenMode.ForRead) as BlockTableRecord;
                BlockTableRecord acBlkTblRec = t.GetObject(d.CurrentSpaceId, OpenMode.ForRead) as BlockTableRecord;

                // Step through the Block table record遍历块表记录
                foreach (ObjectId asObjId in acBlkTblRec)
                {
                    // doc.Editor.WriteMessage("\nDXF name: " + asObjId.ObjectClass.DxfName);
                    doc.Editor.WriteMessage("\nObjectID: " + asObjId.ToString());

                    doc.Editor.WriteMessage("\nHandle: " + asObjId.Handle.ToString());

                    doc.Editor.WriteMessage("\n");
                }
            }

            ////acbt.UpgradeOpen();升降级打开对象
            ////acbt.DowngradeOpen();

            //// 以读的方式打开图层表
            //LayerTable acLyrTbl = acTrans.GetObject(d.LayerTableId, OpenMode.ForRead) as LayerTable;
            ////遍历图层并将图层名以‘Door’开头的图层升级为写打开方式;
            //foreach (ObjectId acObjId in acLyrTbl)
            //{
            //    LayerTableRecord acLyrTblRec = acTrans.GetObject(acObjId, OpenMode.ForRead) as LayerTableRecord;

            //    //检查图层名是否以‘Door’开头

            //    if (acLyrTblRec.Name.StartsWith("Door", StringComparison.OrdinalIgnoreCase) == true)
            //    {

            //        //检查是否为当前层,是则不冻结  // Check to see if the layer is current, if so then do not freeze it

            //        if (acLyrTblRec.ObjectId != d.Clayer)
            //        {
            //            acLyrTblRec.UpgradeOpen();  // Change from read to write mode升级打开方式
            //            acLyrTblRec.IsFrozen = true;    // Freeze the layer冻结图层
            //        }
            //    }
            //}

            //acTrans.Commit(); //提交修改并关闭事务
        }  //遍历块表记录 ++ 升降级打开对象
コード例 #21
0
ファイル: Model.cs プロジェクト: gispda/InterCad
        /// <summary>
        /// Открытие диалогового окна цветовой палитры для изменения свойства Color объекта.
        /// </summary>
        public void ChangeColorByDlg()
        {
            AcadAS.Document doc = AcadAS.Application.DocumentManager.MdiActiveDocument;
            Editor          ed  = doc.Editor;

            Autodesk.AutoCAD.Windows.ColorDialog dlg = new Autodesk.AutoCAD.Windows.ColorDialog();
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                Color = dlg.Color;
            }
        }
コード例 #22
0
 private void HideButton_Click(object sender, EventArgs e)
 {
     Parent.Parent.Parent.Hide(); // this is not mandatory
     ApplicationServices.Document      document = ApplicationServices.Application.DocumentManager.MdiActiveDocument;
     EditorInput.PromptSelectionResult promptSelectionResult = document.Editor.GetSelection();
     if (promptSelectionResult.Status == EditorInput.PromptStatus.OK)
     {
         document.Editor.WriteMessage(promptSelectionResult.Value.Count.ToString() + "\n");
     }
     Parent.Parent.Parent.Show(); // this is mandatory if the form have been hidden
 }
コード例 #23
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);
            }
        }
コード例 #24
0
ファイル: EventsWatcher.cs プロジェクト: 15831944/EM
        public static void documentToBeDestroyed(ref Autodesk.AutoCAD.ApplicationServices.Document doc)
        {
            if (m_docWatcher != null)
            {
                m_docWatcher.removeDoc(ref doc);
            }

            if (m_dbWatcher != null)
            {
                Database db = doc.Database;
                m_dbWatcher.removeDb(ref db);
            }
        }
コード例 #25
0
ファイル: Menu.cs プロジェクト: zhengjian211/DWGLib
        private void LoadCusCUI(string path)
        {
            Autodesk.AutoCAD.ApplicationServices.Document doc = Application.DocumentManager.MdiActiveDocument;

            object oldCmdEcho = Application.GetSystemVariable("CMDECHO");
            object oldFileDia = Application.GetSystemVariable("FILEDIA");

            Application.SetSystemVariable("CMDECHO", 1);
            Application.SetSystemVariable("FILEDIA", 0);
            string LoadCUICommand = "cuiload " + path + " filedia 1";

            doc.SendStringToExecute(LoadCUICommand, true, false, true);
        }
コード例 #26
0
ファイル: Form1.cs プロジェクト: ursc/ftext
        public Form1(ACAD.Document doc)
        {
            InitializeComponent();

            textFinder = new TextFinder(doc);

            myData = MyData.LoadMyData("ftext.bin");
            scaleTrackBar.Value = myData.scale;
            foreach (var find in myData.finds)
            {
                historyDataGridView.Rows.Add(find);
            }
        }
コード例 #27
0
        private void ModifyDwgs(Dictionary <String, DataRow> dict)
        {
            try
            {
                foreach (var entry in dict)
                {
                    if (!File.Exists(entry.Key))
                    {
                        continue;                            //文件不存在则跳过
                    }
#if R18
                    Acad.Document doc = Acad.Application.DocumentManager.Open(entry.Key, true);
#elif R19
                    Acad.Document doc = Acad.DocumentCollectionExtension.Open(Acad.Application.DocumentManager, entry.Key, true, "");
#elif R20
                    Acad.Document doc = Acad.DocumentCollectionExtension.Open(Acad.Application.DocumentManager, entry.Key, true, "");
#endif
                    //Thread.Sleep(500);
                    bool drawMarkLine = XmlUtil.getXmlValue("markArea", "value") == "true";
                    var  dft          = new DwgFrameTools(doc, drawMarkLine);

                    Dictionary <DwgInfoTypeEnum, String> info = new Dictionary <DwgInfoTypeEnum, string>();

                    info.Add(DwgInfoTypeEnum.图号, entry.Value["图号"] as string);
                    info.Add(DwgInfoTypeEnum.称, entry.Value["名称"] as string);
                    info.Add(DwgInfoTypeEnum.版本, entry.Value["版本"] as string);
                    info.Add(DwgInfoTypeEnum.比例, entry.Value["比例"] as string);
                    info.Add(DwgInfoTypeEnum.密级, entry.Value["密级"] as string);
                    info.Add(DwgInfoTypeEnum.总张数, (entry.Value["张数"] as string).Split('-')[0]);
                    info.Add(DwgInfoTypeEnum.数, (entry.Value["张数"] as string).Split('-')[1]);
                    info.Add(DwgInfoTypeEnum.重量, entry.Value["重量"] as string);
                    dft.UpdateDwgInfo(info);
                    //doc.CloseAndSave(doc.Name);
                    doc.Database.SaveAs(doc.Name, false, AcDb.DwgVersion.Current, doc.Database.SecurityParameters);

#if R18
                    doc.CloseAndDiscard();
#elif R19
                    Acad.DocumentExtension.CloseAndDiscard(doc);
#elif R20
                    Acad.DocumentExtension.CloseAndDiscard(doc);
#endif

                    //doc.CloseAndDiscard();
                }
            }
            catch
            {
                throw;
            }
        }
コード例 #28
0
        public static ObjectId criarDefiniçãoDeBloco(ObjectId[] objIds)
        {
            string   nomeBloco = "Teste1";
            Database db        = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                try
                {
                    Autodesk.AutoCAD.ApplicationServices.Document Doc = null;
                    Doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
                    using (DocumentLock dl = Doc.LockDocument())
                    {
                        //abrir tabela de blocos
                        BlockTable bt = trans.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;

                        //verificar se o bloco já existe
                        if (bt.Has(nomeBloco))
                        {
                            return(bt[nomeBloco]);
                        }
                        BlockTableRecord novoBloco = new BlockTableRecord();
                        novoBloco.Name = nomeBloco;

                        bt.UpgradeOpen();
                        bt.Add(novoBloco);

                        trans.AddNewlyCreatedDBObject(novoBloco, true);

                        foreach (ObjectId objId in objIds)
                        {
                            DBObject obj      = trans.GetObject(objId, OpenMode.ForRead);
                            Entity   ent      = (Entity)obj;
                            Entity   entClone = ent.Clone() as Entity;
                            novoBloco.AppendEntity(entClone);
                            trans.AddNewlyCreatedDBObject(entClone, true);
                        }

                        trans.Commit();

                        return(novoBloco.ObjectId);
                    }
                }
                catch (System.Exception ex)
                {
                    trans.Abort();

                    return(ObjectId.Null);
                }
            }
        }
コード例 #29
0
 public ProfileView SetBandSetStyle(LabelStyles.ProfileViews.ProfileViewBandSet bandSet)
 {
     Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
     Autodesk.AutoCAD.DatabaseServices.Database    db  = doc.Database;
     using (Autodesk.AutoCAD.DatabaseServices.Transaction trans = db.TransactionManager.StartTransaction())
     {
         Autodesk.Civil.DatabaseServices.ProfileView entity = (Autodesk.Civil.DatabaseServices.ProfileView)trans.GetObject(_curCivilObject.ObjectId, OpenMode.ForWrite);
         if (!entity.IsErased)
         {
             entity.Bands.ImportBandSetStyle(bandSet.InternalObjectId);
         }
         trans.Commit();
     }
     return(this);
 }
コード例 #30
0
        public void CreateTable()
        {
            LayerHelper.CreateAndAssignALayer("TABLE");
            ac.Document doc = ac.Application.DocumentManager.MdiActiveDocument;
            Database    db  = doc.Database;
            //GET THE ID HERE..... ?
            string   url  = string.Format("{0}/#/{1}", Goodie.hostName, uriInit);
            JsonData data = OpeningBrowser(url);

            if (data != null)
            {
                EditOrCreateTable(data, new Point3d(-1000, -1000, -1000));
            }
            return;
        }