Create Modle Text

Create Modle Text

Anonymous
Not applicable
691 Views
1 Reply
Message 1 of 2

Create Modle Text

Anonymous
Not applicable

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;

}
}
}

 

0 Likes
692 Views
1 Reply
Reply (1)
Message 2 of 2

joshua.lumley
Advocate
Advocate

doc is a project, you need 'myFamilyDoc'. Make a family (Generic Model) where the text size and content can be set via associated parameters then run your code on that. 


Model text can't be directly created in project with the Revit API (that would have been a deliberate decision not an oversight) 3D text screws up performance it's something you use sparingly.