/// <summary>
        /// Returns the value of a specified global constant.
        /// </summary>
        /// <typeparam name="T">The type to return.</typeparam>
        public static T GetGlobalParameter <T>(this SolidEdgeFramework.Application application, SolidEdgeFramework.ApplicationGlobalConstants globalConstant)
        {
            object value = null;

            application.GetGlobalParameter(globalConstant, ref value);
            return((T)value);
        }
Exemplo n.º 2
0
        static void CaptureApplicationGlobalConstants(SolidEdgeFramework.Application application, Dictionary <SolidEdgeFramework.ApplicationGlobalConstants, object> dictionary)
        {
            // Get list of SolidEdgeFramework.ApplicationGlobalConstants names and values.
            var enumConstants = Enum.GetNames(typeof(SolidEdgeFramework.ApplicationGlobalConstants)).ToArray();
            var enumValues    = Enum.GetValues(typeof(SolidEdgeFramework.ApplicationGlobalConstants)).Cast <SolidEdgeFramework.ApplicationGlobalConstants>().ToArray();

            // Populate the dictionary.
            for (int i = 0; i < enumValues.Length; i++)
            {
                var    enumConstant = enumConstants[i];
                var    enumValue    = enumValues[i];
                object value        = null;

                if (enumValue.Equals(SolidEdgeFramework.ApplicationGlobalConstants.seApplicationGlobalOpenAsReadOnly3DFile))
                {
                    continue;
                }

                // We can safely ignore seApplicationGlobalSystemInfo. It's just noise for our purpose.
                if (enumConstant.Equals(SolidEdgeFramework.ApplicationGlobalConstants.seApplicationGlobalSystemInfo))
                {
                    continue;
                }

                application.GetGlobalParameter(enumValue, ref value);
                dictionary.Add(enumValue, value);
            }
        }
Exemplo n.º 3
0
        private void RefreshGlobalParametersListView()
        {
            if (lvGlobalParameters.Items.Count == 0)
            {
                List <ListViewItem> listViewItems = new List <ListViewItem>();
                SolidEdgeFramework.ApplicationGlobalConstants[] appGlobalConstants = GetAllApplicationGlobalConstants();

                foreach (SolidEdgeFramework.ApplicationGlobalConstants appGlobalConstant in appGlobalConstants)
                {
                    string[] itemValues =
                    {
                        appGlobalConstant.ToString(),
                        String.Empty,
                        String.Empty,
                        String.Format("SolidEdgeFramework.ApplicationGlobalConstants.{0}", appGlobalConstant.ToString())
                    };

                    itemValues[0] = itemValues[0].Replace("seApplicationGlobal", String.Empty).CamelCaseToWordString();

                    ListViewItem listViewItem = new ListViewItem(itemValues);
                    listViewItem.ImageIndex = 0;
                    listViewItem.Tag        = appGlobalConstant;
                    listViewItems.Add(listViewItem);
                }

                lvGlobalParameters.Items.AddRange(listViewItems.ToArray());
                lvGlobalParameters.AutoResizeColumn(0, ColumnHeaderAutoResizeStyle.ColumnContent);
                lvGlobalParameters.AutoResizeColumn(2, ColumnHeaderAutoResizeStyle.ColumnContent);
                lvGlobalParameters.AutoResizeColumn(3, ColumnHeaderAutoResizeStyle.ColumnContent);
            }

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

                if (_application == null)
                {
                    // Connect to Solid Edge.
                    _application = SolidEdgeCommunity.SolidEdgeUtils.Connect(true);

                    // Ensure Solid Edge GUI is visible.
                    _application.Visible = true;
                }

                foreach (ListViewItem listViewItem in lvGlobalParameters.Items)
                {
                    SolidEdgeFramework.ApplicationGlobalConstants appGlobalConstant = (SolidEdgeFramework.ApplicationGlobalConstants)listViewItem.Tag;

                    object globalValue     = null;
                    object globalValueType = null;

                    try
                    {
                        _application.GetGlobalParameter(appGlobalConstant, ref globalValue);
                    }
                    catch (System.Exception ex)
                    {
                        globalValue     = ex;
                        globalValueType = ex.GetType();
                    }

                    if (globalValue != null)
                    {
                        if (globalValueType == null)
                        {
                            globalValueType = globalValue.GetType();
                        }
                    }

                    listViewItem.SubItems[1].Text = String.Format("{0}", globalValue);
                    listViewItem.SubItems[1].Tag  = globalValue;
                    listViewItem.SubItems[2].Text = String.Format("{0}", globalValueType);
                    listViewItem.SubItems[2].Tag  = globalValueType;
                }

                lvGlobalParameters.AutoResizeColumn(2, ColumnHeaderAutoResizeStyle.ColumnContent);
            }
            catch
            {
#if DEBUG
                System.Diagnostics.Debugger.Break();
#endif
                throw;
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }