Hi,
If you open the attached project, and then run the code in the attached project, I get an error message that it fails to create a face from the curves (Which are obviously planar). Can anyone see something wrong with the familly (which was created from other code) or is there another change that can fix this? Manually creating a foundation slab works fine.
Thanks in advance,
Jon
Solved! Go to Solution.
Solved by Joe.Ye. Go to Solution.
Hi Jon,
The problem is the method NewFloor doesn't match the floor type that you passed in.
The floor type you passed in ("BaseSlab") is the slab floor type, it cannot work with the NewFloor method. If you replace the type name by Generic 300mm, that will work well on your project model.
If you want to create a slab with the "BaseSlab" type , please use NewSlab() method.
Here is the code to create a normal floor.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.ApplicationServices;
namespace GGYM
{
[Autodesk.Revit.Attributes.Transaction(TransactionMode.Manual)]
publicclassImportIFCGeomGym : IExternalCommand
{
publicResult Execute(ExternalCommandData commandData,
refstring message, ElementSet elements)
{
Document doc = commandData.Application.ActiveUIDocument.Document;
Application app = commandData.Application.Application;
Transaction trn = newTransaction(doc, "ggTest");
trn.Start();
CurveArray ca = newCurveArray();
double d = 16.404199500;
XYZ p1 = newXYZ(-d, -d, 0), p2 = newXYZ(-d, d, 0),
p3 = newXYZ(d, d, 0), p4 = newXYZ(d, -d, 0);
ca.Append(app.Create.NewLine(p1, p2, true));
ca.Append(app.Create.NewLine(p2, p3, true));
ca.Append(app.Create.NewLine(p3, p4, true));
ca.Append(app.Create.NewLine(p4, p1, true));
ElementClassFilter filter = newElementClassFilter(typeof(Level));
FilteredElementCollector coll = newFilteredElementCollector(doc);
coll.WherePasses(filter);
System.Collections.IEnumerator i = coll.GetElementIterator();
i.Reset();
Level l = null;
while (i.MoveNext())
{
l = i.Current asLevel;
if (l != null)
{
break;
}
}
FloorType ft = null;
foreach (FloorType t in doc.FloorTypes)
{
if (t != null && string.Compare(t.Name, "Generic 300mm", true) == 0)
{
ft = t;
break;
}
}
Floor f = doc.Create.NewFloor(ca, ft, l, false);
//doc.Regenerate();
trn.Commit();
returnResult.Succeeded;
}
}
}
______________________________________________________________
If my post answers your question, please click the "Accept as Solution" button. This helps everyone find answers more quickly!
Thanks Joe, I hadn't seen the slab creation methods. Actually NewFoundationSlab is most appropriate as I can nominate floor type. The error message thrown is a little misleading though, and perhaps the help documentation could refer to these methods.
Thanks again for the help,
Jon