<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Setting the Type Comments in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/setting-the-type-comments/m-p/5757134#M71175</link>
    <description>&lt;P&gt;Since you are changing the model by editing the parameters, you need to use a transaction.&lt;/P&gt;</description>
    <pubDate>Wed, 05 Aug 2015 00:47:30 GMT</pubDate>
    <dc:creator>Troy_Gates</dc:creator>
    <dc:date>2015-08-05T00:47:30Z</dc:date>
    <item>
      <title>Setting the Type Comments</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/setting-the-type-comments/m-p/5756316#M71174</link>
      <description>&lt;P&gt;So I'm attempting to edit the Type Comments for all Framing objects currently in a model. &amp;nbsp;When I attempt to display the information gathered, everything works beautifully. &amp;nbsp;However, I'm stuck on how to make the actual change to the Type Comments field... &amp;nbsp;Any thoughts? (Be gentle, I'm just wrapping my head around C#)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;using System;&lt;BR /&gt;using System.Reflection;&lt;BR /&gt;using System.Windows.Media.Imaging;&lt;BR /&gt;using System.Collections;&lt;BR /&gt;using System.Collections.Generic;&lt;BR /&gt;using Autodesk.Revit.UI;&lt;BR /&gt;using Autodesk.Revit.UI.Selection;&lt;BR /&gt;using Autodesk.Revit.DB;&lt;BR /&gt;using Autodesk.Revit.ApplicationServices;&lt;BR /&gt;using Autodesk.Revit.Attributes;&lt;/P&gt;&lt;P&gt;namespace _TT_Revit_Tools&lt;BR /&gt;{&lt;BR /&gt;public class ttAddPanel : IExternalApplication&lt;BR /&gt;{&lt;BR /&gt;public Result OnStartup(UIControlledApplication application)&lt;BR /&gt;{&lt;BR /&gt;RibbonPanel ribbonPanel = application.CreateRibbonPanel("TT Revit Tools");&lt;/P&gt;&lt;P&gt;string thisAssemblyPath = Assembly.GetExecutingAssembly().Location;&lt;BR /&gt;PushButtonData buttonData = new PushButtonData("cmdDocument_Selection",&lt;BR /&gt;"Framing Type Comments",thisAssemblyPath,"_TT_Revit_Tools.Document_Selection");&lt;/P&gt;&lt;P&gt;PushButton pushbutton = ribbonPanel.AddItem(buttonData) as PushButton;&lt;BR /&gt;pushbutton.ToolTip = "Get Element ID of selected objects.";&lt;/P&gt;&lt;P&gt;return Result.Succeeded;&lt;BR /&gt;}&lt;BR /&gt;public Result OnShutdown(UIControlledApplication application)&lt;BR /&gt;{&lt;BR /&gt;return Result.Succeeded;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.ReadOnly)]&lt;BR /&gt;public class Document_Selection : IExternalCommand&lt;BR /&gt;{&lt;BR /&gt;public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData,&lt;BR /&gt;ref string message, ElementSet elements)&lt;BR /&gt;{&lt;BR /&gt;try&lt;BR /&gt;{&lt;BR /&gt;UIDocument uidoc = commandData.Application.ActiveUIDocument;&lt;BR /&gt;Document document = uidoc.Document;&lt;BR /&gt;ElementClassFilter familyInstanceFilter = new ElementClassFilter(typeof(FamilyInstance));&lt;BR /&gt;ElementCategoryFilter framingCategoryFilter = new ElementCategoryFilter(BuiltInCategory.OST_StructuralFraming);&lt;BR /&gt;LogicalAndFilter framingInstanceFilter = new LogicalAndFilter(familyInstanceFilter, framingCategoryFilter);&lt;BR /&gt;FilteredElementCollector collector = new FilteredElementCollector(document);&lt;BR /&gt;ICollection&amp;lt;ElementId&amp;gt; framing = collector.WherePasses(framingInstanceFilter).ToElementIds();&lt;/P&gt;&lt;P&gt;foreach (ElementId id in framing)&lt;BR /&gt;{&lt;BR /&gt;//Obtain Shape&lt;BR /&gt;string name = document.GetElement(id).Name;&lt;BR /&gt;string shape = name.Substring(0, name.IndexOf("X"));&lt;BR /&gt;//get element&lt;BR /&gt;Element e = document.GetElement(id);&lt;BR /&gt;//get element type ID&lt;BR /&gt;ElementId typeID = e.GetTypeId();&lt;BR /&gt;//get element type&lt;BR /&gt;Element framingType = document.GetElement(typeID);&lt;BR /&gt;//get type comment&lt;BR /&gt;Parameter typeComments = framingType.get_Parameter(BuiltInParameter.ALL_MODEL_TYPE_COMMENTS);&lt;/P&gt;&lt;P&gt;typeComments.Set(shape);&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;catch (Exception ex)&lt;BR /&gt;{&lt;BR /&gt;message = ex.Message;&lt;BR /&gt;return Autodesk.Revit.UI.Result.Failed;&lt;BR /&gt;}&lt;BR /&gt;return Autodesk.Revit.UI.Result.Succeeded;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Tue, 04 Aug 2015 15:49:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/setting-the-type-comments/m-p/5756316#M71174</guid>
      <dc:creator>mkrebs</dc:creator>
      <dc:date>2015-08-04T15:49:24Z</dc:date>
    </item>
    <item>
      <title>Re: Setting the Type Comments</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/setting-the-type-comments/m-p/5757134#M71175</link>
      <description>&lt;P&gt;Since you are changing the model by editing the parameters, you need to use a transaction.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Aug 2015 00:47:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/setting-the-type-comments/m-p/5757134#M71175</guid>
      <dc:creator>Troy_Gates</dc:creator>
      <dc:date>2015-08-05T00:47:30Z</dc:date>
    </item>
    <item>
      <title>Re: Setting the Type Comments</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/setting-the-type-comments/m-p/5757625#M71176</link>
      <description>&lt;P&gt;Thank you Troy, you were correct. &amp;nbsp;Adding the transaction resolved the issue.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;using (Transaction transaction = new Transaction(document, "Type Comments"))&lt;BR /&gt;{&lt;BR /&gt;transaction.Start();&lt;BR /&gt;if (typeComments.ToString() != shape)&lt;BR /&gt;{&lt;BR /&gt;if (shape != "")&lt;BR /&gt;{&lt;BR /&gt;FamilyInstance famInstance = e as FamilyInstance;&lt;BR /&gt;famInstance.Symbol.get_Parameter("Type Comments").Set(shape);&lt;BR /&gt;//TaskDialog.Show("Revit", "Completed - set " + id.IntegerValue + " to " + shape);&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;transaction.Commit();&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Wed, 05 Aug 2015 11:55:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/setting-the-type-comments/m-p/5757625#M71176</guid>
      <dc:creator>mkrebs</dc:creator>
      <dc:date>2015-08-05T11:55:07Z</dc:date>
    </item>
    <item>
      <title>Re: Setting the Type Comments</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/setting-the-type-comments/m-p/5800932#M71177</link>
      <description>&lt;P&gt;Mkrebs,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As far as I know, to be able to write value into "Type Comments" parameter, you need to change your current transaction mode as follow:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.&lt;FONT color="#FF0000"&gt;Manual&lt;/FONT&gt;)]&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Sep 2015 01:17:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/setting-the-type-comments/m-p/5800932#M71177</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-09-03T01:17:15Z</dc:date>
    </item>
  </channel>
</rss>

