Exemplo n.º 1
0
        //族实例化,创建族并对其进行旋转
        private FamilyInstance CreateFamlyInstance(DG.Point DGpoint, DG.Curve curve, FamilySymbol FamilySymbol, ExternalCommandData commandData)
        {
            UIDocument uiDoc = commandData.Application.ActiveUIDocument; //取得当前活动文档

            XYZ point = DGpoint.ToRevitType(false);                      //dynamo转Revit

            FamilyInstance familyInstance = uiDoc.Document.Create.NewFamilyInstance(point, FamilySymbol, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
            LocationPoint  locationPoint  = familyInstance.Location as LocationPoint;//自适应族基点
            XYZ            axisP          = new XYZ(point.X, point.Y, point.Z + 100);

            Autodesk.Revit.DB.Line axis = Autodesk.Revit.DB.Line.CreateBound(point, axisP);//旋转轴

            //计算旋转角度
            double ratio = curve.ParameterAtPoint(DGpoint);

            DG.Vector vector = curve.TangentAtParameter(ratio);

            MessageBox.Show(vector.ToString());

            DG.Vector vector1 = DG.Vector.ByCoordinates(vector.X, vector.Y, 0);//三维切向量的平面向量
            DG.Vector vectorY = DG.Vector.ByCoordinates(0, 1, 0);
            double    angle   = vector1.AngleWithVector(vectorY) / 180 * Math.PI;

            MessageBox.Show(angle.ToString());
            //locationPoint.Rotate(axis, angle);//旋转横梁
            ElementTransformUtils.RotateElement(uiDoc.Document, familyInstance.Id, axis, -angle);

            return(familyInstance);
        }
Exemplo n.º 2
0
        private double SelectPoint(ExternalCommandData commandData)
        {
            Document    revitDoc = commandData.Application.ActiveUIDocument.Document; //取得文档
            Application revitApp = commandData.Application.Application;               //取得应用程序
            UIDocument  uiDoc    = commandData.Application.ActiveUIDocument;          //取得当前活动文档

            Selection sel        = uiDoc.Selection;
            Reference ref1       = sel.PickObject(ObjectType.Element, "选择一条模型线");
            Element   elem       = revitDoc.GetElement(ref1);
            ModelLine modelLine1 = elem as ModelLine;

            Autodesk.Revit.DB.Curve curve1;
            //做一个判断,判断其是否为ModelNurbSpline
            if (modelLine1 == null)
            {
                ModelNurbSpline modelNurbSpline = elem as ModelNurbSpline;
                curve1 = modelNurbSpline.GeometryCurve;
            }
            else
            {
                curve1 = modelLine1.GeometryCurve;
            }


            Reference ref2 = sel.PickObject(ObjectType.Element, "选择一条模型线");

            elem = revitDoc.GetElement(ref2);
            ModelLine modelLine2 = elem as ModelLine;

            Autodesk.Revit.DB.Curve curve2;
            //做一个判断,判断其是否为ModelNurbSpline
            if (modelLine2 == null)
            {
                ModelNurbSpline modelNurbSpline = elem as ModelNurbSpline;
                curve2 = modelNurbSpline.GeometryCurve;
            }
            else
            {
                curve2 = modelLine2.GeometryCurve;
            }


            //删除第二条选中的线
            uiDoc.Document.Delete(elem.Id);
            //求交点
            curve1.Intersect(curve2, out IntersectionResultArray intersectionResultArray);
            XYZ pointIntersect = intersectionResultArray.get_Item(0).XYZPoint;

            //交点和线都转化为dynamo的点和线
            DG.Point dgP   = pointIntersect.ToPoint(false);
            DG.Curve dgC   = curve1.ToProtoType(false);
            double   ratio = dgC.ParameterAtPoint(dgP);

            return(ratio);
        }
Exemplo n.º 3
0
 /// <summary>
 /// This function creates a list of cut planes;
 /// Initial cut plane is normal plane to curve at given origin
 /// and the rest of the planes are generated from the initial plane
 /// and the given spacing.
 /// </summary>
 /// <param name="curve"></param>
 /// <param name="origin"></param>
 /// <returns>List containing all cut planes</returns>
 public List<Plane> GenerateCutPlanes(Curve curve, double origin)
 {
     List<Plane> Planes = new List<Plane>();
     if (origin > 0) Planes.Add(Plane.ByOriginNormal(curve.PointAtParameter(origin), curve.TangentAtParameter(origin)));
     else Planes.Add(Plane.ByOriginNormal((Point)Solid.Intersect(curve)[0], curve.TangentAtParameter(curve.ParameterAtPoint((Point)Solid.Intersect(curve)[0]))));
     return Planes;
 }
Exemplo n.º 4
0
        /// <summary>
        /// Constructs a point by projecting a point on a curve which which closest to the curve
        /// </summary>
        /// <param name="curve">the curve on which the projection is to be made.</param>
        /// <returns></returns>
        public Point Project(Curve curve)
        {
            if (curve == null)
            {
                throw new ArgumentNullException("curve");
            }

            var pt = curve.Project(this);
            pt.Context = curve;
            double param = curve.ParameterAtPoint(pt);
            pt.T = param;
            pt.Distance = curve.DistanceAtParameter(param);
            pt.ReferencePoint = this;
            pt.Persist();
            return pt;
        }