예제 #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);
        }
예제 #2
0
        Geo.Line GetMemberLineR(int faceIndex, int edgeIndex, bool rightHand)
        {
            Geo.Point p1 = mesh.faces[faceIndex].vertices[edgeIndex].ToPoint();
            Geo.Point p2 = mesh.faces[faceIndex].vertices[(edgeIndex + 1) % 4].ToPoint();
            Geo.Point p3 = mesh.faces[faceIndex].vertices[(edgeIndex + 2) % 4].ToPoint();

            Geo.Point memberPoint     = GetMemberPointOnEdge(faceIndex, edgeIndex, rightHand);
            Geo.Point nextMemberPoint = GetMemberPointOnEdge(faceIndex, (edgeIndex + 1) % 4, rightHand);

            Geo.Vector v1 = Geo.Vector.ByTwoPoints(p2, p1);
            Geo.Vector v2 = Geo.Vector.ByTwoPoints(p2, p3);

            double l = p2.DistanceTo(nextMemberPoint);
            double x = p2.DistanceTo(memberPoint);
            double a = 90 - v1.AngleWithVector(v2);

            a = (a * (Math.PI / 180));

            double d1 = x / (Math.Tan(a));
            double d2 = (x / Math.Sin(a)) - l;
            double d3 = Math.Cos(a);

            double length = d1 - (d2 / d3);

            Geo.Vector direction = v1.Cross(v1.Cross(v2));
            direction = direction.Reverse();

            var returnLine = Geo.Line.ByStartPointDirectionLength(memberPoint, direction, length);

            // Dispose

            /*{
             *  p1.Dispose();
             *  p2.Dispose();
             *  p3.Dispose();
             *  memberPoint.Dispose();
             *  nextMemberPoint.Dispose();
             *  v1.Dispose();
             *  v2.Dispose();
             *  direction.Dispose();
             * }*/
            return(returnLine);
        }