コード例 #1
0
ファイル: Test1.cs プロジェクト: caobinh92/Autocad
        public static void UserPlot(Document acDoc)
        {
            //Document acDoc = Application.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;
            Editor   acDocEd = acDoc.Editor;

            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                DBObjectCollection acBlkTblRecSpcColl = GetBlockTableRecordSpaceCollection(acDoc);
                BlockTable         acBlkTbl           = (BlockTable)acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead);
                if (acBlkRef == null)
                {
                    acBlkRef    = GetBlockReference(acDoc, "Pick a title block", "You must pick a title block!");
                    acBlkTblRec = (BlockTableRecord)acTrans.GetObject(acBlkRef.BlockTableRecord, OpenMode.ForRead);
                    AttributeID = GetAttributeID(acDoc, acBlkTblRec);
                    Point3d OriginBottomPoint = GetPoint3dFromPrompt(acDoc, "Pick first point");
                    Point3d OriginTopPoint    = GetPoint3dFromPrompt(acDoc, "Pick second point");
                    InsertPointToBottomPoint = acBlkRef.Position.GetVectorTo(OriginBottomPoint);
                    InsertPointToTopPoint    = acBlkRef.Position.GetVectorTo(OriginTopPoint);
                    acScl3d = acBlkRef.ScaleFactors;
                    string[] acPlDevCanMed = GetPlotDeviceAndCanonicalMediaName();
                    acPlDev = acPlDevCanMed[0]; acCanMed = acPlDevCanMed[1];

                    acBlkTblRec = (BlockTableRecord)acBlkTblRec.Clone();
                    acBlkRef    = (BlockReference)acBlkRef.Clone();
                }
                foreach (DBObject acDbBlkTblRec in acBlkTblRecSpcColl)
                {
                    BlockTableRecord acBlkTblRecSpc = (BlockTableRecord)acDbBlkTblRec;
                    foreach (ObjectId acObjId in acBlkTblRecSpc)
                    {
                        Entity acEnt = (Entity)acTrans.GetObject(acObjId, OpenMode.ForRead);
                        if (acEnt is BlockReference)
                        {
                            BlockReference   acBlkRef1    = (BlockReference)acEnt;
                            BlockTableRecord acBlkTblRec1 = (BlockTableRecord)acTrans.GetObject(acBlkRef1.BlockTableRecord, OpenMode.ForRead);
                            if (acBlkTblRec1.Name.Equals(acBlkTblRec.Name))
                            {
                                Extents2d acExt2d = GetPlotArea(acBlkRef1, acScl3d, InsertPointToBottomPoint, InsertPointToTopPoint);
                                string    path    = Path.Combine(DirectoryFolder(acDoc.Database.OriginalFileName), Path.GetFileName(GetAttributeString(acDoc, acBlkRef1, AttributeID)));
                                InKhungTen(acBlkTblRecSpc, acExt2d, path, acPlDev, acCanMed);
                            }
                        }
                    }
                }
                acTrans.Commit();
            }
        }
コード例 #2
0
ファイル: Test1.cs プロジェクト: caobinh92/Autocad
        public static void b()
        {
            DocumentCollection acDocMgr = Application.DocumentManager;
            Document           acDoc    = acDocMgr.MdiActiveDocument;
            Database           acCurDb  = acDocMgr.MdiActiveDocument.Database;
            Editor             acDocEd  = acDocMgr.MdiActiveDocument.Editor;

            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                DBObjectCollection acBlkTblRecSpcColl = GetBlockTableRecordSpaceCollection(acDoc);
                BlockTable         acBlkTbl           = (BlockTable)acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead);
                if (acBlkRef == null)
                {
                    acBlkRef    = GetBlockReference(acDoc, "Pick a title block", "You must pick a title block!");
                    acBlkTblRec = (BlockTableRecord)acTrans.GetObject(acBlkRef.BlockTableRecord, OpenMode.ForRead);
                    AttributeID = GetAttributeID(acDoc, acBlkTblRec);
                    Point3d OriginBottomPoint = GetPoint3dFromPrompt(acDoc, "Pick first point");
                    Point3d OriginTopPoint    = GetPoint3dFromPrompt(acDoc, "Pick second point");
                    InsertPointToBottomPoint = acBlkRef.Position.GetVectorTo(OriginBottomPoint);
                    InsertPointToTopPoint    = acBlkRef.Position.GetVectorTo(OriginTopPoint);
                    acScl3d = acBlkRef.ScaleFactors;
                    string[] acPlDevCanMed = GetPlotDeviceAndCanonicalMediaName();
                    acPlDev     = acPlDevCanMed[0]; acCanMed = acPlDevCanMed[1];
                    acBlkTblRec = (BlockTableRecord)acBlkTblRec.Clone();
                    acBlkRef    = (BlockReference)acBlkRef.Clone();
                }
            }
            foreach (Document acDoc1 in acDocMgr)
            {
                acDocMgr.MdiActiveDocument = acDoc1;
                using (DocumentLock acDocLck1 = acDoc1.LockDocument())
                {
                    UserPlot2(acDoc1);
                }
            }
        }