Website: http://au.autodesk.com/speaker-resource-center/call-for-proposals/voting
To find my classes use the following (or search by name):
IList<FailureMessage> warnings = doc.GetWarnings();
public void ExportWarningsToExcel() { // make sure to add a reference to Excel Object Library // put the following (minus the // into your using statements) // using xls = Microsoft.Office.Interop.Excel; // using System.Reflection; // create a new Excel connection xls.Application xlApp = new xls.Application(); // make sure you have access to Excel if (null == xlApp) { TaskDialog.Show("Error", "Failed to start or access Excel"); return; } // get the current model Document doc = this.ActiveUIDocument.Document; // get a list of all the model's warnings IList<FailureMessage> warnings = doc.GetWarnings(); try { // show the Excel window xlApp.Visible = true; // create a new Workbook in Excel xls.Workbook workbook = xlApp.Workbooks.Add(Missing.Value); // create a new Worksheet in Excel xls.Worksheet worksheet = (xls.Worksheet)workbook.Worksheets.Item[1]; // name the Worksheet with the model name worksheet.Name = doc.Title; // create a header row worksheet.Cells[1,1] = "Warning Description"; worksheet.Cells[1,2] = "Elements"; // count the number of warnings int numWarnings = 0; // start on row 2 for warnings int row = 2; // loop through each warning foreach (FailureMessage fmsg in warnings) { // add the warning desciption to cell in Excel worksheet.Cells[row, 1] = fmsg.GetDescriptionText(); // create a string to hold element info string elements = ""; // loop through the element ids foreach (ElementId eid in fmsg.GetFailingElements()) { // get the element Element e = doc.GetElement(eid); // add the element category elements += e.Category.Name + " : "; // some elements fail when getting their family type, so skip getting type if it fails try { // get the element family type elements += e.LookupParameter("Family").AsValueString() + " : "; } catch { } // add the element name elements += e.Name + " : "; // add the element id elements += "id " + eid.ToString() + System.Environment.NewLine + System.Environment.NewLine; } // add elements to cell in Excel worksheet.Cells[row, 2] = elements; // go to next row to Excel ++row; // increment number of warnings numWarnings++; } // expand columns to fit text xls.Range col1 = worksheet.get_Range("A1", Missing.Value); xls.Range col2 = worksheet.get_Range("B1", Missing.Value); col1.EntireColumn.ColumnWidth = 70; col1.EntireColumn.WrapText = true; col2.EntireColumn.ColumnWidth = 25; // show dialog for results TaskDialog.Show("Success", "Exported " + numWarnings.ToString() + " warnings to Excel!!!"); } catch (Exception ex) { TaskDialog.Show("Error", "Something bad happened!!!" + System.Environment.NewLine + System.Environment.NewLine + ex.Message); } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | public void SheetRevisions() { Document doc = this.ActiveUIDocument.Document; using (Transaction t = new Transaction(doc, "Revisions on Sheet")) { t.Start(); // loop through all the sheets in the model foreach (ViewSheet vs in new FilteredElementCollector(doc).OfClass(typeof(ViewSheet))) { // get a list of all the Revision Ids for this sheet IList<ElementId> revIds = vs.GetAllRevisionIds(); // if at least 1 Revision, continue if (revIds.Count > 0) { // loop through each of the Revision Ids foreach (ElementId eid in revIds) { // get the actual Revision element Element elem = doc.GetElement(eid); Revision rev = elem as Revision; // add an X to the parameter named "Seq #" vs.LookupParameter("Seq " + rev.SequenceNumber.ToString()).Set("X"); } } } t.Commit(); } } |
public void UpdateLeaders()
{
UIDocument uidoc = this.ActiveUIDocument;
Document doc = uidoc.Document;
// create a collection of all the Arrowhead types
ElementId id = new ElementId(BuiltInParameter.ALL_MODEL_FAMILY_NAME);
ParameterValueProvider provider = new ParameterValueProvider(id);
FilterStringRuleEvaluator evaluator = new FilterStringEquals();
FilterRule rule = new FilterStringRule(provider, evaluator, "Arrowhead", false);
ElementParameterFilter filter = new ElementParameterFilter(rule);
FilteredElementCollector collector2 = new FilteredElementCollector(doc).OfClass(typeof(ElementType)).WherePasses(filter);
ElementId arrowheadId = null;
// loop through the collection of Arrowhead types and get the Id of a specific one
foreach(ElementId eid in collector2.ToElementIds())
{
if(doc.GetElement(eid).Name == "Arrow Filled 30 Degree") //change the name to the arrowhead type you want to use
{
arrowheadId = eid;
}
}
// create a collection of all families
List<Family> families = new List<Family>(new FilteredElementCollector(doc).OfClass(typeof(Family)).Cast<Family>());
using(Transaction t = new Transaction(doc, "Update Leaders"))
{
t.Start();
// loop through all families and get their types
foreach(Family f in families)
{
FamilySymbolSet symbols = f.Symbols;
List<FamilySymbol> symbols2 = new List<FamilySymbol>(symbols.Cast<FamilySymbol>());
// loop through the family types and try switching the parameter Leader Arrowhead to the one chosen above
// if the type doesn't have this parameter it will skip to the next family type
foreach(FamilySymbol fs in symbols2)
{
try
{
fs.get_Parameter(BuiltInParameter.LEADER_ARROWHEAD).Set(arrowheadId);
}
catch
{
}
}
}
t.Commit();
}
}