Пример #1
0
        public static object Set(object geometry, [DefaultArgument("{}")] DesignScript.Builtin.Dictionary dictionary)
        {
            if (geometry == null)
            {
                throw new ArgumentNullException("geometry");
            }
            if (!(geometry is DesignScriptEntity))
            {
                throw new ArgumentException(String.Format(typeException, geometry.GetType()), "geometry");
            }
            if (dictionary == null)
            {
                throw new ArgumentNullException("dictionary");
            }

            //non serializable values would fail hashing and further serialization
            foreach (var key in dictionary.Keys)
            {
                if (!dictionary.ValueAtKey(key).IsSerializable())
                {
                    dictionary = dictionary.SetValueAtKeys(new List <string> {
                        key
                    }, new List <object> {
                        null
                    });
                }
            }

            if (dictionary.Count > 0)
            {
                DesignScriptEntity newGeo;
                if (geometry is Mesh)
                {
                    Mesh inputMesh = geometry as Mesh;
                    newGeo = Mesh.ByPointsFaceIndices(inputMesh.VertexPositions, inputMesh.FaceIndices);
                }
                else
                {
                    Geometry inputGeometry = geometry as Geometry;
                    newGeo = inputGeometry.Translate();
                }
                newGeo.Tags.AddTag(speckleKey, dictionary);
                return(newGeo);
            }
            else
            {
                return(geometry);
            }
        }
Пример #2
0
        public static Geometry Set(Geometry geometry, [DefaultArgument("{}")] DesignScript.Builtin.Dictionary dictionary)
        {
            if (geometry == null)
            {
                throw new ArgumentNullException("geometry");
            }
            if (dictionary == null)
            {
                throw new ArgumentNullException("dictionary");
            }

            if (dictionary.Count > 0)
            {
                Geometry newGeo = geometry.Translate();
                newGeo.Tags.AddTag(speckleKey, dictionary);
                return(newGeo);
            }
            else
            {
                return(geometry);
            }
        }