How to get wall ViewSection 2D elements?

How to get wall ViewSection 2D elements?

Anonymous
Not applicable
2,308 Views
5 Replies
Message 1 of 6

How to get wall ViewSection 2D elements?

Anonymous
Not applicable

We are doing a section cut on a wall using ViewSection.CreateSection and adding that section cut to a sheet. That view can then be exported as a 2D AutoCAD drawing. We want to grab the elements of the ViewSection, if they exist, that are used to create the 2D model and exported.

 

I've used RevitLookup to explore the ViewSection and don't see what I'm looking for. There is a Geometry Field but I cannot look further into it and in my code when I try to retrieve a GeometryElement from the ViewSection it returns null.

 

So is there a way of breaking the ViewSection down into elements (lines, faces, solids) that I can retrieve to reproduce my own 2D model as is done when exporting the section cut to an AutoCAD drawing?

0 Likes
Accepted solutions (1)
2,309 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
0 Likes
Message 3 of 6

Anonymous
Not applicable

Thank you for the response. I have code very similar to that contained in the link to create a section cut. I then also display the section cut in its own sheet with ViewSheet.Create. So I can do a section cut and place it in a view.

 

What I'm interested in finding out is how we can inspect the individual 2D (lines, verrtices, etc..) and 3D (solids) elements that make up the section cut of the wall, which is a ViewSection. I've used RevitLookup to explore the section cut but don't see any properties of ViewSection that would give me that information besides Geometry. But, when I use get_Geometry on the ViewSection (with ComputeReferences = true) I get a null for the GeometryElement.

 

When you export a sheet to .dwg or .dxf the views are collapsed down to 2D lines on paper, so it seems there should be a way to perform the same collapse and inspect the lines in Revit before exporting.

0 Likes
Message 4 of 6

jeremytammik
Autodesk
Autodesk

Dear Frank,

 

Thank you for your query.

 

Yes, the Revit API does provide an efficient method to collapse the 3D solids and curves down to 2D lines, the ExtrusionAnalyzer class:

 

http://www.revitapidocs.com/2017/ba9e3283-6868-8834-e8bf-2ea9e7358930.htm

 

Here is an example of using it to generate a 2D curve loop from 3D solids:

 

http://thebuildingcoder.typepad.com/blog/2013/04/extrusion-analyser-and-plan-view-boundaries.html

 

I hope this helps.

 

By the way, please note that you generated an ADN ticket 12487025 [How to get wall ViewSection 2D elements?] by manually escalating this thread.

 

Another ticket 12491418 [How to get wall ViewSection 2D elements?] had already been generated automatically prior to your manual escalation.

 

I am closing the new case 12487025 as a duplicate of the original one 12491418.

 

Do you see both of those two listed in your view? I do.

 

Best regards,

 

Jeremy



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

Message 5 of 6

Anonymous
Not applicable

Dear Jeremy,

 

Thank you for the response. This looks like what I'm needing, but I'm having a problem getting it to work. 

 

I have code to create the section cut for a ViewSection like this:

 

Document doc = revit.Application.ActiveUIDocument.Document;
//find a section view type
IEnumerable<ViewFamilyType> viewFamilyTypes = from elem in new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType))
                                                                              let type = elem as ViewFamilyType
                                                                              where type.ViewFamily == ViewFamily.Section
                                                                              select type;
//create a BoundingBoxXYZ instance centered on wall
ElementCategoryFilter wallsFilter = new ElementCategoryFilter(BuiltInCategory.OST_Walls);
FilteredElementCollector collector = new FilteredElementCollector(doc);
IList<Element> walls = collector.WherePasses(wallsFilter).WhereElementIsNotElementType().ToElements();
Wall wall = (Wall)walls[0];
LocationCurve lc = wall.Location as LocationCurve;
Transform curveTransform = lc.Curve.ComputeDerivatives(0.5, true);

XYZ origin = curveTransform.Origin;
XYZ viewDirection = curveTransform.BasisX.Normalize();
XYZ normal = viewDirection.CrossProduct(XYZ.BasisZ).Normalize();

Transform transform = Transform.Identity;
transform.Origin = origin;
transform.BasisX = normal;
transform.BasisY = XYZ.BasisZ;
transform.BasisZ = normal.CrossProduct(XYZ.BasisZ);

BoundingBoxXYZ sectionBox = new BoundingBoxXYZ();
sectionBox.Transform = transform;
sectionBox.Min = new XYZ(-10, 0, 0);
sectionBox.Max = new XYZ(10, wall.get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM).AsDouble(), 5);

//create section cut

ViewSection viewSection;
using (Transaction tx = new Transaction(doc))
{
    tx.Start("SectionCut");
    viewSection = ViewSection.CreateSection(doc, viewFamilyTypes.First().Id, sectionBox);
    tx.Commit();
}

 

But it looks like to use the ExtrusionAnalyzer I need to break the ViewSection down into Solids through the GeometryElement, but when I try to retrieve the GeometryElement of the ViewSection I get a null. Here's my code that would get the GeometryElement and retrieve the Solids:

 

Autodesk.Revit.DB.Options geoOptions = doc.Application.Create.NewGeometryOptions();
geoOptions.ComputeReferences = true;
geoOptions.DetailLevel = ViewDetailLevel.Medium;
GeometryElement geoElem = viewSection.get_Geometry(geoOptions);
IEnumerator<GeometryObject> Objects1 = geoElem.GetEnumerator();
while (Objects1.MoveNext())
{
    GeometryObject gobj = Objects1.Current;

    Solid tSolid = gobj as Solid;
    //use ExtrusionAnalyzer here
}

 

However geoElem is null. When I explore the section cut in Revit with RevitLookup it has a Geometry Field with <Geometry.Element> Value, but it is not bold and double-clicking on Geometry to Snoop further does nothing. 

 

Am I doing something wrong here? Is there another way to get to the Solids of the ViewSection that I'm not seeing?

 

Sorry about generating two tickets for this one thread.

 

Thank you for your help.

0 Likes
Message 6 of 6

jeremytammik
Autodesk
Autodesk
Accepted solution

Dear Frank,

 

You are querying the section view for its geometry.

 

Does your building consist of section views?

 

Nope, it consists of walls and other building elements, I would hope and assume.

 

I suggest that you query the building elements for their geometry, and pass in the section view as the argument.

 

You can also pass in the view into a filtered element collector to retrieve only those elements that are visible in the given view.

 

Furthermore, you normally do not need to request ComputeReferences = true; that is expensive.

 

You only do that if you really require references and are going to use them in some way.

 

Are you?

 

Once you have the element geometry, it is up to you to decide which portions of it you wish to process.

 

Solids can be flattened using the extrusion analyser.

 

Curves you can easily flatten yourself, e.g., tessellate them and project the resulting line segments onto your view plane:

 

http://thebuildingcoder.typepad.com/blog/2008/12/2d-polygon-areas-and-outer-loop.html

 

http://thebuildingcoder.typepad.com/blog/2008/12/3d-polygon-areas.html

 

 

Cheers,

 

Jeremy

 



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