예제 #1
0
        public void ChangeAttribute()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

            PromptStringOptions blocknameOptions = new PromptStringOptions("\nEnter Blockname")
            {
                AllowSpaces = true
            };
            PromptStringOptions LinkAttName_string = new PromptStringOptions("\nEnter name of attribute to check")
            {
                AllowSpaces = true
            };

            PromptStringOptions LinkAttValue_string = new PromptStringOptions("\nEnter value of attribute to check")
            {
                AllowSpaces = true
            };
            PromptStringOptions ChangeAttName_string = new PromptStringOptions("\nEnter name of attribute to change value")
            {
                AllowSpaces = true
            };

            PromptStringOptions ChangeAttValue_string = new PromptStringOptions("\nEnter new attribute value")
            {
                AllowSpaces = true
            };

            PromptResult blockname = ed.GetString(blocknameOptions);

            if (blockname.Status != PromptStatus.OK)
            {
                ed.WriteMessage("No string was provided\n");
                return;
            }

            PromptResult LinkAttName = ed.GetString(LinkAttName_string);

            if (LinkAttName.Status != PromptStatus.OK)
            {
                ed.WriteMessage("No string was provided\n");
                return;
            }

            PromptResult LinkAttValue = ed.GetString(LinkAttValue_string);

            if (LinkAttValue.Status != PromptStatus.OK)
            {
                ed.WriteMessage("No string was provided\n");
                return;
            }


            PromptResult ChangeAttName = ed.GetString(LinkAttValue_string);

            if (LinkAttValue.Status != PromptStatus.OK)
            {
                ed.WriteMessage("No string was provided\n");
                return;
            }

            PromptResult ChangeAttValue = ed.GetString(LinkAttValue_string);

            if (ChangeAttValue.Status != PromptStatus.OK)
            {
                ed.WriteMessage("No string was provided\n");
                return;
            }

            var UX = new UnloadXref();

            var drawingList = UX.getDrawingList();

            if (drawingList.Count == 0 || drawingList == null)
            {
                return;
            }

            var RV = new ReplaceValue();

            RV.ReplaceStringValue(drawingList, blockname.StringResult, LinkAttName.StringResult, LinkAttValue.StringResult, ChangeAttName.StringResult, ChangeAttValue.StringResult);
        }
예제 #2
0
        public List <string> addXrefSpecialized()
        {
            Document Doc = Application.DocumentManager.MdiActiveDocument;
            int      successfullDrawings = 0;

            var UX = new UnloadXref();

            var xRefFiles = getFilesToXrefList();

            if (xRefFiles.Count == 0 || xRefFiles == null)
            {
                return(null);
            }

            var DrawingList = UX.getDrawingList();

            if (DrawingList.Count == 0 || DrawingList == null)
            {
                return(null);
            }

            foreach (var drawing in DrawingList)
            {
                List <string> MatchingxRefFilesList = new List <string>();
                var           drawingFloor          = drawing.Split('-')[2].Trim();
                foreach (var file in xRefFiles)
                {
                    var fileName  = Path.GetFileNameWithoutExtension(file);
                    var fileFloor = fileName.Split('-')[1].Trim();

                    if (fileFloor == drawingFloor)
                    {
                        MatchingxRefFilesList.Add(file);
                    }
                }

                if (MatchingxRefFilesList.Count == 0)
                {
                    continue;
                }

                try
                {
                    Database xrefDb = new Database(false, true);
                    xrefDb.ReadDwgFile(drawing, FileShare.ReadWrite, false, "");


                    using (Transaction trx = xrefDb.TransactionManager.StartTransaction())
                    {
                        Doc.Editor.WriteMessage("Jobber med fil: " + Path.GetFileNameWithoutExtension(drawing));

                        xrefDb = createLayer(trx, xrefDb);

                        BlockTable       xrefBt = xrefDb.BlockTableId.GetObject(OpenMode.ForRead) as BlockTable;
                        BlockTableRecord btrMs  = xrefBt[BlockTableRecord.ModelSpace].GetObject(OpenMode.ForWrite) as BlockTableRecord;

                        foreach (var xref in MatchingxRefFilesList)
                        {
                            ObjectId xrefObjId = xrefDb.OverlayXref(xref, Path.GetFileNameWithoutExtension(xref));

                            BlockReference bref = new BlockReference(Point3d.Origin, xrefObjId);

                            btrMs.AppendEntity(bref);
                            trx.AddNewlyCreatedDBObject(bref, true);
                        }

                        xrefDb.CloseInput(true);
                        xrefDb.SaveAs(drawing, false, DwgVersion.Current, null);

                        trx.Commit();
                        successfullDrawings++;
                    }
                }
                catch (System.Exception)
                {
                }
                Doc.Editor.WriteMessage("\nAdded xref on " + successfullDrawings + " of " + DrawingList.Count);
            }

            return(DrawingList);
        }