Esempio n. 1
0
        static void ReportCustomProperties(SolidEdgeFramework.PropertySets propertySets)
        {
            var properties = (SolidEdgeFramework.Properties)propertySets.Item("Custom");

            foreach (var property in properties.OfType <SolidEdgeFramework.Property>())
            {
                System.Runtime.InteropServices.VarEnum nativePropertyType = System.Runtime.InteropServices.VarEnum.VT_EMPTY;
                Type runtimePropertyType = null;

                object value = null;

                nativePropertyType = (System.Runtime.InteropServices.VarEnum)property.Type;

                // Accessing Value property may throw an exception...
                try
                {
                    value = property.get_Value();
                }
                catch (System.Exception ex)
                {
                    value = ex.Message;
                }

                if (value != null)
                {
                    runtimePropertyType = value.GetType();
                }

                Console.WriteLine("\t{0} = '{1}' ({2} | {3}).", property.Name, value, nativePropertyType, runtimePropertyType);
            }

            Console.WriteLine();
        }
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application       application  = null;
            SolidEdgeFramework.Documents         documents    = null;
            SolidEdgeFramework.SolidEdgeDocument document     = null;
            SolidEdgeFramework.PropertySets      propertySets = null;

            try
            {
                Console.WriteLine("Registering OleMessageFilter.");

                // Register with OLE to handle concurrency issues on the current thread.
                OleMessageFilter.Register();

                Console.WriteLine("Connecting to Solid Edge.");

                // Connect to or start Solid Edge.
                application = SolidEdgeUtils.Connect(true);

                // Make sure user can see the GUI.
                application.Visible = true;

                // Bring Solid Edge to the foreground.
                application.Activate();

                // Get a reference to the Documents collection.
                documents = application.Documents;

                // Note: these two will throw exceptions if no document is open.
                //application.ActiveDocument
                //application.ActiveDocumentType;

                if (documents.Count > 0)
                {
                    // Get a reference to the documents collection.
                    document = (SolidEdgeFramework.SolidEdgeDocument)application.ActiveDocument;
                }
                else
                {
                    throw new System.Exception("No document open.");
                }

                propertySets = (SolidEdgeFramework.PropertySets)document.Properties;

                ProcessPropertySets(propertySets);

                AddCustomProperties(propertySets);
            }
            catch (System.Exception ex)
            {
#if DEBUG
                System.Diagnostics.Debugger.Break();
#endif
                Console.WriteLine(ex.Message);
            }
        }
        static void ProcessPropertySets(SolidEdgeFramework.PropertySets propertySets)
        {
            SolidEdgeFramework.Properties properties = null;

            for (int i = 1; i <= propertySets.Count; i++)
            {
                properties = propertySets.Item(i);

                Console.WriteLine("PropertSet '{0}'.", properties.Name);

                ProcessProperties(properties);
            }
        }
        static void AddCustomProperties(SolidEdgeFramework.PropertySets propertySets)
        {
            SolidEdgeFramework.Properties properties = null;

            properties = propertySets.Item("Custom");

            Console.WriteLine("Adding custom properties.");

            properties.Add("My String", "Hello world!");
            properties.Add("My Integer", 338);
            properties.Add("My Boolean", true);
            properties.Add("My DateTime", DateTime.Now);
        }
Esempio n. 5
0
        static void AddCustomProperties(SolidEdgeFramework.PropertySets propertySets)
        {
            var properties     = (SolidEdgeFramework.Properties)propertySets.Item("Custom");
            var propertyValues = new object[] { "My text", int.MaxValue, 1.23, true, DateTime.Now };

            foreach (var propertyValue in propertyValues)
            {
                var propertyType = propertyValue.GetType();
                var propertyName = String.Format("My {0}", propertyType);
                var property     = properties.Add(propertyName, propertyValue);

                Console.WriteLine("Added {0} - {1}.", property.Name, propertyValue);
            }
        }
Esempio n. 6
0
        static void DeleteCustomProperties(SolidEdgeFramework.PropertySets propertySets)
        {
            var properties = (SolidEdgeFramework.Properties)propertySets.Item("Custom");

            // Query for custom properties that start with "My".
            var query = properties.OfType <SolidEdgeFramework.Property>().Where(x => x.Name.StartsWith("My"));

            // Force ToArray() so that Delete() doesn't interfere with the enumeration.
            foreach (var property in query.ToArray())
            {
                var propertyName = property.Name;
                property.Delete();
                Console.WriteLine("Deleted {0}.", propertyName);
            }
        }