Announcements
Notice: Upload of PDF documents is currently unavailable across the Community due to an ongoing issue.

Create Solid from boundingbox

Create Solid from boundingbox

Anonymous
Not applicable
10,602 Views
11 Replies
Message 1 of 12

Create Solid from boundingbox

Anonymous
Not applicable

Hello,

I have a boundingbox and i need to convert in to a solid;

one possible solution is to use CreateExtrusionGeometry using a curveloop from some lines created from this boundingbox,

is there a better solution to accomplish this?

0 Likes
10,603 Views
11 Replies
Replies (11)
Message 2 of 12

Anonymous
Not applicable

For now i used CreateExtrusionGeometry and its OK, but i would appreciate better solutions if any.

0 Likes
Message 3 of 12

jeremytammik
Autodesk
Autodesk

Do you want to generate a persistent Revit database element?

 

If so, the simplest solution is almost certainly to use a DirectShape element:

 

http://thebuildingcoder.typepad.com/blog/about-the-author.html#5.50

 

Cheers,

 

Jeremy



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

0 Likes
Message 4 of 12

Anonymous
Not applicable

Dear jeremy,

Thank you for your answer and helpful link.

Here, this solid is a temporary one to use with ElementIntersectsSolidFilter.

Since intersecting element is a brace ,  i couldn't use BoundingBoxIntersectsFilter;

if there were a  gradient boundingboxxyz in Revit API that Could be of great use for elements such as braces;

regards.

 

 

0 Likes
Message 5 of 12

owenmerrick
Contributor
Contributor

 

Hi,

 

I was looking for an answer to the very same question, ended up here, and re-created your solution.  To save the next person a bit of typing, here's my code.  I'd love a more elegant answer but this works for my needs.

 

        public static Solid solidBoundingBox(Solid inputSolid)
        {
            BoundingBoxXYZ bbox = inputSolid.GetBoundingBox();

            // corners in BBox coords
            XYZ pt0 = new XYZ(bbox.Min.X, bbox.Min.Y, bbox.Min.Z);
            XYZ pt1 = new XYZ(bbox.Max.X, bbox.Min.Y, bbox.Min.Z);
            XYZ pt2 = new XYZ(bbox.Max.X, bbox.Max.Y, bbox.Min.Z);
            XYZ pt3 = new XYZ(bbox.Min.X, bbox.Max.Y, bbox.Min.Z);
            //edges in BBox coords
            Line edge0 = Line.CreateBound(pt0, pt1);
            Line edge1 = Line.CreateBound(pt1, pt2);
            Line edge2 = Line.CreateBound(pt2, pt3);
            Line edge3 = Line.CreateBound(pt3, pt0);
            //create loop, still in BBox coords
            List<Curve> edges = new List<Curve>();
            edges.Add(edge0);
            edges.Add(edge1);
            edges.Add(edge2);
            edges.Add(edge3);
            Double height = bbox.Max.Z - bbox.Min.Z;
            CurveLoop baseLoop = CurveLoop.Create(edges);
            List<CurveLoop> loopList = new List<CurveLoop>();
            loopList.Add(baseLoop);
            Solid preTransformBox = GeometryCreationUtilities.CreateExtrusionGeometry(loopList, XYZ.BasisZ, height);

            Solid transformBox = SolidUtils.CreateTransformed(preTransformBox, bbox.Transform);

            return transformBox;
            
        }

 

Message 6 of 12

jeremytammik
Autodesk
Autodesk

Dear Owen,

 

Thank you very much for your nice little sample code snippet.

 

I will gladly add it to The Building Coder samples, if I may.

 

Do you have a sample use case to demonstrate it doing something handy in a simple external command?

 

Thank you!

 

Cheers,

 

Jeremy



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

0 Likes
Message 7 of 12

owenmerrick
Contributor
Contributor

sampleSplitBoundingBox.jpg

Upon selecting the planar face of a solid, two new solids are created - the two halves of the bounding box of the original, split by the plane of the selected face.

 

 

 

Hi Jeremy,

 

Here's a simplified version of how I'm using the bounding box code from yesterday. Whether this command meets the definition of "doing something handy" is debatable, but it's at least a functional command. I'm working on solid modeling tools for working with non-parametric masses using somewhat different formal logic than the built-in "form" tools. The step demo'd here is really just one piece of construction geometry on the way to a more complex, yet-unfinished tool, but it illustrates a few useful functions:

 

- from user face selection, retrieve both the face and the solid
- from solid, generate solid of bounding box
- insert solid into family context

 

 

This draws _very_ heavily on the sample code provided with the SDK, particularly the FreeFormElement sample and planar face selection filter.

 

For the sample code I copied the relevant bits into a fresh addin and zipped the whole thing up. This has the source, working(for me) .dll and sample image and rfa in the "doc" folder.

 

Best,

Owen

 

0 Likes
Message 8 of 12

Mustafa.Salaheldin
Advisor
Advisor

Can you please provide a sample RVT file for your "brace" family because I guess there is a direct way to do your intersection.


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Digital Integration Manager, DuPod

Facebook | Twitter | LinkedIn

0 Likes
Message 9 of 12

BobbyC.Jones
Advocate
Advocate

Hi Jeremy,

As a use case, we use very similar code to do interference checking within a provided tolerance.

 

Owen,

I think you nailed it and I don't think there is a more elegant solution.

--
Bobby C. Jones
0 Likes
Message 10 of 12

jeremytammik
Autodesk
Autodesk

Wonderful, thank you ever so much for the perfect sample!

 

I summarised, polished and published this thread on The Building Coder:

 

http://thebuildingcoder.typepad.com/blog/2016/09/solid-from-bounding-box-and-forge-webinar-4.html#2

 

Cheers,

 

Jeremy



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

0 Likes
Message 11 of 12

owenmerrick
Contributor
Contributor

Jeremy,

 

Great, glad it worked out for you.  If I get my alternative massing modeling tools working well perhaps I'll post a follow up.

 

Bobby,

 

Thanks for the kind words.  I'm an architect rather than a proper programmer so sometimes I'm not sure if I'm missing an easier or more elegant way of doing things.

 

Best,

 

Owen

0 Likes
Message 12 of 12

516579196
Observer
Observer

516579196_0-1658825579631.png

 

 

namespace SizeAdjustment

{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class WindowDoorOpening : IExternalCommand
{

public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData,
ref string message, ElementSet elements)
{

UIApplication uIApp = commandData.Application;
Application application = uIApp.Application;
UIDocument uIDoc = uIApp.ActiveUIDocument;
Document document = uIDoc.Document;
Selection selection = uIDoc.Selection;
View view = uIDoc.ActiveView;
//【】过滤墙体 用户选择
IList<Element> faces = uIDoc.Selection.PickElementsByRectangle();


Transaction trans = new Transaction(document, "LS");
trans.Start();


var solid = solidBoundingBox(view, faces.First());
var ds7 = DirectShape.CreateElement(document, new ElementId(BuiltInCategory.OST_GenericModel));
ds7.GetGeneratingElementIds(solid);
ds7.SetShape(new List<GeometryObject>() { solid });
trans.Commit();


return Result.Succeeded;
}
public static Solid solidBoundingBox(View view,Element inputSolid)
{
BoundingBoxXYZ bbox = inputSolid.get_BoundingBox(view);

// corners in BBox coords
XYZ pt0 = new XYZ(bbox.Min.X, bbox.Min.Y, bbox.Min.Z);
XYZ pt1 = new XYZ(bbox.Max.X, bbox.Min.Y, bbox.Min.Z);
XYZ pt2 = new XYZ(bbox.Max.X, bbox.Max.Y, bbox.Min.Z);
XYZ pt3 = new XYZ(bbox.Min.X, bbox.Max.Y, bbox.Min.Z);
//edges in BBox coords
Line edge0 = Line.CreateBound(pt0, pt1);
Line edge1 = Line.CreateBound(pt1, pt2);
Line edge2 = Line.CreateBound(pt2, pt3);
Line edge3 = Line.CreateBound(pt3, pt0);
//create loop, still in BBox coords
List<Curve> edges = new List<Curve>();
edges.Add(edge0);
edges.Add(edge1);
edges.Add(edge2);
edges.Add(edge3);
Double height = bbox.Max.Z - bbox.Min.Z;
CurveLoop baseLoop = CurveLoop.Create(edges);
List<CurveLoop> loopList = new List<CurveLoop>();
loopList.Add(baseLoop);
Solid preTransformBox = GeometryCreationUtilities.CreateExtrusionGeometry(loopList, XYZ.BasisZ, height);

Solid transformBox = SolidUtils.CreateTransformed(preTransformBox, bbox.Transform);

return transformBox;

}
}
}

0 Likes