How converting simple macro to Revit API to create List Of Drawings:
/* * Created by SharpDevelop. * User: MOHAMED.moussa * Date: 4/3/2017 * Time: 3:25 PM * * To change this template use Tools | Options | Coding | Edit Standard Headers. */ using System; using Autodesk.Revit.UI; using Autodesk.Revit.DB; using Autodesk.Revit.UI.Selection; using System.Collections.Generic; using System.Linq; using System.Text; using Autodesk.Revit.ApplicationServices; namespace LODCREATION { [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] [Autodesk.Revit.DB.Macros.AddInId("137BBBD9-148E-4401-913F-168FDEA677C6")] public partial class ThisDocument { private void Module_Startup(object sender, EventArgs e){ } private void Module_Shutdown(object sender, EventArgs e){ } public void LODCREATION() { UIApplication uiApp = this.Application; Application app = uiApp.Application; UIDocument uiDoc = uiApp.ActiveUIDocument; Document Doc = uiDoc.Document; StringBuilder sb = new StringBuilder(); ElementCategoryFilter sheetcf = new ElementCategoryFilter(BuiltInCategory.OST_Sheets); FilteredElementCollector sheetCollector = new FilteredElementCollector(Doc); IList<Element> sheetlist = sheetCollector.WherePasses(sheetcf).WhereElementIsNotElementType().ToElements(); foreach(Element sheet in sheetlist) { FilteredElementCollector panelCollector = new FilteredElementCollector(Doc, sheet.Id); IList<Element> panellist = panelCollector.WherePasses(panelcf).WhereElementIsNotElementType().ToElements(); sb.AppendLine(sheet.get_Parameter(BuiltInParameter.SHEET_NUMBER).AsString() + " \t"+sheet.get_Parameter(BuiltInParameter.SHEET_NAME).AsString()); } Autodesk.Revit.DB.XYZ baseVec = Document.Application.Create.NewXYZ(0.0, 0.0, 1.0); Autodesk.Revit.DB.XYZ upVec = Document.Application.Create.NewXYZ(0.0, 0.0, 1.0); Autodesk.Revit.DB.XYZ origin = Document.Application.Create.NewXYZ(0.0, 0.0, 0.0); Autodesk.Revit.DB.XYZ origin1 = Document.Application.Create.NewXYZ(0.0, 3.0, 0.0); Autodesk.Revit.DB.TextAlignFlags align = Autodesk.Revit.DB.TextAlignFlags.TEF_ALIGN_LEFT | Autodesk.Revit.DB.TextAlignFlags.TEF_ALIGN_TOP; string strText = sb.ToString(); //----------- double lineWidth = 4.0 / 12.0; Autodesk.Revit.DB.Transaction t = new Autodesk.Revit.DB.Transaction(Document, "NewTextNote"); t.Start(); Autodesk.Revit.DB.View pView = Document.ActiveView; Document.Create.NewTextNote(pView,origin1, baseVec, upVec, lineWidth, align, strText); t.Commit(); } #region Revit Macros generated code private void InternalStartup() { this.Startup += new System.EventHandler(Module_Startup); this.Shutdown += new System.EventHandler(Module_Shutdown); } #endregion } }
Excuse while it's the first Revit Macro.
Solved! Go to Solution.
Solved by IbrahimNaeem. Go to Solution.
Solved by IbrahimNaeem. Go to Solution.
Follow along with the steps mentioned in the following URL
http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=16849339
Thanks, Ibrahim Naeem
namespace LODCREATION { [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] public class ThisDocument : IExternalCommand //subscribe to //the interface { public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { \\Write your Code here. \\ get everything from the document and application from CommandData \\parameter Document doc = commandData.Application.ActiveUIDocument.Document; Application app = doc.Application; \\Continue to write and adjust your code return Result.Succeeded; }
Use the Manifest file as described in the link given before.
After finishing with build succeeded , you'll find your button under external tools in the addins tab
Thanks, Ibrahim Naeem
Thanks for solving,
The final working code is:
using System; using System.Collections.Generic; using System.Linq; using Autodesk.Revit.DB; using Autodesk.Revit.DB.Architecture; using Autodesk.Revit.UI; using Autodesk.Revit.UI.Selection; using Autodesk.Revit.ApplicationServices; using Autodesk.Revit.Attributes; using System.Text; using Autodesk.Revit.ApplicationServices; [TransactionAttribute(TransactionMode.Manual)] [RegenerationAttribute(RegenerationOption.Manual)] public class Lab1PlaceGroup : IExternalCommand { public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { //Get application and document objects UIApplication uiApp = commandData.Application; Document doc = uiApp.ActiveUIDocument.Document; StringBuilder sb = new StringBuilder(); ElementCategoryFilter sheetcf = new ElementCategoryFilter(BuiltInCategory.OST_Sheets); FilteredElementCollector sheetCollector = new FilteredElementCollector(doc); IList<Element> sheetlist = sheetCollector.WherePasses(sheetcf).WhereElementIsNotElementType().ToElements(); foreach (Element sheet in sheetlist) { FilteredElementCollector panelCollector = new FilteredElementCollector(doc, sheet.Id); sb.AppendLine(sheet.get_Parameter(BuiltInParameter.SHEET_NUMBER).AsString() + " \t" + sheet.get_Parameter(BuiltInParameter.SHEET_NAME).AsString()); } XYZ baseVec = new XYZ(0.0, 0.0, 1.0); XYZ upVec = new XYZ(0.0, 0.0, 1.0); XYZ origin = new XYZ(0.0, 0.0, 0.0); XYZ origin1 = new XYZ(0.0, 3.0, 0.0); Autodesk.Revit.DB.TextAlignFlags align = Autodesk.Revit.DB.TextAlignFlags.TEF_ALIGN_LEFT | Autodesk.Revit.DB.TextAlignFlags.TEF_ALIGN_TOP; string strText = sb.ToString(); //----------- double lineWidth = 4.0 / 12.0; Autodesk.Revit.DB.Transaction t = new Autodesk.Revit.DB.Transaction(doc, "NewTextNote"); t.Start(); Autodesk.Revit.DB.View pView = doc.ActiveView; doc.Create.NewTextNote(pView, origin1, baseVec, upVec, lineWidth, align, strText); t.Commit(); return Result.Succeeded; } }
Finally if you have optimization to show more sheet data(in addition to name and number like system..etc) in the list of drawings Also to fit the LOD to the sheet I will be appreciate that.
Many thanks.
Glad that the problem has been solved. Now I'm asking why do you use a text to show sheet data, you have already a schedule where you can define parameters and everything?
Thanks, Ibrahim Naeem
Can't find what you're looking for? Ask the community or share your knowledge.