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: