Building Coder (Revit Secondary Development)-create sphere for AVF and filter

Source: Internet
Author: User

Revit 2012 API introduces the GeometryCreationUtilities class to help create objects. However, it does not provide a direct sphere creation method, but provides the following five auxiliary methods to create ry based on the input curve:
CreateBlendGeometry Fusion
CreateExtrusionGeometry stretch
CreateRevolvedGeometry Rotation
CreateSweptGeometry lofting
CreateSweptBlendGeometry lofting Fusion
The created geometric results are not added to the document as elements. However, you can use the created object, object surface, and edge to perform the following operations:
-As a surface input parameter of the Analysis Visualization Framework (AVF) Method
Example: SpatialFieldManager. AddSpatialFieldPrimitive
-As an object input parameter for determining the 3D element Space Intersection
-As a Boolean input parameter
-As input parameter for geometric calculation
For example, Face. Project, Face. Intersect, and other geometric methods related to surfaces, entities, and edges

Since the entities created in this way only exist in the memory and cannot be added to the Revit file database and saved together with the files, what are their functions?

As we mentioned above, you can use these entities to visually display some results through AVF; or when searching for intersection elements (ElementIntersectsFilter), you can limit the scope to a space area.

Create sphere
We can use the CreateRevolvedGeometry () method: first, create a closed curve that represents the semi-circle, including a 180 degree arc and a straight line connecting the two endpoints of the arc (that is, the diameter line passing through the center of the circle ). Then you can rotate the semi-circular area to 360 degrees on the axis with the line diameter.


Here we first need to create an object called Frame in Revit. To allow my code to create a sphere anywhere, I also need to take the ball center and ball radius as input parameters. I can use the Ballon to define the Frame position. At first, I thought that since the closed curve of the semi-circular plane is for the global coordinate system, the Frame should automatically convert other geometric data of the semi-circular plane to the global coordinate system. However, when I use a local coordinate system with a ball center as the origin to define an arc and a diameter line, the CreateRevolvedGeometry () method throws an exception: the closed curve must be on the right of the Z axis (X coordinate> = 0 ).


Therefore, when creating the arc and diameter line, we must use the coordinate values that have been converted to the global coordinate system.
[Csharp
<Span style = "font-size: 12px;" >/// <summary>
/// Create a sphere with the specified center and radius
/// </Summary>
Static public Solid CreateSphereAt (
CreationApp creapp,
XYZ center,
Double radius)
{
// Create a Frame using the standard global coordinate system

Frame frame = new Frame (center,
XYZ. BasisX, XYZ. BasisY, XYZ. BasisZ );

// Create a semi-circular closed curve in the Z axis (note that all coordinates are relative to the global coordinate system)

Arc arc = creapp. NewArc (
Center-radius * XYZ. BasisZ,
Center + radius * XYZ. BasisZ,
Center + radius * XYZ. BasisX );

Line line = creapp. NewLineBound (
Arc. get_EndPoint (1 ),
Arc. get_EndPoint (0 ));

CurveLoop halfCircle = new CurveLoop ();
HalfCircle. Append (arc );
HalfCircle. Append (line );

List <CurveLoop> loops = new List <CurveLoop> (1 );
Loops. Add (halfCircle );

Return GeometryCreationUtilities
. CreateRevolvedGeometry (
Frame, loops, 0, 2 * Math. PI );
} </Span>

Use AVF to display objects
An important use of temporary entities created using the ry creation tool class is to filter elements based on geometric features, which I will discuss recently. Now let's use AVF to display these geometric entities.

[Csharp]
Void PaintSolids (
Document doc,
Solid solid,
Int level)
{
Application app = doc. Application;
 
View view = doc. ActiveView;
 
If (view. AnalysisDisplayStyleId = ElementId. InvalidElementId)
{
CreateAvfDisplayStyle (doc, view );
}
 
SpatialFieldManager sfm = SpatialFieldManager. GetSpatialFieldManager (view );
 
If (null = sfm)
{
Sfm = SpatialFieldManager. CreateSpatialFieldManager (view, 1 );
}
 
If (_ schemaId! =-1)
{
IList <int> results = sfm. GetRegisteredResults ();
 
If (! Results. Contains (_ schemaId ))
{
_ SchemaId =-1;
}
}
 
If (_ schemaId =-1)
{
AnalysisResultSchema resultSchema = new AnalysisResultSchema ("PaintedSolids", "Description ");
_ SchemaId = sfm. RegisterResult (resultSchema );
}
 
FaceArray faces = solid. Faces;
Transform trf = Transform. Identity;
 
Foreach (Face face in faces)
{
Int idx = sfm. AddSpatialFieldPrimitive (face, trf );
 
IList <UV> uvPts = new List <UV> (1 );
 
UvPts. Add (face. GetBoundingBox (). Min );
 
FieldDomainPointsByUV pnts = new FieldDomainPointsByUV (uvPts );
 
List <double> doubleList = new List <double> (1 );
 
DoubleList. Add (level );
 
IList <ValueAtPoint> valList = new List <ValueAtPoint> (1 );
 
ValList. Add (new ValueAtPoint (doubleList ));
 
FieldValues vals = new FieldValues (valList );
 
Sfm. UpdateSpatialFieldPrimitive (idx, pnts, vals, _ schemaId );
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.