Created
June 13, 2020 12:55
-
-
Save chuongmep/f30210a4859a574cde688c787ab659e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static Autodesk.DesignScript.Geometry.Solid CreateCutPlaneSolid(global::Revit.Elements.Element planv) | |
{ | |
View planView = planv.InternalElement as View; | |
BoundingBoxXYZ bbActiview = planView.get_BoundingBox(null); | |
Plane planePlanView = planView.SketchPlane.GetPlane(); | |
PlanViewRange viewRange = (planView as ViewPlan).GetViewRange(); | |
double cutPlaneHeight = viewRange.GetOffset(PlanViewPlane.CutPlane); | |
XYZ pt0 = new XYZ(bbActiview.Min.X, bbActiview.Min.Y, bbActiview.Min.Z); | |
XYZ pt1 = new XYZ(bbActiview.Max.X, bbActiview.Min.Y, bbActiview.Min.Z); | |
XYZ pt2 = new XYZ(bbActiview.Max.X, bbActiview.Max.Y, bbActiview.Min.Z); | |
XYZ pt3 = new XYZ(bbActiview.Min.X, bbActiview.Max.Y, bbActiview.Min.Z); | |
XYZ pt00 = ProjectOnto(planePlanView, pt0); | |
XYZ pt11 = ProjectOnto(planePlanView, pt1); | |
XYZ pt22 = ProjectOnto(planePlanView, pt2); | |
XYZ pt33 = ProjectOnto(planePlanView, pt3); | |
Line edge00 = Line.CreateBound(pt00, pt11); | |
Line edge11 = Line.CreateBound(pt11, pt22); | |
Line edge22 = Line.CreateBound(pt22, pt33); | |
Line edge33 = Line.CreateBound(pt33, pt00); | |
List<Curve> edges0 = new List<Curve>(); | |
edges0.Add(edge00); | |
edges0.Add(edge11); | |
edges0.Add(edge22); | |
edges0.Add(edge33); | |
CurveLoop baseLoop0 = CurveLoop.Create(edges0); | |
List<CurveLoop> loopList0 = new List<CurveLoop>(); | |
loopList0.Add(baseLoop0); | |
Solid preTransformSolid = | |
GeometryCreationUtilities.CreateExtrusionGeometry(loopList0, | |
XYZ.BasisZ, cutPlaneHeight); | |
//transform | |
Solid transformSolid = SolidUtils.CreateTransformed(preTransformSolid, | |
bbActiview.Transform); | |
return transformSolid.ToProtoType(); | |
} | |
[IsVisibleInDynamoLibrary(false)] | |
public static XYZ ProjectOnto(this Plane plane, XYZ p) | |
{ | |
double d = plane.SignedDistanceTo(p); | |
XYZ q = p - d * plane.Normal; | |
return q; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment