In this lab, we shall create a divided surface on top of the form we created in the lab 7-1 as shown in the
image below -
For this lab, we shall use the Category filter to extract all the mass elements which belong to
category OST_MassSurface.
# region Lab7_2_CreateDividedSurface
/// <summary>
/// Create a divided surface using reference of a face of the form.
/// </summary>
public class Lab7_2_CreateDividedSurface : IExternalCommand
{
public IExternalCommand.Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
Application app = commandData.Application;
Document doc = app.ActiveDocument;
try
{
// find forms in the model by filter:
Filter filterForm = app.Create.Filter.NewCategoryFilter(BuiltInCategory.OST_MassSurface);
List<Autodesk.Revit.Element> forms = new List<Autodesk.Revit.Element>();
doc.get_Elements(filterForm, forms);
foreach (Form form in forms)
{
. . .
}
}
catch
{
return IExternalCommand.Result.Failed;
}
return IExternalCommand.Result.Succeeded;
}
}
#endregion
#Region "Lab7_2_CreateDividedSurface"
Public Class Lab7_2_CreateDividedSurface
Implements IExternalCommand
Public Function Execute( _
ByVal commandData As ExternalCommandData, _
ByRef message As String, _
ByVal elements As ElementSet) _
As IExternalCommand.Result _
Implements IExternalCommand.Execute
Dim app As Application = commandData.Application
Dim doc As Document = app.ActiveDocument
Try
' find forms in the model by filter:
Dim filterForm As Filter = app.Create.Filter.NewCategoryFilter(BuiltInCategory.OST_MassSurface)
Dim forms As New List(Of Autodesk.Revit.Element)()
Dim iForms As Integer = doc.Elements(filterForm, forms)
For Each form As Form In forms
. . .
Next
Catch
Return IExternalCommand.Result.Failed
End Try
Return IExternalCommand.Result.Succeeded
End Function
End Class
#End Region
With each of the forms in the model, we shall get access to the geometry
element of each form which is a collection of Geometry Objects stored in an
array GeometryObjectArray. With each of the geometry object, working with only
the ones that are solids, we shall work with each face on the solid and create a
divided surface on the face(s) using the NewDividedSurface method on the
FamilyItemFactory instance.
// Now, lets create the Divided surface on the loft form
Autodesk.Revit.Creation.FamilyItemFactory fac = doc.FamilyCreate;
Options options = app.Create.NewGeometryOptions();
options.ComputeReferences = true;
options.View = doc.ActiveView;
Autodesk.Revit.Geometry.Element element = form.get_Geometry(options);
GeometryObjectArray geoObjectArray = element.Objects;
//enum the geometry element
for (int j = 0; j < geoObjectArray.Size; j++)
{
GeometryObject geoObject = geoObjectArray.get_Item(j);
Solid solid = geoObject as Solid;
foreach (Face face in solid.Faces)
{
if (face.Reference != null)
{
if (null != face)
{
DividedSurface divSurface = fac.NewDividedSurface(face.Reference);
}
}
}
}
' Now, lets create the Divided surface on the loft form
Dim fac As Autodesk.Revit.Creation.FamilyItemFactory = doc.FamilyCreate
Dim options As Autodesk.Revit.Geometry.Options = app.Create.NewGeometryOptions()
options.ComputeReferences = True
options.View = doc.ActiveView
Dim element As Autodesk.Revit.Geometry.Element = form.Geometry(options)
Dim geoObjectArray As GeometryObjectArray = element.Objects
'enum the geometry element
For j As Integer = 0 To geoObjectArray.Size - 1
Dim geoObject As GeometryObject = geoObjectArray.Item(j)
Dim solid As Solid = TryCast(geoObject, Solid)
For Each face As Autodesk.Revit.Geometry.Face In solid.Faces
If face.Reference IsNot Nothing Then
If face IsNot Nothing Then
Dim divSurface As DividedSurface = fac.NewDividedSurface(face.Reference)
End If
End If
Next
Next
Compile the code, update Revit.ini and test the command. Examine the outcome.
next previous home copyright © 2007-2009 jeremy tammik, autodesk inc. all rights reserved.