Create Modle Text

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi
I am trying to create Model text by using API, somehow its not working, whats wrong with my code?
Any helps will be appreciated
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
namespace modeltext
{
[Transaction(TransactionMode.Manual)]
public class Class1 : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
Transaction tx = new Transaction(doc, "create modeletext");
tx.Start();
string st = "ABCccc";
ModelTextType mtt = new FilteredElementCollector(doc).OfClass(typeof(ModelTextType)).First() as ModelTextType;
mtt.get_Parameter(BuiltInParameter.TEXT_FONT).Set("Consolas");
mtt.get_Parameter(BuiltInParameter.TEXT_SIZE).SetValueString("333");
Plane plane = Plane.CreateByNormalAndOrigin(new XYZ(0, 0, 1), XYZ.Zero);
SketchPlane sp = SketchPlane.Create(doc, plane);
//HorizontalAlignment ha = HorizontalAlignment.Center;
HorizontalAlign haa = HorizontalAlign.Center;
XYZ position = new XYZ(20, 0, 0);
double depth = 20;
doc.FamilyCreate.NewModelText(st, mtt, sp, position, haa, depth);
tx.Commit();
return Result.Succeeded;
}
}
}