
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have a class to reloadimages from a source. I have it working fine if the code is executed from the Commad class. I have moved the code into it's own class, and following the adivce here (https://forums.autodesk.com/t5/revit-api/call-class-from-windows-form/m-p/5984297/highlight/true#M13... I am passing the ExternalCommandData through a called Form, and then again to the called class. The called class is being run as a backgroundWorker, and in it when I try to access the UIApplication, Revit crashes. As I step through the code, whenever I try to inspect the UIApplication it results in a crash. The ExternalCommandData looks to pass fine, I just can't get a UIApplication out of it.
This is the code to call the Form. The ExternalCommandData is commandData.
using (Form1 thisForm = new Form1(path, commandData)) { thisForm.ShowDialog(); if (thisForm.DialogResult == System.Windows.Forms.DialogResult.Cancel) { return Result.Cancelled; } if (thisForm.DialogResult == System.Windows.Forms.DialogResult.OK) { path = thisForm.WordDocPath; } }
This is the begining of the code to call the class inside the Form
public class ReplaceImages
{
private void backgroundWorker2_Dowork(object sender, DoWorkEventArgs e) { int pageCount = (int)e.Argument; e.Result = replace1.replaceImages(commandData, WordDocPath, pageCount); }
And then inside the actual class to replace the images
public class ReplaceImages { public delegate void ProgressUpdate(int value); public event ProgressUpdate OnProgressUpdate; public ExternalCommandData commandData; public Result replaceImages(ExternalCommandData commandDatax, string WordDocPath, int pageCount) { commandData = commandDatax; UIApplication uiApp = commandData.Application; UIDocument uidoc = uiApp.ActiveUIDocument; Application app = uiApp.Application; Document doc = uidoc.Document; FilteredElementCollector col = new FilteredElementCollector(uiApp.ActiveUIDocument.Document).OfCategory(BuiltInCategory.OST_RasterImages); string imagePath = Path.GetDirectoryName(WordDocPath); imagePath = imagePath + @"\Sheet Spec (Images)\"; int imageNumber = 1; foreach (Element e in col)
Any Idea why I am unable to get a functioning UIApplication in the ReplaceImage class?
Solved! Go to Solution.