Revit API floor opening

Source: Internet
Author: User

Start [Transaction (TransactionMode. Manual)]
[Regeneration (RegenerationOption. Manual)]
CmdFloorOpening: IExternalCommand
{
Result Execute (ExternalCommandData upload data, msg, ElementSet elements)
{
UIDocument uiDoc = upload data. Application. ActiveUIDocument;
Document doc = uiDoc. Document;
Selection sel = uiDoc. Selection;
Autodesk. Revit. Creation. Application aCreate = export data. Application. Application. Create;

Transaction ts = Transaction (doc ,);
Ts. Start ();
Reference refFloor = sel. PickObject (ObjectType. Element ,);
Floor floor = doc. GetElement (refFloor) Floor;
Face face = FindFloorFace (floor );
CurveArray curves = aCreate. NewCurveArray ();
Reference refDuct = sel. PickObject (ObjectType. Element ,);
Duct duct = doc. GetElement (refDuct) Duct;
Curve curve = FindDuctCurve (duct );
XYZ xyz = FindFaceCurve (face, curve );

XYZ xyz1 = xyz + XYZ (,,)*/;
XYZ xyz2 = xyz + XYZ (,-,)*/;
XYZ xyz3 = xyz + XYZ (-,-,)*/;
XYZ xyz4 = xyz + XYZ (-,,)*/;
Curve c1 = aCreate. NewLine (xyz1, xyz2 ,);
Curve c2 = aCreate. NewLine (xyz2, xyz3 ,);
Curve c3 = aCreate. NewLine (xyz3, xyz4 ,);
Curve c4 = aCreate. NewLine (xyz4, xyz1 ,);
Curves. Append (c1 );
Curves. Append (c2 );
Curves. Append (c3 );
Curves. Append (c4 );

Double startAngle = 0;
Double midAngle = Math. PI;
Double endAngle = 2 * Math. PI;

XYZ xAxis = XYZ. BasisX;
XYZ yAxis = XYZ. BasisY;
Double radius = 180/304 .8;

Arc arc1 = aCreate. NewArc (xyz, radius, startAngle, midAngle, xAxis, yAxis );
Arc arc2 = aCreate. NewArc (xyz, radius, midAngle, endAngle, xAxis, yAxis );

Curves. Append (arc1 );
Curves. Append (arc2 );

Doc. Create. NewOpening (floor, curves ,);

Ts. Commit ();

Result. Succeeded;
}
XYZ FindFaceCurve (Face face, Curve curve)
{
IntersectionResultArray intersectionR = IntersectionResultArray (); SetComparisonResult comparisonR; comparisonR = face. Intersect (curve, intersectionR );
XYZ intersectionResult =; (SetComparisonResult. Disjoint! = ComparisonR ){
(! IntersectionR. IsEmpty)
{
IntersectionResult = intersectionR. get_Item (). XYZPoint;
}
}
IntersectionResult;
}
Curve FindDuctCurve (Duct duct)
{
IList <XYZ> list = List <XYZ> ();
ConnectorSetIterator csi = duct. ConnectorManager. Connectors. ForwardIterator ();
(Csi. MoveNext ())
{
Connector conn = csi. Current Connector;
List. Add (conn. Origin );
}
Curve curve = Line. get_Bound (list. ElementAt (), list. ElementAt () Curve;
Curve. MakeUnbound ();
Curve;
}
Face FindFloorFace (Floor floor)
{
Face normalFace =;
Options opt = Options ();
Opt. ComputeReferences =;
Opt. DetailLevel = Autodesk. Revit. DB. DetailLevels. Medium;
GeometryElement e = floor. get_Geometry (opt );
IEnumerator <GeometryObject> enm = e. GetEnumerator ();
While (enm. MoveNext ())
{
Solid solid = enm. Current as Solid;
}
(GeometryObject obj e. Objects ){
Solid solid = obj Solid;
(Solid! = & Solid. Faces. Size>)
{
(Face face solid. Faces)
{
PlanarFace pf = face PlanarFace;
(Pf! =)
{
(Pf. Normal. AngleTo (XYZ (,-) <){
NormalFace = face;
}
}
}
}
}
NormalFace;
}
}
Url:

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.