How can I display the created cube?

How can I display the created cube?

Anonymous
Not applicable
1,083 Views
4 Replies
Message 1 of 5

How can I display the created cube?

Anonymous
Not applicable

Greetings.

 

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.

0 Likes
1,084 Views
4 Replies
Replies (4)
Message 2 of 5

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @Anonymous ,

 

The code you used creates a cube in the project but the cube is not visible.

 

For visualization, use AVF to show the cube.

https://thebuildingcoder.typepad.com/blog/2015/07/intersect-solid-filter-avf-and-directshape-for-debugging.html 

 

 

 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 5

Anonymous
Not applicable

Thanks. I will also try that.

 

Could you, please, also advice me on how to make a cube using model lines instead?

0 Likes
Message 4 of 5

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @Anonymous ,

The below link helps you to create a model line.

By giving appropriate points(XYZ) you can create a 3D Cube using model lines

https://forums.autodesk.com/t5/revit-api-forum/3d-model-line/td-p/5961937 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 5 of 5

3dimdev
Enthusiast
Enthusiast

You can also add it to your document as a DirectShape.

 

        public static void DrawShape(Solid sourceSolid, Document revitDocument, ElementId categoryId = null)
        {
            if (sourceSolid == null) {
                throw new ArgumentNullException(nameof(sourceSolid));
            }

            if (revitDocument == null) {
                throw new ArgumentNullException(nameof(revitDocument));
            }

            if (categoryId == null || categoryId == ElementId.InvalidElementId)
            {
                var genericModelId = revitDocument.Settings.Categories.get_Item(BuiltInCategory.OST_GenericModel).Id;
                categoryId = genericModelId;
            }

            var shape = DirectShape.CreateElement(revitDocument, categoryId);

            shape.SetShape(new List<GeometryObject> {sourceSolid});
        }

 

3rd Dimension Developer
YouTube.com/@3DimDev
0 Likes