Beispiel #1
0
        public Dictionary <string, ObjectId> GetBlockReferenceFromBtIds(PilihanDrawing mode)
        {
            Dictionary <string, ObjectId> newList = new Dictionary <string, ObjectId>();
            ObjectIdCollection            objIds  = new ObjectIdCollection();

            switch (mode)
            {
            case PilihanDrawing.CurrentDrawing:
                break;

            case PilihanDrawing.PickFromDrawing:
                break;

            case PilihanDrawing.ExternalDrawing:
                foreach (KeyValuePair <string, ObjectId> btName in GetBT_IDs)
                {
                    for (int i1 = 0; i1 < DBFiles.Count; i1++)
                    {
                        acDbs = new Database(false, true);
                        try
                        {
                            acDbs.ReadDwgFile(ListFileDwgs[i1].FullName, FileShare.Read, false, "");
                        }
                        catch (Autodesk.AutoCAD.Runtime.Exception acExep)
                        {
                            throw new Autodesk.AutoCAD.Runtime.Exception(ErrorStatus.FilerError, acExep.Message);
                        }
                        using (Transaction tr = acDbs.TransactionManager.StartTransaction())
                        {
                            BlockTable       bt  = acDbs.BlockTableId.GetObject(OpenMode.ForRead) as BlockTable;
                            BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[btName.Key], OpenMode.ForRead);
                            objIds = btr.GetBlockReferenceIds(true, false);
                            foreach (ObjectId id in objIds)
                            {
                                BlockReference bRef = (BlockReference)tr.GetObject(id, OpenMode.ForRead);
                                newList.Add(btr.Name + id, id);
                            }
                        }
                    }
                }
                break;

            default:
                break;
            }
            return(newList);
        }
Beispiel #2
0
        public KoleksiBlok(PilihanDrawing mode)
        {
            switch (mode)
            {
            case PilihanDrawing.CurrentDrawing:
                acDoc = AcAp.DocumentManager.MdiActiveDocument;
                acDbs = acDoc.Database;
                break;

            case PilihanDrawing.PickFromDrawing:
                break;

            case PilihanDrawing.ExternalDrawing:
                break;

            default:
                break;
            }
        }
Beispiel #3
0
 public KoleksiBlok(PilihanDrawing mode, string[] FileNames)
 {
     if (mode == PilihanDrawing.ExternalDrawing)
     {
         ListFileDwgs = new List <FileInfo>();
         dbFiles      = new List <Database>();
         for (int i = 0; i < FileNames.Length; i++)
         {
             ListFileDwgs.Add(new FileInfo(FileNames[i]));
             dbFiles.Add(new Database(false, true));
             //try
             //{
             //    dbFiles[i].ReadDwgFile(ListFileDwgs[i].FullName, FileShare.Read, false, "");
             //}
             //catch (Autodesk.AutoCAD.Runtime.Exception acExep)
             //{
             //    throw new Autodesk.AutoCAD.Runtime.Exception(ErrorStatus.FilerError, acExep.Message);
             //}
         }
     }
 }
Beispiel #4
0
        public Dictionary <string, ObjectId> GetDataBlokAttributes(PilihanDrawing mode)
        {
            Dictionary <string, ObjectId> newList = new Dictionary <string, ObjectId>();

            switch (mode)
            {
            case PilihanDrawing.CurrentDrawing:
                break;

            case PilihanDrawing.PickFromDrawing:
                break;

            case PilihanDrawing.ExternalDrawing:
                break;

            default:
                break;
            }

            return(newList);
        }
Beispiel #5
0
        public Dictionary <string, ObjectId> GetBlokTableIdFromDrawing(PilihanDrawing mode)
        {
            Dictionary <string, ObjectId> newList = new Dictionary <string, ObjectId>();

            getbtId = new Dictionary <string, ObjectId>();
            switch (mode)
            {
            case PilihanDrawing.CurrentDrawing:
                acDoc = AcAp.DocumentManager.MdiActiveDocument;
                acDbs = acDoc.Database;

                using (Transaction tr = acDbs.TransactionManager.StartTransaction())
                {
                    BlockTable bt = (BlockTable)acDbs.BlockTableId.GetObject(OpenMode.ForRead) as BlockTable;
                    foreach (ObjectId btId in bt)
                    {
                        BlockTableRecord btr = (BlockTableRecord)tr.GetObject(btId, OpenMode.ForRead);
                        if (btr.HasAttributeDefinitions)
                        {
                            if (newList.Keys.Contains(btr.Name))
                            {
                                continue;
                            }
                            newList.Add(btr.Name, btId);
                            getbtId.Add(btr.Name, btId);
                        }
                    }
                }

                break;

            case PilihanDrawing.PickFromDrawing:
                break;

            case PilihanDrawing.ExternalDrawing:
                for (int i = 0; i < DBFiles.Count; i++)
                {
                    acDbs = new Database(false, true);
                    try
                    {
                        acDbs.ReadDwgFile(ListFileDwgs[i].FullName, FileShare.Read, false, "");
                    }
                    catch (Autodesk.AutoCAD.Runtime.Exception acExep)
                    {
                        throw new Autodesk.AutoCAD.Runtime.Exception(ErrorStatus.FilerError, acExep.Message);
                    }
                    using (Transaction tr = acDbs.TransactionManager.StartTransaction())
                    {
                        BlockTable bt = (BlockTable)acDbs.BlockTableId.GetObject(OpenMode.ForRead) as BlockTable;
                        foreach (ObjectId btId in bt)
                        {
                            BlockTableRecord btr = (BlockTableRecord)btId.GetObject(OpenMode.ForRead);
                            if (btr.HasAttributeDefinitions)
                            {
                                if (newList.Keys.Contains(btr.Name))
                                {
                                    continue;
                                }
                                newList.Add(btr.Name, btId);
                                getbtId.Add(btr.Name, btId);
                            }
                        }
                        //tr.Commit();
                    }
                }
                break;

            default:
                break;
            }
            return(newList);
        }
Beispiel #6
0
        /// <summary>
        /// Get Block Attributes From Drawing
        /// </summary>
        /// <param name="mode">Select All From Current Drawing, Pick From Current Drawing, Select All From External Drawing</param>
        public void GetBlokByDrawing(PilihanDrawing mode)
        {
            switch (mode)
            {
            case PilihanDrawing.CurrentDrawing:
                acDoc = AcAp.DocumentManager.MdiActiveDocument;
                acDbs = acDoc.Database;
                break;

            case PilihanDrawing.PickFromDrawing:

                break;

            case PilihanDrawing.ExternalDrawing:
                for (int i = 0; i < (FileDrawings.Count); i++)
                {
                    acDbs = new Database(false, true);
                    string file = FileDrawings[i].FullName;
                    try
                    {
                        acDbs.ReadDwgFile(file, FileShare.Read, false, "");
                    }
                    catch (Autodesk.AutoCAD.Runtime.Exception AcEx)
                    {
                        throw new Autodesk.AutoCAD.Runtime.Exception(ErrorStatus.CantOpenFile, "Error Loading File" + "\n" + AcEx.Message);
                    }
                    using (Transaction tr = acDbs.TransactionManager.StartTransaction())
                    {
                        BlockTable bt = (BlockTable)acDbs.BlockTableId.GetObject(OpenMode.ForRead) as BlockTable;
                        foreach (ObjectId tbId in bt)
                        {
                            BlockTableRecord btr = (BlockTableRecord)tbId.GetObject(OpenMode.ForRead);
                            if (btr.IsAnonymous)
                            {
                                continue;
                            }
                            if (btr.GetBlockReferenceIds(true, false).Count > 0)
                            {
                                if (btr.HasAttributeDefinitions)
                                {
                                    KoleksiBlokTableId.Add(btr.Name, tbId);
                                    ObjectIdCollection ObjRefIds = btr.GetBlockReferenceIds(true, false);
                                    foreach (ObjectId ObjId in ObjRefIds)
                                    {
                                        BlockReference bRef = (BlockReference)tr.GetObject(ObjId, OpenMode.ForRead);
                                        KoleksiBlockReferenceIds.Add(bRef.Name + bRef.Id, ObjId);
                                        foreach (ObjectId AtrId in bRef.AttributeCollection)
                                        {
                                            AttributeReference AttRef = (AttributeReference)tr.GetObject(AtrId, OpenMode.ForRead);
                                            try
                                            {
                                                if (KoleksiAtributBlokRefs.Keys.Contains(AttRef.Tag))
                                                {
                                                    continue;
                                                }
                                                KoleksiAtributBlokRefs.Add(AttRef.Tag, AttRef.Id);
                                            }
                                            catch
                                            {
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                break;

            default:
                break;
            }
        }