Esempio n. 1
0
        public static Dictionary <string, object> CurveSinusoidalPointsWithVoxel(
            Autodesk.DesignScript.Geometry.Curve _Curve,
            VoxelImage Voxel,
            double WaveLength = 5.0,
            double Amplitude  = 1.0,
            double Resolution = 2.0)
        {
            VoxelChannel _VoxelChannel = Voxel.GetChannel(VoxelImageLayout.SHAPECHANNEL);

            double n     = (_Curve.Length / WaveLength) * 4 * Resolution;
            double _Span = _Curve.Length / n;
            List <Autodesk.DesignScript.Geometry.Point> points = new List <Autodesk.DesignScript.Geometry.Point>();
            List <double> ks = new List <double>();

            for (int i = 0; i < n; i++)
            {
                Autodesk.DesignScript.Geometry.Plane pl = _Curve.PlaneAtParameter(_Curve.ParameterAtSegmentLength(i * _Span));
                Autodesk.DesignScript.Geometry.Point p  = _Curve.PointAtSegmentLength(i * _Span);
                double FieldValue = V2GVoxel.GetVoxelFieldValue(_VoxelChannel, p.X, p.Y, p.Z);

                double k = FieldValue * Amplitude * Math.Sin(i * _Span * Math.PI * 2 / WaveLength + Math.PI * 2);

                points.Add((Autodesk.DesignScript.Geometry.Point)p.Translate(pl.YAxis, k));
                ks.Add(k);
            }

            return(new Dictionary <string, object>
            {
                { "Points", points },
                { "k", ks }
            });
        }
Esempio n. 2
0
        public static Dictionary <string, object> CurveSinusoidalPoints(
            Autodesk.DesignScript.Geometry.Curve _Curve,
            double WaveLength = 5.0,
            double Amplitude  = 1.0,
            double Resolution = 2.0)
        {
            double n     = (_Curve.Length / WaveLength) * 4 * Resolution;
            double _Span = _Curve.Length / n;
            List <Autodesk.DesignScript.Geometry.Point> points = new List <Autodesk.DesignScript.Geometry.Point>();
            List <double> ks = new List <double>();

            for (int i = 0; i < n; i++)
            {
                double k = Amplitude * Math.Sin(i * _Span * Math.PI * 2 / WaveLength + Math.PI * 2);
                Autodesk.DesignScript.Geometry.Plane pl = _Curve.PlaneAtParameter(_Curve.ParameterAtSegmentLength(i * _Span));
                Autodesk.DesignScript.Geometry.Point p  = _Curve.PointAtSegmentLength(i * _Span);
                points.Add((Autodesk.DesignScript.Geometry.Point)p.Translate(pl.YAxis, k));
                ks.Add(k);
            }

            return(new Dictionary <string, object>
            {
                { "Points", points },
                { "k", ks }
            });
        }
Esempio n. 3
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            // 【利用Dynamo库创建弧线】
            DyGeometry.Point point1 = DyGeometry.Point.ByCoordinates(0, 0, 0);
            DyGeometry.Point point2 = DyGeometry.Point.ByCoordinates(0, 5, 3);
            DyGeometry.Point point3 = DyGeometry.Point.ByCoordinates(0, 10, 0);
            DyGeometry.Arc   arc1   = DyGeometry.Arc.ByThreePoints(point1, point2, point3);
            // 【利用Dynamo创建直线】
            DyGeometry.Point point4 = DyGeometry.Point.ByCoordinates(10, 10, 0);
            DyGeometry.Point point5 = DyGeometry.Point.ByCoordinates(10, 0, 0);
            DyGeometry.Line  line1  = DyGeometry.Line.ByStartPointEndPoint(point4, point5);
            // 【利用Dynamo在直线和弧线之间创建连接线】
            DyGeometry.Curve curve1 = DyGeometry.Curve.ByBlendBetweenCurves(arc1, line1);
            // 【利用Dynamo获取生成的连接线上的某个点】
            DyGeometry.Point outPoint = curve1.PointAtSegmentLength(3);
            // 【转化为Revit的坐标点】
            XYZ result = new XYZ(outPoint.X / 0.3048, outPoint.Y / 0.3048, outPoint.Z / 0.3048);

            // 【输出生成的结果】
            TaskDialog.Show("Result", $"X:{result.X.ToString("0.00")}-Y:{result.Y.ToString("0.00")}-Z:{result.Z.ToString("0.00")}");
            return(Result.Succeeded);
        }
Esempio n. 4
0
        Result IExternalCommand.Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Document    revitDoc = commandData.Application.ActiveUIDocument.Document; //取得文档
            Application revitApp = commandData.Application.Application;               //取得应用程序
            UIDocument  uiDoc    = commandData.Application.ActiveUIDocument;          //取得当前活动文档

            Document document = commandData.Application.ActiveUIDocument.Document;

            Window1 window1 = new Window1();

            //载入族
            FamilySymbol familySymbol;

            using (Transaction tran = new Transaction(uiDoc.Document))
            {
                tran.Start("载入族");

                //载入弦杆族
                string file = @"C:\Users\zyx\Desktop\2RevitArcBridge\CrossBeam\CrossBeam\source\crossBeam.rfa";
                familySymbol = loadFaimly(file, commandData);
                familySymbol.Activate();

                tran.Commit();
            }


            //把这组模型线通过获取首尾点,生成dynamo里的curve
            List <XYZ> ps = new List <XYZ>();

            using (Transaction transaction = new Transaction(uiDoc.Document))
            {
                transaction.Start("选取模型线生成Curve");

                Selection         sel        = uiDoc.Selection;
                IList <Reference> modelLines = sel.PickObjects(ObjectType.Element, "选一组模型线");

                foreach (Reference reference in modelLines)
                {
                    Element   elem            = revitDoc.GetElement(reference);
                    ModelLine modelLine       = elem as ModelLine;
                    Autodesk.Revit.DB.Curve c = modelLine.GeometryCurve;

                    ps.Add(c.GetEndPoint(0));
                    ps.Add(c.GetEndPoint(1));
                }

                for (int i = ps.Count - 1; i > 0; i--)
                {
                    XYZ p1 = ps[i];
                    XYZ p2 = ps[i - 1];

                    //注意此处重合点有一个闭合差
                    if (p1.DistanceTo(p2) < 0.0001)
                    {
                        ps.RemoveAt(i);
                    }
                }

                transaction.Commit();
            }


            //做一个revit和dynamo点的转换
            DG.CoordinateSystem coordinateSystem = DG.CoordinateSystem.ByOrigin(0, 0, 0);//标准坐标系
            List <DG.Point>     DGps             = new List <DG.Point>();

            foreach (XYZ p in ps)
            {
                DGps.Add(p.ToPoint(false));
            }

            DG.PolyCurve polyCurve = DG.PolyCurve.ByPoints(DGps);
            DG.Curve     curve     = polyCurve as DG.Curve;

            List <DG.Point> DGCBps      = new List <DG.Point>();//横梁的放置点位列表
            double          StartLength = 0;

            if (window1.ShowDialog() == true)
            {
                //窗口打开并停留,只有点击按键之后,窗口关闭并返回true
            }


            //按键会改变window的属性,通过对属性的循环判断来实现对按键的监测
            while (!window1.Done)
            {
                //选择起点
                if (window1.StartPointSelected)
                {
                    using (Transaction transaction = new Transaction(uiDoc.Document))
                    {
                        transaction.Start("选择起点");

                        double   r1   = SelectPoint(commandData);
                        DG.Point dgp1 = curve.PointAtParameter(r1);
                        DGCBps.Add(dgp1);
                        StartLength = curve.SegmentLengthAtParameter(r1);


                        transaction.Commit();
                    }

                    //2、重置window1.StartPointSelected

                    window1.StartPointSelected = false;
                }

                if (window1.ShowDialog() == true)
                {
                    //窗口打开并停留,只有点击按键之后,窗口关闭并返回true
                }
            }



            //在这里根据间距获取到各个点
            for (int i = 1; i < window1.cbNumber; i++)
            {
                double   L     = StartLength + window1.cbDistance * i;
                DG.Point point = curve.PointAtSegmentLength(L);
                DGCBps.Add(point);
                MessageBox.Show(i.ToString());
            }

            List <FamilyInstance> instances = new List <FamilyInstance>();

            using (Transaction transaction = new Transaction(uiDoc.Document))
            {
                transaction.Start("创建横梁实例");

                foreach (DG.Point p in DGCBps)
                {
                    FamilyInstance familyInstance;
                    familyInstance = CreateFamlyInstance(p, curve, familySymbol, commandData);
                    instances.Add(familyInstance);
                }


                transaction.Commit();
            }


            //给每个族实例设置参数
            using (Transaction transaction = new Transaction(uiDoc.Document))
            {
                transaction.Start("族实例参数设置");

                foreach (FamilyInstance instance in instances)
                {
                    double h1 = instance.LookupParameter("l1/2").AsDouble();
                    instance.LookupParameter("l1/2").Set(window1.l1 / 2);
                    instance.LookupParameter("l2").Set(window1.l2);

                    //instance.LookupParameter("h1").Set(window1.l1);
                    //instance.LookupParameter("h2").Set(window1.l1);
                }
                transaction.Commit();
            }

            return(Result.Succeeded);
        }