public static void DrawReferencePoint(RenderDescription description, object obj)
        {
            ReferencePoint point = obj as ReferencePoint;

            if (point == null)
            {
                return;
            }

            description.points.Add(new Point3D(point.GetCoordinateSystem().Origin.X,
                                               point.GetCoordinateSystem().Origin.Y,
                                               point.GetCoordinateSystem().Origin.Z));
        }
        void CreateChainWithTwoFixedEnds(ReferencePoint pt1, ReferencePoint pt2, int numX, double springDampening, double springRestLength, double springConstant, double mass)
        {
            Particle p;
            Particle p2;
            XYZ partXYZ1 = pt1.Position;
            XYZ partXYZ2 = pt2.Position;
            XYZ lineVec = partXYZ2 - partXYZ1;

            double stepSize = lineVec.GetLength() / numX;

            for (int j = 0; j < numX; j++)//step along curve and evaluate at each step, making sure to thread in the existing fixed parts
            {
                double curveParam = 0;
                XYZ pointOnLine;

                if (j == 0) // starting point
                {
                    p = particleSystem.makeParticle(mass, partXYZ1, true); // make first particle fixed
                }
                else if(j > 0 && j < numX-1) // middle points
                {
                    pointOnLine = partXYZ1 + lineVec.Normalize() * (j * stepSize);
                    p = particleSystem.makeParticle(mass, pointOnLine, false); // make a new particle along curve at j-th point on line
                    p2 = particleSystem.getParticle(j - 1);
                    particleSystem.makeSpring(p, p2, springRestLength, springConstant, springDampening);//make a new spring and connect it to the last-made point
                }
                else //last point - fixed
                {
                    p = particleSystem.getParticle(j - 1);
                    p2 = particleSystem.makeParticle(mass, partXYZ2, true); // make last particle fixed
                    particleSystem.makeSpring(p, p2, springRestLength, springConstant, springDampening);//make a new spring and connect the j-th point to the fixed point
                }
            }
        }
        void CreateChainWithOneFixedEnd(ReferencePoint pt1, int numX, double springDampening, double springRestLength, double springConstant, double mass)
        {
            Particle p;

            XYZ partXYZ1 = pt1.Position;
            Particle fixedPart1 = particleSystem.makeParticleFromElementID(pt1.Id, mass, pt1.Position, true); // true means 'make fixed'

            XYZ partXYZ2 = partXYZ1 + new XYZ(10, 0, 0);
            Line tempLine = this.UIDocument.Application.Application.Create.NewLineBound(partXYZ1, partXYZ2);

            for (int j = 0; j < numX; j++)//step along curve and evaluate at each step, making sure to thread in the existing fixed parts
            {
                double curveParam = 0;
                XYZ pointOnLine;

                if (j == 0) // starting point
                {
                    curveParam = (double)j / numX;
                    pointOnLine = tempLine.Evaluate(curveParam, true);
                    p = particleSystem.makeParticle(mass, pointOnLine, true); // make first particle fixed
                }
                else // middle points
                {
                    curveParam = (double)j / numX;
                    pointOnLine = tempLine.Evaluate(curveParam, true);
                    p = particleSystem.makeParticle(mass, pointOnLine, false); // make a new particle along curve at j-th point on line
                    particleSystem.makeSpring(particleSystem.getParticle((j - 1)), p, springRestLength, springConstant, springDampening);//make a new spring and connect it to the last-made point
                }
            }
        }
        // geometric test, fairly expensive.
        public ReferencePoint FindRefPointWithCoincidentXYZ(ReferencePoint rp)
        {
            Element el;
            ReferencePoint rp2;

            foreach (ElementId id in this.Elements) // compare to inputed points
            {
                dynUtils.TryGetElement(id, out el);
                rp2 = el as ReferencePoint;

                if (rp != null && rp2 != null && rp.Position.IsAlmostEqualTo(rp2.Position))// note this is not gauranteed to be unique. there may be mulitple coincident refpoints and this utill will only return the first found
                {
                    return rp2; // found a match
                }
            }

            return null;
        }
Example #5
0
        public override Value Evaluate(FSharpList<Value> args)
        {
            Autodesk.LibG.Geometry geometry = (Autodesk.LibG.Geometry)((Value.Container)args[0]).Item;

            Autodesk.LibG.Point point = geometry as Autodesk.LibG.Point;

            if (point != null)
            {
                XYZ xyz = new XYZ(point.x(), point.y(), point.z());

                if (_revitPoint == null)
                {
                    _revitPoint = this.UIDocument.Document.FamilyCreate.NewReferencePoint(xyz);
                    this.Elements.Add(_revitPoint.Id);
                }
                else
                {
                    _revitPoint.Position = xyz;
                }

                return Value.NewContainer(_revitPoint);
            }

            Autodesk.LibG.Line line = geometry as Autodesk.LibG.Line;

            if (line != null)
            {
                ReferencePointArray refPoints = new ReferencePointArray();

                Autodesk.LibG.Point start_point = line.start_point();
                Autodesk.LibG.Point end_point = line.end_point();

                if (_curveByPoints == null)
                {
                    _startPoint = ReferencePointFromPoint(start_point);
                    _endPoint = ReferencePointFromPoint(end_point);

                    refPoints.Append(_startPoint);
                    refPoints.Append(_endPoint);

                    _curveByPoints = this.UIDocument.Document.FamilyCreate.NewCurveByPoints(refPoints);
                    this.Elements.Add(_curveByPoints.Id);
                }
                else
                {
                    _startPoint.Position = new XYZ(start_point.x(), start_point.y(), start_point.z());
                    _endPoint.Position = new XYZ(end_point.x(), end_point.y(), end_point.z());
                }

                return Value.Container.NewContainer(_curveByPoints);
            }

            //Autodesk.LibG.BSplineCurve bspline = geometry as Autodesk.LibG.BSplineCurve;

            //if (bspline != null)
            //{
            //    ReferencePointArray refPoints = new ReferencePointArray();

            //    for (int i = 0; i <= 15; ++i)
            //    {
            //        double param = (double)i / 15.0;
            //        Autodesk.LibG.Point p = bspline.point_at_parameter(param);
            //        ReferencePoint refPoint = ReferencePointFromPoint(p);
            //        refPoints.Append(refPoint);
            //    }

            //    if (_curveByPoints == null)
            //    {
            //        _curveByPoints = this.UIDocument.Document.FamilyCreate.NewCurveByPoints(refPoints);
            //        this.Elements.Add(_curveByPoints.Id);
            //    }
            //    else
            //    {
            //        _curveByPoints.SetPoints(refPoints);
            //    }

            //    foreach (ReferencePoint refPoint in refPoints)
            //    {
            //        refPoint.Visible = false;
            //    }

            //    return Value.Container.NewContainer(_curveByPoints);
            //}

            return Value.Container.NewContainer(null);

            // Surface

            // Solid
        }