Almost Complete! Convert short C# script to Python
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
So i've been trying to create a script that allows assignment of custom detail component buttons wherever the user decides. One of my friends help me get it in C# but now I need to convert it to python.
Anyone whose wanted the C# script feel free to use the one below, just sway out the quoted text family name to the new family, and then name to the name type.
using System;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;
using System.Collections.Generic;
using System.Linq;
namespace test
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.DB.Macros.AddInId("BED06542-3666-45CA-80C6-C9131404C514")]
public partial class ThisApplication
{
private void Module_Startup(object sender, EventArgs e)
{
}
private void Module_Shutdown(object sender, EventArgs e)
{
}
#region Revit Macros generated code
private void InternalStartup()
{
this.Startup += new System.EventHandler(Module_Startup);
this.Shutdown += new System.EventHandler(Module_Shutdown);
}
#endregion
public void test()
{
UIDocument uidoc = this.ActiveUIDocument;
Document doc = this.ActiveUIDocument.Document;
FamilySymbol fs = new FilteredElementCollector(doc)
.OfClass(typeof(FamilySymbol))
.Cast<FamilySymbol>()
.FirstOrDefault(q => q.FamilyName == "AISC S Shapes-Section" && q.Name == "S12X50");
if (fs == null)
{
TaskDialog.Show("Error", "Family symbol not found");
return;
}
try
{
uidoc.PromptForFamilyInstancePlacement(fs);
}
catch (Autodesk.Revit.Exceptions.OperationCanceledException)
{
// user pushes ESC to end the commmand
}
catch (Exception ex)
{
// for example, command is run with a schedule view as the active view
TaskDialog.Show("Error", ex.Message);
}
}
}
}