Esempio n. 1
0
        public string GetExpression(Dictionary <string, object> parameters, string variable)
        {
            object obj     = parameters["Handle"];
            Array  handles = null;

            if (obj.GetType().IsArray)
            {
                handles = obj as Array;
            }
            else
            {
                handles = new Object[] { obj }
            };

            List <IGeometryEntity> geometry = new List <IGeometryEntity>();

            foreach (var item in handles)
            {
                IPersistentObject persitentObject = HostFactory.PersistenceManager.GetPersistentObjectFromHandle(item);
                if (null != persitentObject)
                {
                    geometry.Add(persitentObject.Geometry);
                }
            }

            return(GeometryExpressionBuilder.GetExpression(geometry.ToArray(), variable));
        }
    }
        public static string GetExpression(IGeometryEntity[] entities, string paramName)
        {
            GeometryExpressionBuilder eb = new GeometryExpressionBuilder();
            string methodName            = kImportMethodPrefix + paramName;

            eb.WriteString(String.Format(@"def {0}() {{", methodName));

            if (entities.Length == 1)
            {
                eb.WriteDSEntity(entities[0], "return");
            }
            else
            {
                List <IGeometryEntity> primitives = new List <IGeometryEntity>();
                List <IGeometryEntity> asm        = new List <IGeometryEntity>();

                foreach (var item in entities)
                {
                    if (item is ISurfaceEntity || item is ISolidEntity)
                    {
                        asm.Add(item);
                    }
                    else
                    {
                        primitives.Add(item);
                    }
                }
                string sat = "__sat";
                if (asm.Count > 0)
                {
                    eb.WriteSATImport(asm.ToArray(), sat);
                }

                if (primitives.Count > 0)
                {
                    string collection = eb.WriteEntities(primitives.ToArray());
                    if (asm.Count > 0)
                    {
                        eb.WriteString(String.Format(@"return = Flatten({{{1}, {0}}});", sat, collection));
                    }
                    else
                    {
                        eb.WriteString(String.Format("return = {0};", collection));
                    }
                }
            }

            eb.WriteString("}");
            eb.WriteString(string.Format("{0} = {1}();", paramName, methodName));

            return(eb.ToString());
        }
 public static string WriteEntity <T>(GeometryExpressionBuilder eb, IDesignScriptEntity entity, string paramName) where T : IDesignScriptEntity
 {
     return(eb.WriteEntity((T)entity, paramName));
 }