예제 #1
0
        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application
        /// which contains data related to the command,
        /// such as the application object and active view.</param>
        /// <param name="message">A message that can be set by the external application
        /// which will be displayed if a failure or cancellation is returned by
        /// the external command.</param>
        /// <param name="elements">A set of elements to which the external application
        /// can add elements that are to be highlighted in case of failure or cancellation.</param>
        /// <returns>Return the status of the external command.
        /// A result of Succeeded means that the API external method functioned as expected.
        /// Cancelled can be used to signify that the user cancelled the external operation
        /// at some point. Failure should be returned if the application is unable to proceed with
        /// the operation.</returns>
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Autodesk.Revit.ApplicationServices.Application app = commandData.Application.Application;
            Document doc = commandData.Application.ActiveUIDocument.Document;

            Transaction transaction = new Transaction(doc, "PointsOnCurve");

            transaction.Start();
            XYZ start = new XYZ(0, 0, 0);
            XYZ end   = new XYZ(50, 50, 0);

            Autodesk.Revit.DB.Line line = Autodesk.Revit.DB.Line.CreateBound(start, end);
            Plane       geometryPlane   = Plane.CreateByNormalAndOrigin(XYZ.BasisZ, start);
            SketchPlane skplane         = SketchPlane.Create(doc, geometryPlane);
            ModelCurve  modelcurve      = doc.FamilyCreate.NewModelCurve(line, skplane);

            for (double i = 0.1; i <= 1; i = i + 0.1)
            {
                PointLocationOnCurve locationOnCurve = new PointLocationOnCurve(PointOnCurveMeasurementType.NormalizedCurveParameter, i, PointOnCurveMeasureFrom.Beginning);
                PointOnEdge          poe             = app.Create.NewPointOnEdge(modelcurve.GeometryCurve.Reference, locationOnCurve);
                ReferencePoint       rp2             = doc.FamilyCreate.NewReferencePoint(poe);
            }
            transaction.Commit();

            return(Result.Succeeded);
        }
예제 #2
0
        Stream(ArrayList data, PointElementReference ptElemRef)
        {
            data.Add(new Snoop.Data.ClassSeparator(typeof(PointElementReference)));

            PointOnEdge ptOnEdge = ptElemRef as PointOnEdge;

            if (ptOnEdge != null)
            {
                Stream(data, ptOnEdge);
                return;
            }

            PointOnEdgeEdgeIntersection ptOnEdgeEdgeInt = ptElemRef as PointOnEdgeEdgeIntersection;

            if (ptOnEdgeEdgeInt != null)
            {
                Stream(data, ptOnEdgeEdgeInt);
                return;
            }

            PointOnEdgeFaceIntersection ptOnEdgeFaceInt = ptElemRef as PointOnEdgeFaceIntersection;

            if (ptOnEdgeFaceInt != null)
            {
                Stream(data, ptOnEdgeFaceInt);
                return;
            }

            PointOnFace ptOnFace = ptElemRef as PointOnFace;

            if (ptOnFace != null)
            {
                Stream(data, ptOnFace);
                return;
            }

            //PointOnSketch ptOnSketch = ptElemRef as PointOnSketch;
            //if (ptOnSketch != null) {
            //    Stream(data, ptOnSketch);
            //    return;
            //}

            //PointRelativeToPoint ptRelToPt = ptElemRef as PointRelativeToPoint;
            //if (ptRelToPt != null) {
            //    Stream(data, ptRelToPt);
            //    return;
            //}
        }
        /// <summary>
        /// Find the exterior edge with the closest point on the edge to the query position.
        /// </summary>
        /// <param name="pos">The query position.</param>
        /// <returns>A triangle interpolant that will evaluate to the interpolation between the two edge endpoints. Returns null if there are no exterior edges.</returns>
        /// <remarks>
        /// The third triangle vertex always has index 0 and weight 0.
        /// </remarks>
        private Interpolant FindClosestExteriorEdge(Vector3 pos)
        {
            if (exteriorEdges.Count == 0)
            {
                if (vertices.Count == 5)
                {
                    /// There is a single real vertex, so no exterior edges.
                    /// That's okay, the single vertex wins all the weight.
                    Interpolant singleVert = new Interpolant();
                    singleVert.idx[0]     = singleVert.idx[1] = singleVert.idx[2] = 4;
                    singleVert.weights[0] = 1.0f;
                    singleVert.weights[1] = singleVert.weights[2] = 0.0f;
                    return(singleVert);
                }
                return(null);
            }
            int   closestEdge     = -1;
            float closestDistance = float.MaxValue;
            float closestParm     = 0.0f;

            for (int i = 0; i < exteriorEdges.Count; ++i)
            {
                PointOnEdge point = PositionOnEdge(exteriorEdges[i], pos);

                if (point.distanceSqr < closestDistance)
                {
                    closestEdge     = i;
                    closestDistance = point.distanceSqr;
                    closestParm     = point.parm;
                }
            }
            Debug.Assert(closestEdge >= 0, "If there are any edges, there must be a closest one.");
            Edge        edge = exteriorEdges[closestEdge];
            Interpolant bary = new Interpolant();

            bary.idx[0]     = edge.idx0;
            bary.idx[1]     = edge.idx1;
            bary.idx[2]     = 0;
            bary.weights[0] = 1.0f - closestParm;
            bary.weights[1] = closestParm;
            bary.weights[2] = 0;

            return(bary);
        }
예제 #4
0
 Stream(ArrayList data, PointOnEdge ptOnEdge)
 {
     data.Add(new Snoop.Data.ClassSeparator(typeof(PointOnEdge)));
     data.Add(new Snoop.Data.Object("PointLocationOnCurve", ptOnEdge.LocationOnCurve));
     data.Add(new Snoop.Data.Object("Reference", ptOnEdge.GetEdgeReference()));
 }
예제 #5
0
 Stream(ArrayList data, PointOnEdge ptOnEdge)
 {
    data.Add(new Snoop.Data.ClassSeparator(typeof(PointOnEdge)));
    data.Add(new Snoop.Data.Object("PointLocationOnCurve", ptOnEdge.LocationOnCurve));
    data.Add(new Snoop.Data.Object("Reference", ptOnEdge.GetEdgeReference()));
 }