- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
So I'm attempting to edit the Type Comments for all Framing objects currently in a model. When I attempt to display the information gathered, everything works beautifully. However, I'm stuck on how to make the actual change to the Type Comments field... Any thoughts? (Be gentle, I'm just wrapping my head around C#)
using System;
using System.Reflection;
using System.Windows.Media.Imaging;
using System.Collections;
using System.Collections.Generic;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.DB;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
namespace _TT_Revit_Tools
{
public class ttAddPanel : IExternalApplication
{
public Result OnStartup(UIControlledApplication application)
{
RibbonPanel ribbonPanel = application.CreateRibbonPanel("TT Revit Tools");
string thisAssemblyPath = Assembly.GetExecutingAssembly().Location;
PushButtonData buttonData = new PushButtonData("cmdDocument_Selection",
"Framing Type Comments",thisAssemblyPath,"_TT_Revit_Tools.Document_Selection");
PushButton pushbutton = ribbonPanel.AddItem(buttonData) as PushButton;
pushbutton.ToolTip = "Get Element ID of selected objects.";
return Result.Succeeded;
}
public Result OnShutdown(UIControlledApplication application)
{
return Result.Succeeded;
}
}
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.ReadOnly)]
public class Document_Selection : IExternalCommand
{
public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData,
ref string message, ElementSet elements)
{
try
{
UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document document = uidoc.Document;
ElementClassFilter familyInstanceFilter = new ElementClassFilter(typeof(FamilyInstance));
ElementCategoryFilter framingCategoryFilter = new ElementCategoryFilter(BuiltInCategory.OST_StructuralFraming);
LogicalAndFilter framingInstanceFilter = new LogicalAndFilter(familyInstanceFilter, framingCategoryFilter);
FilteredElementCollector collector = new FilteredElementCollector(document);
ICollection<ElementId> framing = collector.WherePasses(framingInstanceFilter).ToElementIds();
foreach (ElementId id in framing)
{
//Obtain Shape
string name = document.GetElement(id).Name;
string shape = name.Substring(0, name.IndexOf("X"));
//get element
Element e = document.GetElement(id);
//get element type ID
ElementId typeID = e.GetTypeId();
//get element type
Element framingType = document.GetElement(typeID);
//get type comment
Parameter typeComments = framingType.get_Parameter(BuiltInParameter.ALL_MODEL_TYPE_COMMENTS);
typeComments.Set(shape);
}
}
catch (Exception ex)
{
message = ex.Message;
return Autodesk.Revit.UI.Result.Failed;
}
return Autodesk.Revit.UI.Result.Succeeded;
}
}
}
Solved! Go to Solution.