示例#1
0
 public Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
 {
     appRevit = commandData.Application;
     ProcessManager pm = new ProcessManager();
     pm.ReloadImages();
     return Result.Succeeded;
 }
        public void ReloadImages()
        {
            ProcessManager pm = new ProcessManager();
            UIDocument uidoc = Reload.appRevit.ActiveUIDocument;
            Document doc = uidoc.Document;

            var rasterImages = new FilteredElementCollector(doc).OfClass(typeof(ImageType)).OfCategory(BuiltInCategory.OST_RasterImages).ToList();
            using (Transaction transaction = new Transaction(doc, "Обновление изображений"))
            {
                transaction.Start();
                foreach (ImageType imageElement in rasterImages)
                {
                    try
                    {
                        string fileName = Path.GetFileNameWithoutExtension(imageElement.Name);
                        int viewId = 0;
                        bool isValid = Int32.TryParse(fileName, out viewId);
                        if (!isValid) continue;
                        ElementId elId = new ElementId(viewId);
                        Element elView = doc.GetElement(elId);
                        pm.GetImageFromView(uidoc, (Autodesk.Revit.DB.View)elView, true);
                        imageElement.Reload();
                    }
                    catch { }
                }
                transaction.Commit();
            }
        }