コード例 #1
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            string inputType = "";

            if (!DA.GetData("SpeckleObjectType", ref inputType))
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "No type specified.");
                return;
            }

            SpeckleObject inputObject = null;

            if (!DA.GetData("SpeckleObject", ref inputObject))
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "No input object.");
                return;
            }

            // Try to find type in SpeckleInitializer
            Type objType = SpeckleCore.SpeckleInitializer.GetTypes().FirstOrDefault(t => t.Name == inputType);

            if (objType == null)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Could not find SpeckleObject of type " + inputType + ".");
                return;
            }

            SpeckleObject convertedObject = (SpeckleObject)Activator.CreateInstance(objType);

            // Check to see if one is a subclass of another
            if (!(inputObject.Type.Contains(convertedObject.Type)) && !(convertedObject.Type.Contains(inputObject.Type)))
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "SpeckleObject not convertible to type.");
                return;
            }

            foreach (PropertyInfo p in convertedObject.GetType().GetProperties().Where(p => p.CanWrite))
            {
                PropertyInfo inputProperty = inputObject.GetType().GetProperty(p.Name);
                if (inputProperty != null)
                {
                    p.SetValue(convertedObject, inputProperty.GetValue(inputObject));
                }
            }

            convertedObject.GenerateHash();
            DA.SetData("Result", convertedObject);
        }
コード例 #2
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            var check = ValidateKeys();

            if (check.Item1)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, check.Item2);
                return;
            }

            var myDictionary = new Dictionary <string, object>();

            for (int i = 0; i < Params.Input.Count; i++)
            {
                var key = Params.Input[i].NickName;

                object ghInputProperty = null;
                DA.GetData(i, ref ghInputProperty);

                if (ghInputProperty == null)
                {
                    continue;
                }

                var valueExtract = ghInputProperty.GetType().GetProperty("Value").GetValue(ghInputProperty, null);

                try
                {
                    var tests = valueExtract is IEnumerable <object>;

                    if (valueExtract is IEnumerable <int> || valueExtract is IEnumerable <double> || valueExtract is IEnumerable <string> || valueExtract is IEnumerable <bool> )
                    {
                        myDictionary.Add(key, valueExtract);
                    }
                    else if (valueExtract is IEnumerable <object> )
                    {
                        //valueExtract = ( ( IEnumerable<object> ) valueExtract ).Select( o => o.GetType().GetProperty( "Value" ).GetValue( o, null ) );
                        myDictionary.Add(key, Converter.Serialise(valueExtract as IEnumerable <object>));
                    }

                    else if (valueExtract is System.Collections.IDictionary)
                    {
                        myDictionary.Add(key, valueExtract);
                    }
                    else
                    {
                        if (valueExtract is bool || valueExtract is string || valueExtract is double || valueExtract is int)
                        {
                            myDictionary.Add(key, valueExtract);
                        }
                        else
                        {
                            myDictionary.Add(key, Converter.Serialise(valueExtract));
                        }
                    }
                }
                catch (Exception e)
                {
                    continue;
                }
            }
            var test     = myDictionary;
            var myObject = new SpeckleObject()
            {
                Properties = myDictionary
            };

            myObject.GenerateHash();

            DA.SetData(0, myObject);
            DA.SetData(1, myDictionary);
            //new GH_SpeckleObject()
        }
コード例 #3
0
        // Curve
        public static SpeckleObject ToSpeckle(this NurbsCurve curve)
        {
            var properties = curve.UserDictionary.ToSpeckle(root: curve);

            if (curve.IsArc(Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance))
            {
                Arc        getObj; curve.TryGetArc(out getObj);
                SpeckleArc myObject = getObj.ToSpeckle(); myObject.Properties = properties; myObject.GenerateHash();
                return(myObject);
            }

            if (curve.IsCircle(Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance))
            {
                Circle        getObj; curve.TryGetCircle(out getObj);
                SpeckleCircle myObject = getObj.ToSpeckle(); myObject.Properties = properties; myObject.GenerateHash();
                return(myObject);
            }

            if (curve.IsEllipse(Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance))
            {
                Ellipse        getObj; curve.TryGetEllipse(out getObj);
                SpeckleEllipse myObject = getObj.ToSpeckle(); myObject.Properties = properties; myObject.GenerateHash();
                return(myObject);
            }

            if (curve.IsLinear(Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance) || curve.IsPolyline()) // defaults to polyline
            {
                Polyline      getObj; curve.TryGetPolyline(out getObj);
                SpeckleObject myObject = getObj.ToSpeckle(); myObject.Properties = properties; myObject.GenerateHash();
                return(myObject);
            }

            Polyline poly;

            curve.ToPolyline(0, 1, 0, 0, 0, 0.1, 0, 0, true).TryGetPolyline(out poly);

            SpecklePolyline displayValue;

            if (poly.Count == 2)
            {
                displayValue       = new SpecklePolyline();
                displayValue.Value = new List <double> {
                    poly[0].X, poly[0].Y, poly[0].Z, poly[1].X, poly[1].Y, poly[1].Z
                };
                displayValue.GenerateHash();
            }
            else
            {
                displayValue = poly.ToSpeckle() as SpecklePolyline;
            }

            SpeckleCurve myCurve    = new SpeckleCurve(displayValue);
            NurbsCurve   nurbsCurve = curve.ToNurbsCurve();

            myCurve.Weights  = nurbsCurve.Points.Select(ctp => ctp.Weight).ToList();
            myCurve.Points   = nurbsCurve.Points.Select(ctp => ctp.Location).ToFlatArray().ToList();
            myCurve.Knots    = nurbsCurve.Knots.ToList();
            myCurve.Degree   = nurbsCurve.Degree;
            myCurve.Periodic = nurbsCurve.IsPeriodic;
            myCurve.Rational = nurbsCurve.IsRational;
            myCurve.Domain   = nurbsCurve.Domain.ToSpeckle();
            myCurve.Closed   = nurbsCurve.IsClosed;

            myCurve.Properties = properties;
            myCurve.GenerateHash();

            return(myCurve);
        }
コード例 #4
0
        // Dictionaries & ArchivableDictionaries
        public static Dictionary <string, object> ToSpeckle(this ArchivableDictionary dict, Dictionary <int, string> traversed = null, string path = "root", GeometryBase root = null)
        {
            if (dict.Values.Length == 0)
            {
                return(null);
            }
            if (dict == null)
            {
                return(null);
            }

            if (traversed == null)
            {
                traversed = new Dictionary <int, string>();
                traversed.Add(root.GetHashCode(), "root");
            }

            Dictionary <string, object> myDictionary = new Dictionary <string, object>();

            foreach (var key in dict.Keys)
            {
                var myObj = dict[key];
                if (traversed.ContainsKey(myObj.GetHashCode()))
                {
                    myDictionary.Add(key, new SpeckleAbstract()
                    {
                        _type = "ref", _ref = traversed[myObj.GetHashCode()]
                    });
                    continue;
                }

                traversed.Add(myObj.GetHashCode(), path + "/" + key);

                if (dict[key] is ArchivableDictionary)
                {
                    myDictionary.Add(key, (( ArchivableDictionary )dict[key]).ToSpeckle(traversed, path + "/" + key, root));
                }
                else if (dict[key] is string || dict[key] is double || dict[key] is float || dict[key] is int || dict[key] is SpeckleObject)
                {
                    myDictionary.Add(key, dict[key]);
                }
                else if (dict[key] is IEnumerable)
                {
                    myDictionary.Add(key, "enums not supported yet.");
                }
                else
                {
                    if (dict[key] is GeometryBase)
                    {
                        GeometryBase         obj      = dict[key] as GeometryBase;
                        ArchivableDictionary dictCopy = obj.UserDictionary.Clone();
                        obj.UserDictionary.Clear();
                        SpeckleObject conv = SpeckleCore.Converter.Serialise(obj);
                        conv.Properties = dictCopy.ToSpeckle(traversed, path + "/" + key, root);
                        conv.GenerateHash();
                        myDictionary.Add(key, conv);
                        obj.UserDictionary.ReplaceContentsWith(dictCopy);
                    }
                    else
                    {
                        myDictionary.Add(key, SpeckleCore.Converter.Serialise(dict[key]));
                    }
                }
            }
            return(myDictionary);
        }
コード例 #5
0
        public static List <SpeckleObject> ToSpeckle(this AnalyticalModelSurface mySurface)
        {
            var returnObjects = new List <SpeckleObject>();

            if (!mySurface.IsEnabled())
            {
                return(new List <SpeckleObject>());
            }

            // Get the family
            var myRevitElement = Doc.GetElement(mySurface.GetElementId());

            var type = Structural2DElementType.Generic;

            if (myRevitElement is Floor)
            {
                type = Structural2DElementType.Slab;
            }
            else if (myRevitElement is Wall)
            {
                type = Structural2DElementType.Wall;
            }

            // Voids first

            var voidLoops = mySurface.GetLoops(AnalyticalLoopType.Void);

            foreach (var loop in voidLoops)
            {
                var coor = new List <double>();
                foreach (var curve in loop)
                {
                    var points = curve.Tessellate();

                    foreach (var p in points.Skip(1))
                    {
                        coor.Add(p.X / Scale);
                        coor.Add(p.Y / Scale);
                        coor.Add(p.Z / Scale);
                    }
                }

                returnObjects.Add(new Structural2DVoid(coor.ToArray(), null));
            }

            var polylines = new List <double[]>();

            var loops = mySurface.GetLoops(AnalyticalLoopType.External);

            foreach (var loop in loops)
            {
                var coor = new List <double>();
                foreach (var curve in loop)
                {
                    var points = curve.Tessellate();

                    foreach (var p in points.Skip(1))
                    {
                        coor.Add(p.X / Scale);
                        coor.Add(p.Y / Scale);
                        coor.Add(p.Z / Scale);
                    }
                }

                polylines.Add(coor.ToArray());
            }

            var coordinateSystem = mySurface.GetLocalCoordinateSystem();
            var axis             = coordinateSystem == null ? null : new StructuralAxis(
                new StructuralVectorThree(new double[] { coordinateSystem.BasisX.X, coordinateSystem.BasisX.Y, coordinateSystem.BasisX.Z }),
                new StructuralVectorThree(new double[] { coordinateSystem.BasisY.X, coordinateSystem.BasisY.Y, coordinateSystem.BasisY.Z }),
                new StructuralVectorThree(new double[] { coordinateSystem.BasisZ.X, coordinateSystem.BasisZ.Y, coordinateSystem.BasisZ.Z })
                );

            // Property
            string sectionID = null;

            try
            {
                var mySection = new Structural2DProperty();

                mySection.Name          = Doc.GetElement(myRevitElement.GetTypeId()).Name;
                mySection.ApplicationId = Doc.GetElement(myRevitElement.GetTypeId()).UniqueId;

                if (myRevitElement is Floor)
                {
                    var myFloor = myRevitElement as Floor;
                    mySection.Thickness = myFloor.get_Parameter(BuiltInParameter.FLOOR_ATTR_THICKNESS_PARAM).AsDouble() / Scale;
                }
                else if (myRevitElement is Wall)
                {
                    var myWall = myRevitElement as Wall;
                    mySection.Thickness = myWall.WallType.Width / Scale;
                }

                try
                {
                    // Material
                    Material        myMat    = null;
                    StructuralAsset matAsset = null;

                    if (myRevitElement is Floor)
                    {
                        var myFloor = myRevitElement as Floor;
                        myMat = Doc.GetElement(myFloor.FloorType.StructuralMaterialId) as Material;
                    }
                    else if (myRevitElement is Wall)
                    {
                        var myWall = myRevitElement as Wall;
                        myMat = Doc.GetElement(myWall.WallType.get_Parameter(BuiltInParameter.STRUCTURAL_MATERIAL_PARAM).AsElementId()) as Material;
                    }

                    SpeckleObject myMaterial = null;

                    matAsset = ((PropertySetElement)Doc.GetElement(myMat.StructuralAssetId)).GetStructuralAsset();

                    var matType = myMat.MaterialClass;

                    switch (matType)
                    {
                    case "Concrete":
                        var concMat = new StructuralMaterialConcrete();
                        concMat.ApplicationId         = myMat.UniqueId;
                        concMat.Name                  = Doc.GetElement(myMat.StructuralAssetId).Name;
                        concMat.YoungsModulus         = matAsset.YoungModulus.X;
                        concMat.ShearModulus          = matAsset.ShearModulus.X;
                        concMat.PoissonsRatio         = matAsset.PoissonRatio.X;
                        concMat.Density               = matAsset.Density;
                        concMat.CoeffThermalExpansion = matAsset.ThermalExpansionCoefficient.X;
                        concMat.CompressiveStrength   = matAsset.ConcreteCompression;
                        concMat.MaxStrain             = 0;
                        concMat.AggragateSize         = 0;
                        myMaterial = concMat;
                        break;

                    case "Steel":
                        var steelMat = new StructuralMaterialSteel();
                        steelMat.ApplicationId         = myMat.UniqueId;
                        steelMat.Name                  = Doc.GetElement(myMat.StructuralAssetId).Name;
                        steelMat.YoungsModulus         = matAsset.YoungModulus.X;
                        steelMat.ShearModulus          = matAsset.ShearModulus.X;
                        steelMat.PoissonsRatio         = matAsset.PoissonRatio.X;
                        steelMat.Density               = matAsset.Density;
                        steelMat.CoeffThermalExpansion = matAsset.ThermalExpansionCoefficient.X;
                        steelMat.YieldStrength         = matAsset.MinimumYieldStress;
                        steelMat.UltimateStrength      = matAsset.MinimumTensileStrength;
                        steelMat.MaxStrain             = 0;
                        myMaterial = steelMat;
                        break;

                    default:
                        var defMat = new StructuralMaterialSteel();
                        defMat.ApplicationId = myMat.UniqueId;
                        defMat.Name          = Doc.GetElement(myMat.StructuralAssetId).Name;
                        myMaterial           = defMat;
                        break;
                    }

                    myMaterial.GenerateHash();
                    mySection.MaterialRef = (myMaterial as SpeckleObject).ApplicationId;

                    returnObjects.Add(myMaterial);
                }
                catch { }

                mySection.GenerateHash();

                sectionID = mySection.ApplicationId;

                returnObjects.Add(mySection);
            }
            catch { }

            var counter = 0;

            foreach (var coor in polylines)
            {
                var dummyMesh = new Structural2DElementMesh(coor, null, type, null, null, null);

                var numFaces = 0;
                for (var i = 0; i < dummyMesh.Faces.Count(); i++)
                {
                    numFaces++;
                    i += dummyMesh.Faces[i] + 3;
                }

                var mesh = new Structural2DElementMesh();
                mesh.Vertices    = dummyMesh.Vertices;
                mesh.Faces       = dummyMesh.Faces;
                mesh.Colors      = dummyMesh.Colors;
                mesh.ElementType = type;
                if (sectionID != null)
                {
                    mesh.PropertyRef = sectionID;
                }
                if (axis != null)
                {
                    mesh.Axis = Enumerable.Repeat(axis, numFaces).ToList();
                }
                mesh.Offset = Enumerable.Repeat(0.0, numFaces).Cast <double>().ToList(); //TODO

                mesh.GenerateHash();
                mesh.ApplicationId = mySurface.UniqueId + "_" + (counter++).ToString();

                returnObjects.Add(mesh);
            }

            return(returnObjects);
        }
コード例 #6
0
        public static List <SpeckleObject> ToSpeckle(this AnalyticalModelStick myStick)
        {
            var returnObjects = new List <SpeckleObject>();

            if (!myStick.IsEnabled())
            {
                return(new List <SpeckleObject>());
            }

            // Get the family
            var myFamily = (FamilyInstance)Doc.GetElement(myStick.GetElementId());

            var myElement = new Structural1DElementPolyline
            {
                Value = new List <double>()
            };

            var curves = myStick.GetCurves(AnalyticalCurveType.RigidLinkHead).ToList();

            curves.AddRange(myStick.GetCurves(AnalyticalCurveType.ActiveCurves));
            curves.AddRange(myStick.GetCurves(AnalyticalCurveType.RigidLinkTail));

            foreach (var curve in curves)
            {
                var points = curve.Tessellate();

                if (points.Count == 0)
                {
                    continue;
                }

                if (myElement.Value.Count == 0)
                {
                    myElement.Value.Add(points[0].X / Scale);
                    myElement.Value.Add(points[0].Y / Scale);
                    myElement.Value.Add(points[0].Z / Scale);
                }

                foreach (var p in points.Skip(1))
                {
                    myElement.Value.Add(p.X / Scale);
                    myElement.Value.Add(p.Y / Scale);
                    myElement.Value.Add(p.Z / Scale);
                }
            }

            myElement.ResultVertices = new List <double>(myElement.Value);

            var vertexCount = myElement.Value.Count / 3;

            var coordinateSystem = myStick.GetLocalCoordinateSystem();

            if (coordinateSystem != null)
            {
                myElement.ZAxis = Enumerable.Repeat(new StructuralVectorThree(new double[] { coordinateSystem.BasisZ.X, coordinateSystem.BasisZ.Y, coordinateSystem.BasisZ.Z }), (vertexCount - 1)).ToList();
            }

            try
            {
                var offset1 = myStick.GetOffset(AnalyticalElementSelector.StartOrBase);
                var offset2 = myStick.GetOffset(AnalyticalElementSelector.EndOrTop);

                // TODO: This should be linear interpolation?
                var fillerList = Enumerable.Repeat(new StructuralVectorThree(new double[] { 0, 0, 0 }), (vertexCount - 1) * 2 - 2).ToList();

                myElement.Offset = new List <StructuralVectorThree>()
                {
                    new StructuralVectorThree(new double[] { offset1.X / Scale, offset1.Y / Scale, offset1.Z / Scale })
                }
                .Concat(fillerList)
                .Concat(new List <StructuralVectorThree>()
                {
                    new StructuralVectorThree(new double[] { offset2.X / Scale, offset2.Y / Scale, offset2.Z / Scale })
                }).ToList();
            }
            catch
            {
                try
                {
                    var offset = myStick.GetOffset(AnalyticalElementSelector.Whole);
                    myElement.Offset = Enumerable.Repeat(new StructuralVectorThree(new double[] { offset.X / Scale, offset.Y / Scale, offset.Z / Scale }), (vertexCount - 1) * 2).ToList();
                }
                catch
                {
                }
            }

            if (myStick is AnalyticalModelColumn)
            {
                StructuralVectorBoolSix endRelease1 = null, endRelease2 = null;

                switch (myStick.get_Parameter(BuiltInParameter.STRUCTURAL_BOTTOM_RELEASE_TYPE).AsInteger())
                {
                case 0:
                    endRelease1 = new StructuralVectorBoolSix(new bool[] { false, false, false, false, false, false });
                    break;

                case 1:
                    endRelease1 = new StructuralVectorBoolSix(new bool[] { false, false, false, true, true, true });
                    break;

                case 2:
                    endRelease1 = new StructuralVectorBoolSix(new bool[] { false, false, false, false, true, true });
                    break;

                case 3:
                    endRelease1 = new StructuralVectorBoolSix(new bool[] {
                        myStick.get_Parameter(BuiltInParameter.STRUCTURAL_BOTTOM_RELEASE_FX).AsInteger() == 1,
                        myStick.get_Parameter(BuiltInParameter.STRUCTURAL_BOTTOM_RELEASE_FY).AsInteger() == 1,
                        myStick.get_Parameter(BuiltInParameter.STRUCTURAL_BOTTOM_RELEASE_FZ).AsInteger() == 1,
                        myStick.get_Parameter(BuiltInParameter.STRUCTURAL_BOTTOM_RELEASE_MX).AsInteger() == 1,
                        myStick.get_Parameter(BuiltInParameter.STRUCTURAL_BOTTOM_RELEASE_MY).AsInteger() == 1,
                        myStick.get_Parameter(BuiltInParameter.STRUCTURAL_BOTTOM_RELEASE_MZ).AsInteger() == 1,
                    });
                    break;
                }

                switch (myStick.get_Parameter(BuiltInParameter.STRUCTURAL_TOP_RELEASE_TYPE).AsInteger())
                {
                case 0:
                    endRelease2 = new StructuralVectorBoolSix(new bool[] { false, false, false, false, false, false });
                    break;

                case 1:
                    endRelease2 = new StructuralVectorBoolSix(new bool[] { false, false, false, true, true, true });
                    break;

                case 2:
                    endRelease2 = new StructuralVectorBoolSix(new bool[] { false, false, false, false, true, true });
                    break;

                case 3:
                    endRelease2 = new StructuralVectorBoolSix(new bool[] {
                        myStick.get_Parameter(BuiltInParameter.STRUCTURAL_TOP_RELEASE_FX).AsInteger() == 1,
                        myStick.get_Parameter(BuiltInParameter.STRUCTURAL_TOP_RELEASE_FY).AsInteger() == 1,
                        myStick.get_Parameter(BuiltInParameter.STRUCTURAL_TOP_RELEASE_FZ).AsInteger() == 1,
                        myStick.get_Parameter(BuiltInParameter.STRUCTURAL_TOP_RELEASE_MX).AsInteger() == 1,
                        myStick.get_Parameter(BuiltInParameter.STRUCTURAL_TOP_RELEASE_MY).AsInteger() == 1,
                        myStick.get_Parameter(BuiltInParameter.STRUCTURAL_TOP_RELEASE_MZ).AsInteger() == 1,
                    });
                    break;
                }

                var fillerList = Enumerable.Repeat(new StructuralVectorBoolSix(new bool[] { false, false, false, false, false, false }), (vertexCount - 1) * 2 - 2).ToList();

                myElement.EndRelease = new List <StructuralVectorBoolSix>()
                {
                    endRelease1
                }.Concat(fillerList).Concat(new List <StructuralVectorBoolSix>()
                {
                    endRelease2
                }).ToList();
            }
            else
            {
                StructuralVectorBoolSix endRelease1 = null, endRelease2 = null;

                switch (myStick.get_Parameter(BuiltInParameter.STRUCTURAL_START_RELEASE_TYPE).AsInteger())
                {
                case 0:
                    endRelease1 = new StructuralVectorBoolSix(new bool[] { false, false, false, false, false, false });
                    break;

                case 1:
                    endRelease1 = new StructuralVectorBoolSix(new bool[] { false, false, false, true, true, true });
                    break;

                case 2:
                    endRelease1 = new StructuralVectorBoolSix(new bool[] { false, false, false, false, true, true });
                    break;

                case 3:
                    endRelease1 = new StructuralVectorBoolSix(new bool[] {
                        myStick.get_Parameter(BuiltInParameter.STRUCTURAL_START_RELEASE_FX).AsInteger() == 1,
                        myStick.get_Parameter(BuiltInParameter.STRUCTURAL_START_RELEASE_FY).AsInteger() == 1,
                        myStick.get_Parameter(BuiltInParameter.STRUCTURAL_START_RELEASE_FZ).AsInteger() == 1,
                        myStick.get_Parameter(BuiltInParameter.STRUCTURAL_START_RELEASE_MX).AsInteger() == 1,
                        myStick.get_Parameter(BuiltInParameter.STRUCTURAL_START_RELEASE_MY).AsInteger() == 1,
                        myStick.get_Parameter(BuiltInParameter.STRUCTURAL_START_RELEASE_MZ).AsInteger() == 1,
                    });
                    break;
                }

                switch (myStick.get_Parameter(BuiltInParameter.STRUCTURAL_END_RELEASE_TYPE).AsInteger())
                {
                case 0:
                    endRelease2 = new StructuralVectorBoolSix(new bool[] { false, false, false, false, false, false });
                    break;

                case 1:
                    endRelease2 = new StructuralVectorBoolSix(new bool[] { false, false, false, true, true, true });
                    break;

                case 2:
                    endRelease2 = new StructuralVectorBoolSix(new bool[] { false, false, false, false, true, true });
                    break;

                case 3:
                    endRelease2 = new StructuralVectorBoolSix(new bool[] {
                        myStick.get_Parameter(BuiltInParameter.STRUCTURAL_END_RELEASE_FX).AsInteger() == 1,
                        myStick.get_Parameter(BuiltInParameter.STRUCTURAL_END_RELEASE_FY).AsInteger() == 1,
                        myStick.get_Parameter(BuiltInParameter.STRUCTURAL_END_RELEASE_FZ).AsInteger() == 1,
                        myStick.get_Parameter(BuiltInParameter.STRUCTURAL_END_RELEASE_MX).AsInteger() == 1,
                        myStick.get_Parameter(BuiltInParameter.STRUCTURAL_END_RELEASE_MY).AsInteger() == 1,
                        myStick.get_Parameter(BuiltInParameter.STRUCTURAL_END_RELEASE_MZ).AsInteger() == 1,
                    });
                    break;
                }

                var fillerList = Enumerable.Repeat(new StructuralVectorBoolSix(new bool[] { false, false, false, false, false, false }), (vertexCount - 1) * 2 - 2).ToList();

                myElement.EndRelease = new List <StructuralVectorBoolSix>()
                {
                    endRelease1
                }.Concat(fillerList).Concat(new List <StructuralVectorBoolSix>()
                {
                    endRelease2
                }).ToList();
            }

            // Property
            try
            {
                var mySection = new Structural1DProperty
                {
                    Name          = Doc.GetElement(myStick.GetElementId()).Name,
                    ApplicationId = myFamily.Symbol.UniqueId
                };

                switch (myFamily.Symbol.GetStructuralSection().StructuralSectionGeneralShape)
                {
                case Autodesk.Revit.DB.Structure.StructuralSections.StructuralSectionGeneralShape.GeneralI:
                    mySection.Shape  = Structural1DPropertyShape.I;
                    mySection.Hollow = false;
                    break;

                case Autodesk.Revit.DB.Structure.StructuralSections.StructuralSectionGeneralShape.GeneralT:
                    mySection.Shape  = Structural1DPropertyShape.T;
                    mySection.Hollow = false;
                    break;

                case Autodesk.Revit.DB.Structure.StructuralSections.StructuralSectionGeneralShape.GeneralH:
                    mySection.Shape     = Structural1DPropertyShape.Rectangular;
                    mySection.Hollow    = true;
                    mySection.Thickness = (double)typeof(Autodesk.Revit.DB.Structure.StructuralSections.StructuralSectionGeneralH).GetProperty("WallNominalThickness").GetValue(myFamily.Symbol.GetStructuralSection()) / Scale;
                    break;

                case Autodesk.Revit.DB.Structure.StructuralSections.StructuralSectionGeneralShape.GeneralR:
                    mySection.Shape     = Structural1DPropertyShape.Circular;
                    mySection.Hollow    = true;
                    mySection.Thickness = (double)typeof(Autodesk.Revit.DB.Structure.StructuralSections.StructuralSectionGeneralR).GetProperty("WallNominalThickness").GetValue(myFamily.Symbol.GetStructuralSection()) / Scale;
                    mySection.Profile   = new SpeckleCircle(
                        new SpecklePlane(new SpecklePoint(0, 0, 0),
                                         new SpeckleVector(0, 0, 1),
                                         new SpeckleVector(1, 0, 0),
                                         new SpeckleVector(0, 1, 0)),
                        (double)typeof(Autodesk.Revit.DB.Structure.StructuralSections.StructuralSectionGeneralR).GetProperty("Diameter").GetValue(myFamily.Symbol.GetStructuralSection()) / 2 / Scale);
                    break;

                case Autodesk.Revit.DB.Structure.StructuralSections.StructuralSectionGeneralShape.GeneralF:
                    mySection.Shape  = Structural1DPropertyShape.Rectangular;
                    mySection.Hollow = false;
                    break;

                case Autodesk.Revit.DB.Structure.StructuralSections.StructuralSectionGeneralShape.GeneralS:
                    mySection.Shape   = Structural1DPropertyShape.Circular;
                    mySection.Profile = new SpeckleCircle(
                        new SpecklePlane(new SpecklePoint(0, 0, 0),
                                         new SpeckleVector(0, 0, 1),
                                         new SpeckleVector(1, 0, 0),
                                         new SpeckleVector(0, 1, 0)),
                        (double)typeof(Autodesk.Revit.DB.Structure.StructuralSections.StructuralSectionGeneralR).GetProperty("Diameter").GetValue(myFamily.Symbol.GetStructuralSection()) / 2 / Scale);
                    mySection.Hollow = false;
                    break;

                default:
                    mySection.Shape  = Structural1DPropertyShape.Generic;
                    mySection.Hollow = false;
                    break;
                }

                // Generate section profile
                var profile = myFamily.GetSweptProfile().GetSweptProfile();

                if (mySection.Shape != Structural1DPropertyShape.Circular)
                {
                    var myProfile = new SpecklePolyline
                    {
                        Value = new List <double>()
                    };

                    for (var i = 0; i < profile.Curves.Size; i++)
                    {
                        var sectionCurves = SpeckleCore.Converter.Serialise(profile.Curves.get_Item(i));

                        var sectionCoordinates = new List <double>();
                        var nextCoordinates    = new List <double>();

                        if (sectionCurves is SpeckleLine)
                        {
                            sectionCoordinates = (sectionCurves as SpeckleLine).Value.Select(x => Math.Round(x, 10)).ToList();

                            if (myProfile.Value.Count == 0)
                            {
                                myProfile.Value = sectionCoordinates;
                                continue;
                            }

                            if (myProfile.Value.Skip(myProfile.Value.Count - 3).SequenceEqual(sectionCoordinates.Take(3)))
                            {
                                nextCoordinates = sectionCoordinates.Skip(3).ToList();
                            }
                            else
                            {
                                break;
                            }
                        }
                        else if (sectionCurves is SpeckleArc)
                        {
                            if (myProfile.Value.Count == 0)
                            {
                                myProfile.Value = (sectionCurves as SpeckleArc).StartPoint.Value.Select(x => Math.Round(x, 10))
                                                  .Concat((sectionCurves as SpeckleArc).MidPoint.Value.Select(x => Math.Round(x, 10)))
                                                  .Concat((sectionCurves as SpeckleArc).EndPoint.Value.Select(x => Math.Round(x, 10)))
                                                  .ToList();
                                continue;
                            }

                            if (myProfile.Value.Skip(myProfile.Value.Count - 3).SequenceEqual((sectionCurves as SpeckleArc).StartPoint.Value.Select(x => Math.Round(x, 10))))
                            {
                                nextCoordinates = (sectionCurves as SpeckleArc).EndPoint.Value.Select(x => Math.Round(x, 10)).ToList();
                            }
                            else if (myProfile.Value.Skip(myProfile.Value.Count - 3).SequenceEqual((sectionCurves as SpeckleArc).EndPoint.Value.Select(x => Math.Round(x, 10))))
                            {
                                nextCoordinates = (sectionCurves as SpeckleArc).StartPoint.Value.Select(x => Math.Round(x, 10)).ToList();
                            }
                            else
                            {
                                break;
                            }
                        }

                        if (nextCoordinates.SequenceEqual(myProfile.Value.Take(3)))
                        {
                            myProfile.Closed = true;
                            break;
                        }
                        else
                        {
                            myProfile.Value.AddRange(nextCoordinates);
                        }
                    }

                    myProfile.GenerateHash();

                    mySection.Profile = myProfile;
                }

                // Material
                try
                {
                    var matType = myFamily.StructuralMaterialType;

                    var structMat = (Material)Doc.GetElement(myFamily.StructuralMaterialId);
                    if (structMat == null)
                    {
                        structMat = (Material)Doc.GetElement(myFamily.Symbol.get_Parameter(BuiltInParameter.STRUCTURAL_MATERIAL_PARAM).AsElementId());
                    }
                    var matAsset = ((PropertySetElement)Doc.GetElement(structMat.StructuralAssetId)).GetStructuralAsset();

                    SpeckleObject myMaterial = null;

                    switch (matType)
                    {
                    case Autodesk.Revit.DB.Structure.StructuralMaterialType.Concrete:
                        var concMat = new StructuralMaterialConcrete
                        {
                            ApplicationId         = Doc.GetElement(myFamily.StructuralMaterialId).UniqueId,
                            Name                  = Doc.GetElement(myFamily.StructuralMaterialId).Name,
                            YoungsModulus         = matAsset.YoungModulus.X,
                            ShearModulus          = matAsset.ShearModulus.X,
                            PoissonsRatio         = matAsset.PoissonRatio.X,
                            Density               = matAsset.Density,
                            CoeffThermalExpansion = matAsset.ThermalExpansionCoefficient.X,
                            CompressiveStrength   = matAsset.ConcreteCompression,
                            MaxStrain             = 0,
                            AggragateSize         = 0
                        };
                        myMaterial = concMat;
                        break;

                    case Autodesk.Revit.DB.Structure.StructuralMaterialType.Steel:
                        var steelMat = new StructuralMaterialSteel
                        {
                            ApplicationId         = Doc.GetElement(myFamily.StructuralMaterialId).UniqueId,
                            Name                  = Doc.GetElement(myFamily.StructuralMaterialId).Name,
                            YoungsModulus         = matAsset.YoungModulus.X,
                            ShearModulus          = matAsset.ShearModulus.X,
                            PoissonsRatio         = matAsset.PoissonRatio.X,
                            Density               = matAsset.Density,
                            CoeffThermalExpansion = matAsset.ThermalExpansionCoefficient.X,
                            YieldStrength         = matAsset.MinimumYieldStress,
                            UltimateStrength      = matAsset.MinimumTensileStrength,
                            MaxStrain             = 0
                        };
                        myMaterial = steelMat;
                        break;

                    default:
                        var defMat = new StructuralMaterialSteel
                        {
                            ApplicationId = Doc.GetElement(myFamily.StructuralMaterialId).UniqueId,
                            Name          = Doc.GetElement(myFamily.StructuralMaterialId).Name
                        };
                        myMaterial = defMat;
                        break;
                    }

                    myMaterial.GenerateHash();
                    mySection.MaterialRef = (myMaterial as SpeckleObject).ApplicationId;

                    returnObjects.Add(myMaterial);
                }
                catch { }

                mySection.GenerateHash();
                myElement.PropertyRef = mySection.ApplicationId;

                returnObjects.Add(mySection);
            }
            catch { }

            myElement.GenerateHash();
            myElement.ApplicationId = myStick.UniqueId;
            returnObjects.Add(myElement);

            return(returnObjects);
        }
コード例 #7
0
    protected override void SolveInstance(IGH_DataAccess DA)
    {

      var check = ValidateKeys();
      if (check.Item1)
      {
        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, check.Item2);
        return;
      }

      var myDictionary = new Dictionary<string, object>();

      for (int i = 0; i < Params.Input.Count; i++)
      {
        var key = Params.Input[i].NickName;

        dynamic ghInputProperty = null;
        object valueExtract = null;
        switch (Params.Input[i].Access)
        {
          case GH_ParamAccess.item:
            DA.GetData(i, ref ghInputProperty);
            valueExtract = ghInputProperty?.Value;
            break;
          case GH_ParamAccess.list:
            var dataValues = new List<dynamic>();
            DA.GetDataList(i, dataValues);
            valueExtract = dataValues.Select(x => x.Value).ToList();
            break;
          case GH_ParamAccess.tree:
            var tree = new GH_Structure<IGH_Goo>();
            DA.GetDataTree(i, out tree);
            var dict = new Dictionary<string, IEnumerable<object>>();

            for (int j = 0; j < tree.PathCount; j++)
            {
              var branch = tree.Branches[j];
              var list = new List<object>();
              for (int k = 0; k < branch.Count; k++)
              {
                list.Add(branch[k].GetType().GetProperty("Value").GetValue(branch[k], null));
              }
              dict.Add(j.ToString(), list);
            }

            myDictionary.Add(key, dict);
            continue;
          default:
            continue;
        }

        try
        {
          var tests = valueExtract is IEnumerable<object>;
          if (valueExtract is IEnumerable<object>)
          {
            var val = valueExtract as List<object>;
            //Is this important? It replaced IEnumerable<int> 
            if(val.Count > 0 && val[0] is int || val[0] is double || val[0] is string || val[1] is bool)
            {
              myDictionary.Add(key, val);
            }
            else
            {
              myDictionary.Add(key, Converter.Serialise(val));
            }
          }
          else if (valueExtract is System.Collections.IDictionary)
          {
            myDictionary.Add(key, valueExtract);
          }
          else
          {
            if (valueExtract is bool || valueExtract is string || valueExtract is double || valueExtract is int)
              myDictionary.Add(key, valueExtract);
            else
              myDictionary.Add(key, Converter.Serialise(valueExtract));
          }
        }
        catch (Exception)
        {
          continue;
        }
      }
      var test = myDictionary;
      var myObject = new SpeckleObject() { Properties = myDictionary };
      myObject.GenerateHash();

      DA.SetData(0, myObject);
      DA.SetData(1, myDictionary);
      //new GH_SpeckleObject()
    }
コード例 #8
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            if (SelectedType is null)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "No type chosen.");
                return;
            }

            object inputObject = null;

            if (!DA.GetData(0, ref inputObject))
            {
                return;
            }

            try
            {
                inputObject = inputObject.GetType().GetProperty("Value").GetValue(inputObject);
            }
            catch { }

            if (inputObject == null)
            {
                return;
            }

            if (!(inputObject.GetType().IsSubclassOf(typeof(SpeckleObject))))
            {
                inputObject = Converter.Serialise(inputObject);
            }

            SpeckleObject convertedObject = (SpeckleObject)Activator.CreateInstance(SelectedType);

            string inputObjectTypeString = (string)inputObject.GetType().GetProperty("Type").GetValue(inputObject);

            // Check to see if one is a subclass of another
            if (!((inputObjectTypeString.Contains(convertedObject.Type))) && !(convertedObject.Type.Contains(inputObjectTypeString)))
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "SpeckleObject not convertible to type.");
                return;
            }

            var deepCopyObject = CreateCopy(inputObject);

            foreach (PropertyInfo p in convertedObject.GetType().GetProperties().Where(p => p.CanWrite))
            {
                PropertyInfo inputProperty = deepCopyObject.GetType().GetProperty(p.Name);
                if (inputProperty != null)
                {
                    p.SetValue(convertedObject, inputProperty.GetValue(deepCopyObject));
                }
            }

            convertedObject.GenerateHash();

            // applicationId generation/setting
            var appId = convertedObject.GetType().GetProperty("ApplicationId").GetValue(convertedObject);

            if (appId == null)
            {
                var myGeneratedAppId = "gh/" + convertedObject.GetType().GetProperty("Hash").GetValue(convertedObject);
                convertedObject.GetType().GetProperty("ApplicationId").SetValue(convertedObject, myGeneratedAppId);
            }

            DA.SetData(0, convertedObject);
        }