Esempio n. 1
0
        private static void CopyItems(ref ArrayList LIST, string sm, string spm)
        {
            double   DY      = 0; //определя позицията за вмъкване
            Document Doc     = Application.DocumentManager.MdiActiveDocument;
            Database Db      = Application.DocumentManager.MdiActiveDocument.Database;
            string   oldSTR  = ""; //ползва се при сепарирането пази предишнч резултат от маската с което се сравнява
            string   oldSTRR = "";
            int      counter = 0;  //брой за да се отчете последния елемент и да има запис без резултат от сравняване

            foreach (DynamicBlocksData dstr in LIST)
            {
                #region SEPARATE
                try
                {
                    string str1  = "";
                    string str11 = "";
                    string pathh = dstr.FileName.Remove(dstr.FileName.LastIndexOf('\\') + 1);
                    for (int i = 0; i < dstr.arr.Length; i++)
                    {
                        str1  += dstr.arr[i];
                        str11 += dstr.ARRR[i]; str11 += "_";
                        if (str1.Length > 0)
                        {
                            if (str1[str1.Length - 1] != '_')
                            {
                                str1 += "_";
                            }
                        }
                    }
                    if (counter == 0)
                    {
                        oldSTR  = str1;
                        oldSTRR = str11;
                    }
                    else
                    {
                        if ((oldSTR != str1) || (counter == (LIST.Count - 1)))
                        {
                            if (spm == "Together")
                            {
                                if (counter != (LIST.Count - 1))
                                {
                                    DY += 200;
                                }
                            }
                            else
                            {
                                string str2 = oldSTR.TrimEnd('_');
                                if ((str2 == "") || (str2 == " ") || (str2 == "  "))
                                {
                                    str2 = "OTHER_" + counter.ToString();
                                }
                                str2 = pathh + str2 + ".dwg";
                                DocumentLock locch = Doc.LockDocument();
                                using (locch)
                                {
                                    Db.SaveAs(str2, DwgVersion.Current);
                                }
                                if (counter != (LIST.Count - 1))
                                {
                                    EraseAll();
                                    DY = 0;
                                }
                            }
                            oldSTR  = str1;
                            oldSTRR = str11;
                        }
                    }
                }
                catch
                {
                    MessageBox.Show("Separate ERROR !");
                }
                #endregion

                ObjectIdCollection acObjIdColl = new ObjectIdCollection();
                OpenNewDocument(dstr.FileName);
                Document DocO = Application.DocumentManager.MdiActiveDocument;
                Database DbO  = Application.DocumentManager.MdiActiveDocument.Database;
                Editor   EdO  = Application.DocumentManager.MdiActiveDocument.Editor;
                Point3d  minP = new Point3d(dstr.Pos.X - 1, dstr.Pos.Y - 1, 0);
                Point3d  maxP = new Point3d(dstr.Pos.X + dstr.xD1 + 1, dstr.Pos.Y + dstr.yD1 + 1, 0);

                PromptSelectionResult prrr = null;
                if (sm == "Window")
                {
                    prrr = EdO.SelectWindow(minP, maxP);
                }
                else
                {
                    Point3d           minP1 = new Point3d(dstr.Pos.X + dstr.xD1 + 0.2, dstr.Pos.Y - 0.2, 0);
                    Point3d           maxP1 = new Point3d(dstr.Pos.X - 0.2, dstr.Pos.Y + dstr.yD1 + 0.2, 0);
                    Point3dCollection pcd   = new Point3dCollection();
                    pcd.Add(minP); pcd.Add(minP1); pcd.Add(maxP); pcd.Add(maxP1);
                    prrr = EdO.SelectCrossingPolygon(pcd);
                }
                if (prrr.Status == PromptStatus.OK)
                {
                    SelectionSet acSSett = prrr.Value;
                    acObjIdColl = new ObjectIdCollection(acSSett.GetObjectIds());
                }
                else
                {
                    continue;
                }
                DocumentLock locc = DocO.LockDocument();
                using (locc)
                {
                    using (Transaction trr = DocO.TransactionManager.StartTransaction())
                    {
                        foreach (ObjectId ID in acObjIdColl)
                        {
                            Entity   ent     = trr.GetObject(ID, OpenMode.ForWrite) as Entity;
                            Point3d  f       = new Point3d(0, 0, 0);
                            Point3d  t       = new Point3d(dstr.Pos.X, dstr.Pos.Y - DY, dstr.Pos.Z);
                            Vector3d acVec3d = t.GetVectorTo(f);
                            try
                            {
                                ent.TransformBy(Matrix3d.Displacement(acVec3d));
                            }
                            catch { MessageBox.Show("Transform Coordinates ERROR !"); }
                        }

                        trr.Commit();
                    }
                    using (Transaction trr = DocO.TransactionManager.StartTransaction())
                    {
                        foreach (ObjectId asObjId in acObjIdColl)
                        {
                            Entity     ent = trr.GetObject(asObjId, OpenMode.ForWrite) as Entity;
                            AcadEntity En  = (AcadEntity)ent.AcadObject;
                            if (En.ObjectName == "AcDbBlockReference")
                            {
                                BlockReference     bref = trr.GetObject(ent.ObjectId, OpenMode.ForRead) as BlockReference;
                                AcadBlockReference BR   = (AcadBlockReference)bref.AcadObject;
                                if ((BR.EffectiveName == "PSYMB_EXTRACT_DATA_2007") || (BR.EffectiveName == "PSYMB_EXTRACT_DATA"))
                                {
                                    foreach (ObjectId attId in bref.AttributeCollection)
                                    {
                                        AttributeReference attRef = (AttributeReference)trr.GetObject(attId, OpenMode.ForWrite) as AttributeReference;
                                        if (attRef.Tag == "DESCRIPTION")
                                        {
                                            {
                                                string[] path = dstr.FileName.Split('\\');
                                                try
                                                {
                                                    attRef.TextString = path[path.Length - 1] + "-" + attRef.TextString;
                                                }
                                                catch { }

                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        trr.Commit();
                    }
                }
                Application.DocumentManager.MdiActiveDocument = Doc;
                DocumentLock loc = Doc.LockDocument();
                using (loc)
                {
                    using (Transaction tr = Doc.TransactionManager.StartTransaction())
                    {
                        // Open the Block table for read
                        BlockTable acBlkTbl;
                        acBlkTbl = tr.GetObject(Db.BlockTableId, OpenMode.ForRead) as BlockTable;

                        // Open the Block table record Model space for write
                        BlockTableRecord acBlkTblRec;
                        acBlkTblRec = tr.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                        IdMapping acIdMap = new IdMapping();
                        Db.WblockCloneObjects(acObjIdColl, acBlkTblRec.ObjectId, acIdMap, DuplicateRecordCloning.Ignore, false);

                        tr.Commit();
                    }
                }
                //DocO.CloseAndDiscard();
                new UtilityClass().CloseActiveDocument(false);
                DY += (dstr.yD1 + 5);
                counter++;
            }
        }
Esempio n. 2
0
        private static void PreData(ref ArrayList list, string Name)
        {
            Document Doc = Application.DocumentManager.MdiActiveDocument;
            Database Db  = Application.DocumentManager.MdiActiveDocument.Database;

            using (Transaction tr = Doc.TransactionManager.StartTransaction())
            {
                BlockTable acBlkTbl;
                acBlkTbl = tr.GetObject(Db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord acBlkTblRec;
                acBlkTblRec = tr.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForRead) as BlockTableRecord;
                foreach (ObjectId asObjId in acBlkTblRec)
                {
                    Entity     ent = asObjId.GetObject(OpenMode.ForRead) as Entity;
                    AcadEntity En  = (AcadEntity)ent.AcadObject;
                    if (En.ObjectName == "AcDbBlockReference")
                    {
                        BlockReference     bref = tr.GetObject(ent.ObjectId, OpenMode.ForRead) as BlockReference;
                        AcadBlockReference BR   = (AcadBlockReference)bref.AcadObject;

                        if ((BR.EffectiveName == "PSYMB_EXTRACT_DATA_2007") || (BR.EffectiveName == "PSYMB_EXTRACT_DATA"))
                        {
                            DynamicBlocksData dstr = new DynamicBlocksData();
                            dstr.Pos  = bref.Position;
                            dstr.arr  = new string[Len];
                            dstr.ARRR = new string[Len];
                            for (int i = 0; i < Len; i++)
                            {
                                dstr.arr[i] = ""; dstr.ARRR[i] = "";
                            }
                            foreach (DynamicBlockReferenceProperty attId in bref.DynamicBlockReferencePropertyCollection)
                            {
                                if (attId.PropertyName == "X Distance1")
                                {
                                    dstr.xD1 = (double)attId.Value;
                                }
                                if (attId.PropertyName == "Y Distance1")
                                {
                                    dstr.yD1 = (double)attId.Value;
                                }
                            }

                            foreach (ObjectId attId in bref.AttributeCollection)
                            {
                                AttributeReference attRef = (AttributeReference)tr.GetObject(attId, OpenMode.ForWrite) as AttributeReference;
                                if (attRef.Tag == "DESCRIPTION")
                                {
                                    dstr.FileName = Name;
                                    string[] desarr = attRef.TextString.Split(',');
                                    for (int j = 0; j < desarr.Length; j++)
                                    {
                                        if (j < Len)
                                        {
                                            dstr.arr[j]  = desarr[j];
                                            dstr.arr[j]  = dstr.arr[j].TrimEnd(' ');
                                            dstr.arr[j]  = dstr.arr[j].TrimStart(' ');
                                            dstr.ARRR[j] = dstr.arr[j];
                                        }
                                        else
                                        {
                                            break;
                                        }
                                    }
                                    list.Add(dstr);
                                }
                            }
                        }
                    }
                }
            }
        }