Namespace:
Autodesk.Revit.DB
DirectShape
Class
Description:
This class is used to store externally created geometric shapes. Primary intended use is for importing shapes from other data formats such as IFC or STEP. A DirectShape object may be assigned a category.
This class is used to store externally created geometric shapes. Primary intended use is for importing shapes from other data formats such as IFC or STEP. A DirectShape object may be assigned a category.
Remarks:
DirectShape is not a replacement for "real" Wall, Roof, Window, etc. It would typically be used where there is not enough information to create, e.g., a Wall, or full functionality of a Wall object is not needed. Some category-specific functionality may be available. If you need to modify a shape held by a DirectShape object, use Revit Geometry API, and then store the modified shape back to the DirectShape object.
DirectShape is not a replacement for "real" Wall, Roof, Window, etc. It would typically be used where there is not enough information to create, e.g., a Wall, or full functionality of a Wall object is not needed. Some category-specific functionality may be available. If you need to modify a shape held by a DirectShape object, use Revit Geometry API, and then store the modified shape back to the DirectShape object.
Examples
// Create a DirectShape Sphere
public void CreateSphereDirectShape(Document doc)
{
List<Curve> profile = new List<Curve>();
// first create sphere with 2' radius
XYZ center = XYZ.Zero;
double radius = 2.0;
XYZ profile00 = center;
XYZ profilePlus = center + new XYZ(0, radius, 0);
XYZ profileMinus = center - new XYZ(0, radius, 0);
profile.Add(Line.CreateBound(profilePlus, profileMinus));
profile.Add(Arc.Create(profileMinus, profilePlus, center + new XYZ(radius, 0, 0)));
CurveLoop curveLoop = CurveLoop.Create(profile);
SolidOptions options = new SolidOptions(ElementId.InvalidElementId, ElementId.InvalidElementId);
Frame frame = new Frame(center, XYZ.BasisX, -XYZ.BasisZ, XYZ.BasisY);
if (Frame.CanDefineRevitGeometry(frame) == true)
{
Solid sphere = GeometryCreationUtilities.CreateRevolvedGeometry(frame, new CurveLoop[] { curveLoop }, 0, 2 * Math.PI, options);
using (Transaction t = new Transaction(doc, "Create sphere direct shape"))
{
t.Start();
// create direct shape and assign the sphere shape
DirectShape ds = DirectShape.CreateElement(doc, new ElementId(BuiltInCategory.OST_GenericModel));
ds.ApplicationId = "Application id";
ds.ApplicationDataId = "Geometry object id";
ds.SetShape(new GeometryObject[] { sphere });
t.Commit();
}
}
}