This might sound like a very basic question, and I apologize for that - however, I literally couldn't find anything about this anywhere around.
I am trying to make a command which creates a cube made of model lines and puts it in the drawing. For the cube creation, I've found on Jeremy Tammik's blog some documentation about this and got the following code:
static Solid CreateCube(double d)
{
return CreateRectangularPrism(
XYZ.Zero, d, d, d);
}
static Solid CreateRectangularPrism(
XYZ center,
double d1,
double d2,
double d3)
{
List<Curve> profile = new List<Curve>();
XYZ profile00 = new XYZ(-d1 / 2, -d2 / 2, -d3 / 2);
XYZ profile01 = new XYZ(-d1 / 2, d2 / 2, -d3 / 2);
XYZ profile11 = new XYZ(d1 / 2, d2 / 2, -d3 / 2);
XYZ profile10 = new XYZ(d1 / 2, -d2 / 2, -d3 / 2);
profile.Add(Line.CreateBound(profile00, profile01));
profile.Add(Line.CreateBound(profile01, profile11));
profile.Add(Line.CreateBound(profile11, profile10));
profile.Add(Line.CreateBound(profile10, profile00));
CurveLoop curveLoop = CurveLoop.Create(profile);
SolidOptions options = new SolidOptions(
ElementId.InvalidElementId,
ElementId.InvalidElementId);
return GeometryCreationUtilities
.CreateExtrusionGeometry(
new CurveLoop[] { curveLoop },
XYZ.BasisZ, d3, options);
}
In the Execute() method, I only have this:
using (Transaction tx = new Transaction(doc))
{
tx.Start("create cube");
Solid cube = CreateCube(100);
// What shall I do next??
tx.Commit();
}
At this point I am stuck, as I can't seem to find any way to display this cube in the drawing. Moreover, what is further confusing me is that the cube's Id is set to -1. I also checked its visibility in code and it seems to hold true, however, it does not appear anywhere in the drawing. What am I missing out? How can I make it appear in the drawing?
Any tips, documentation is code is highly welcome!
Thank you.
You have created a GeometryObject but no Revit Element, then you cannot see any object because there is no a database object to show.
You could create a DirectShape and set the geometry that you created :
var ds = DirectShape.CreateElement(revitDocument, new ElementId(BuiltInCategory.OST_GenericModel));
ds.SetName("Cube");
ds.SetShape(new List<GeometryObject>() { cube });