Message 1 of 7
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Dear all,
I tried to batch open and close documents by API, and I write a sample as follow:
#region batch open and close UIApplication app = commandData.Application; UIDocument uidoc = app.ActiveUIDocument; Document doc = uidoc.Document; string CurFileName = doc.PathName; string path = Interaction.InputBox("please input path1"); string path2 = Interaction.InputBox("please input path2"); DirectoryInfo pathdir = new DirectoryInfo(path); int i = 0; foreach (FileInfo fi in pathdir.GetFiles()) { i = i + 1; UIDocument newUIdoc = app.OpenAndActivateDocument(fi.FullName); Document newdoc = newUIdoc.Document; doc.Close(false); doc.Dispose(); uidoc.Dispose(); Transaction transPara = new Transaction(newdoc); transPara.Start("openandsavetest"); FamilyManager FM = newdoc.FamilyManager; FamilyParameter paraHello = FM.AddParameter("Hello", BuiltInParameterGroup.INVALID, ParameterType.Text, true); //FM.Set(paraHello, "world"); transPara.Commit(); SaveAsOptions saveopt = new SaveAsOptions(); saveopt.Compact = true; saveopt.OverwriteExistingFile = true; newdoc.SaveAs(path2 + i.ToString() + ".rfa", saveopt); UIDocument tempuidoc1 = app.ActiveUIDocument; Document tempdoc1 = tempuidoc1.Document; newdoc.Dispose(); uidoc = app.OpenAndActivateDocument(CurFileName); doc = uidoc.Document; tempdoc1.Close(false); tempdoc1.Dispose(); tempuidoc1.Dispose(); } #endregion
There are about thousands of .rfa files need to be operated. When about 400th file running, Revit is crashed. -_-
Please help me, thank you!
Solved! Go to Solution.