Solid as OpenShell DirectShape

Solid as OpenShell DirectShape

vanlion
Advocate Advocate
3,359 Views
11 Replies
Message 1 of 12

Solid as OpenShell DirectShape

vanlion
Advocate
Advocate

Hi,

 

With a code i create in C# i can make a Solid DirectShape. But i'm also looking how you can make an OpenShell DirectShape. So you get a DirectShape like dynamo does. Anybody can point me in a direction what to do?

 

Thanks.

 

My C# DirectShape:

Annotation 2019-05-08 121414.png

 

 

Dynamo DirectShape:

 

Annotation 2019-05-08 125611.png

 

0 Likes
3,360 Views
11 Replies
Replies (11)
Message 2 of 12

jeremytammik
Autodesk
Autodesk

You can define the geometry for your direct shape element using the ShapeBuilder class:

 

http://www.revitapidocs.com/2019/66c1678c-2e01-e0de-1386-5a0e1eb3ccff.htm

 

That class enables you to build wireframe, open b-rep face or solid geometry, just as you please.

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 12

vanlion
Advocate
Advocate

Thanks jeremy!

 

So it was easy to create a wireframe with this class. but when i try to do this for creating faces, it's a little bit harder to understand which step you have to take. Do you need to use BRepBuilder or TessellatedShapeBuilder? i thought let's try a simple face creation to a directShape geometry. So i use the bottom lines from my created solid. I tried this with BRepBuilder but i was getting the error not enough faces. 

 

Thanks

 

Annotation 2019-05-10 225907.png

 

0 Likes
Message 4 of 12

jeremytammik
Autodesk
Autodesk

Glad to hear that helped. I think the BRepBuilder is possible to use, but not encouraged. The TesselatedShapeBuilder ought to be easier to use than the BRepBuilder.

 

Also note that it’s much easier to use GeometryCreationUtilities functions to create extrusions:

 

https://thebuildingcoder.typepad.com/blog/2018/02/directshape-from-brepbuilder-and-boolean.html

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 5 of 12

vanlion
Advocate
Advocate

Hello,

 

Yes the bRep looks very complex to create a shape. The shape i made as you can see at the beginning is creates as follows:

 

List<CurveLoop> profile3 = new List<CurveLoop>();
    profile3.Add(CreateCurveloop(pointList1);
    profile3.Add(CreateCurveloop(pointList2);
    ....
    Solid loft = GeometryCreationUtilities.CreateLoftGeometry(profile3 ,options);

 

But there isn't a simple step to say this solid must openshell or isn't solid but had only faces like in dynamo.

 

Maybe i'm missing something simple but i really want to understand the differeneces 🙂

0 Likes
Message 6 of 12

jeremytammik
Autodesk
Autodesk
Message 7 of 12

vanlion
Advocate
Advocate

Thanks again for sending the examples.

I will take a look at it and let you know what i can figure out!

0 Likes
Message 8 of 12

vanlion
Advocate
Advocate

Hi @jeremytammik 

 

I took me some time but i got it almost working like it should, with the code underneath. This makes Triangled faces from the solid faces. The last option i'm looking for is creating these faces only that they are not triangled. I can't find how to do this with bRep Builder as you said. I hope it's as easy as making triangled faces like this code.

 

Thanks!

 

        public TessellatedShapeBuilderResult Build_Tessellate(Face faces)
        {
            Mesh mesh = faces.Triangulate();

            TessellatedShapeBuilder builder = new TessellatedShapeBuilder();

            builder.OpenConnectedFaceSet(false);

            List<XYZ> args = new List<XYZ>(3);

            XYZ[] triangleCorners = new XYZ[3];

            for (int i = 0; i < mesh.NumTriangles; ++i)
            {
                MeshTriangle triangle = mesh.get_Triangle(i);

                triangleCorners[0] = triangle.get_Vertex(0);
                triangleCorners[1] = triangle.get_Vertex(1);
                triangleCorners[2] = triangle.get_Vertex(2);

                TessellatedFace tesseFace = new TessellatedFace(triangleCorners, ElementId.InvalidElementId);

                if (builder.DoesFaceHaveEnoughLoopsAndVertices(tesseFace))
                {
                    builder.AddFace(tesseFace);
                }
            }

            builder.CloseConnectedFaceSet();
            builder.Target = TessellatedShapeBuilderTarget.AnyGeometry;
            builder.Fallback = TessellatedShapeBuilderFallback.Mesh;

            builder.Build();

            TessellatedShapeBuilderResult result2 = builder.GetBuildResult();

            return result2;
        }

Woktin part with TessellatedBuilder:

Script.gif

0 Likes
Message 9 of 12

jeremytammik
Autodesk
Autodesk

Congratulations on the good progress!

 

I am sorry to say that I think it may not be possible to hide individual edges of the triangulated faces.

  

I hope someone corrects me on this if I am wrong, and points out how it can be achieved.

 

Thank you!

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 10 of 12

vanlion
Advocate
Advocate

Hi,

 

Thanks Jeremy. Yes i feel i'm almost there. The progress i've made is creating Tessellated faces (see earlier posts)

With the same ShapeBuilder i now can build non triangled faces, only if they are planar (see image1, simple box) and they are individually selectable, what i need!

 

When using this with an object that doesn't have all planar faces you see it not creates all the single faces (image2)

The result i need is the same as image3 but this is a solid shape and i need individually faces. So the conclusion for now is that Tessellated builder can't build my non planar shape in individually faces that aren't triangled. Anyone an idea what the right builder?

 

 

Annotation 2019-06-13 095239.pngAnnotation 2019-06-13 095338.pngAnnotation 2019-06-13 095440.png

List<Solid> sol = new List<Solid>();

Solid loft = GeometryCreationUtilities.CreateLoftGeometry(profileLoop, options);

sol.Add(loft); foreach (Solid s in sol) { foreach (Face f in s.Faces) { Build_Tessellate2(f); ElementId categoryId = new ElementId(BuiltInCategory.OST_GenericModel); DirectShape ds = DirectShape.CreateElement(doc, categoryId); ds.ApplicationId = System.Reflection.Assembly.GetExecutingAssembly().GetType().GUID.ToString(); ds.ApplicationDataId = Guid.NewGuid().ToString(); foreach (TessellatedShapeBuilderResult t1 in Build_Tessellate2(f)) { ds.SetShape(t1.GetGeometricalObjects()); ds.Name = "Single_Surface"; } } }

public List<TessellatedShapeBuilderResult> Build_Tessellate2(Face faces) { Mesh mesh = faces.Triangulate(); List<XYZ> vert = new List<XYZ>(); foreach (XYZ ij in mesh.Vertices) { XYZ vertices = ij; vert.Add(vertices); } TessellatedShapeBuilder builder = new TessellatedShapeBuilder(); builder.OpenConnectedFaceSet(false); //Filter for Title Blocks in active document FilteredElementCollector materials = new FilteredElementCollector(m_revit.Application.ActiveUIDocument.Document) .OfClass(typeof(Autodesk.Revit.DB.Material)) .OfCategory(BuiltInCategory.OST_Materials); ElementId materialId = materials.First().Id; builder.AddFace(new TessellatedFace(vert, materialId)); builder.CloseConnectedFaceSet(); builder.Target = TessellatedShapeBuilderTarget.AnyGeometry; builder.Fallback = TessellatedShapeBuilderFallback.Mesh; builder.Build(); TessellatedShapeBuilderResult result3 = builder.GetBuildResult(); List<TessellatedShapeBuilderResult> res = new List<TessellatedShapeBuilderResult>(); if (result3.Outcome.ToString() == "Sheet") { res.Add(result3); } return res; }

 

 

0 Likes
Message 11 of 12

jeremytammik
Autodesk
Autodesk

You say, '... an object that doesn't have all planar faces ... (image2)'.

 

However, as far as I can tell, all the faces in image2 are planar after all.

 

Why do you say they are non-planar?

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 12 of 12

vanlion
Advocate
Advocate

It's hardly to see in the image.

 

Attached you can find the RVT model as a solid

0 Likes