public void RefreshGlobalParameters() { ComPtr pApplication = IntPtr.Zero; if (MarshalEx.Succeeded(MarshalEx.GetActiveObject("SolidEdge.Application", out pApplication))) { SelectedObject = new GlobalParameterInfo(pApplication, this.textBoxSearch.Text); } }
public void Connect() { Disconnect(); ComPtr pApplication = IntPtr.Zero; try { if (MarshalEx.Succeeded(MarshalEx.GetActiveObject("SolidEdge.Application", out pApplication))) { comTreeView.AddRootNode(pApplication, "Application"); } } catch { GlobalExceptionHandler.HandleException(); } finally { } }
private bool ConnectToSolidEdge() { ComPtr pApplication = IntPtr.Zero; try { if (MarshalEx.Succeeded(MarshalEx.GetActiveObject("SolidEdge.Application", out pApplication))) { _application = pApplication.TryGetUniqueRCW <SolidEdgeFramework.Application>(); _connectionPointController.AdviseSink <SolidEdgeFramework.ISEApplicationEvents>(_application); commandBrowser.ActiveEnvironment = _application.GetActiveEnvironment(); globalParameterBrowser.RefreshGlobalParameters(); objectBrowser.Connect(); // Older versions of Solid Edge don't have the ProcessID property. try { processBrowser.ProcessId = _application.ProcessID; } catch { } return(true); } } catch { GlobalExceptionHandler.HandleException(); } finally { pApplication.Dispose(); } return(false); }
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) { if ((_pApplication == null) || (_pApplication.IsInvalid)) { return(new PropertyDescriptorCollection(new PropertyDescriptor[] { })); } List <GlobalParameterPropertyDescriptor> list = new List <GlobalParameterPropertyDescriptor>(); try { ComTypeLibrary comTypeLibrary = ComTypeManager.Instance.ComTypeLibraries.Where(x => x.Name.Equals("SolidEdgeFramework")).FirstOrDefault(); if (comTypeLibrary != null) { ComEnumInfo enumInfo = comTypeLibrary.Enums.Where(x => x.Name.Equals("ApplicationGlobalConstants")).FirstOrDefault(); foreach (ComVariableInfo variableInfo in enumInfo.Variables) { if (String.IsNullOrEmpty(_filter) == false) { if (variableInfo.Name.IndexOf(_filter, StringComparison.OrdinalIgnoreCase) == -1) { continue; } } SolidEdgeFramework.ApplicationGlobalConstants globalConst = (SolidEdgeFramework.ApplicationGlobalConstants)variableInfo.ConstantValue; // There is a known bug where seApplicationGlobalOpenAsReadOnly3DFile causes SE to display the read-only icon on // files after GetGlobalParameter() is called. if (globalConst.Equals(SolidEdgeFramework.ApplicationGlobalConstants.seApplicationGlobalOpenAsReadOnly3DFile)) { continue; } try { object[] args = new object[] { globalConst, new VariantWrapper(null) }; object returnValue = null; if (MarshalEx.Succeeded(_pApplication.TryInvokeMethod("GetGlobalParameter", args, out returnValue))) { if (args[1] != null) { Type propertyType = args[1].GetType(); string name = variableInfo.Name.Replace("seApplicationGlobal", string.Empty); StringBuilder description = new StringBuilder(); description.AppendLine(variableInfo.Description); description.AppendLine(String.Format("Application.GetGlobalParameter({0}.{1}, out value)", enumInfo.FullName, variableInfo.Name)); GlobalParameterProperty property = new GlobalParameterProperty(name, description.ToString(), args[1], propertyType, true); list.Add(new GlobalParameterPropertyDescriptor(ref property, attributes)); try { if (_colorGlobalConstants.Contains(globalConst)) { var color = Color.Empty; if (args[1] is int) { byte[] rgb = BitConverter.GetBytes((int)args[1]); color = Color.FromArgb(255, rgb[0], rgb[1], rgb[2]); } else if (args[1] is uint) { byte[] rgb = BitConverter.GetBytes((uint)args[1]); color = Color.FromArgb(255, rgb[0], rgb[1], rgb[2]); } else { #if DEBUG //System.Diagnostics.Debugger.Break(); #endif } if (color.IsEmpty == false) { description = new StringBuilder(); description.AppendLine(property.Description); description.AppendLine("byte[] rgb = BitConverter.GetBytes((int)value)"); description.AppendLine("Color color = Color.FromArgb(255, rgb[0], rgb[1], rgb[2]"); property = new GlobalParameterProperty(String.Format("{0} (converted to color)", property.Name), description.ToString(), color, color.GetType(), true); list.Add(new GlobalParameterPropertyDescriptor(ref property, attributes)); } } } catch { } } } } catch { GlobalExceptionHandler.HandleException(); } } } } catch { GlobalExceptionHandler.HandleException(); } return(new PropertyDescriptorCollection(list.ToArray())); }
private ComTreeNode[] GetChildren(ComPtr comPtr) { if (comPtr == null) { return new ComTreeNode[] { } } ; ComTypeInfo comTypeInfo = comPtr.TryGetComTypeInfo(); if (comTypeInfo == null) { return new ComTreeNode[] { } } ; List <ComTreeNode> childNodes = new List <ComTreeNode>(); try { foreach (ComPropertyInfo comPropertyInfo in comTypeInfo.Properties) { // Special case. MailSession is a PITA property that causes modal dialog. if (comPropertyInfo.Name.Equals("MailSession")) { continue; } ComTreeNode comTreeNode = GetChild(comPtr, comPropertyInfo); if (comTreeNode != null) { if ((comTreeNode is ComPropertyTreeNode) && (_showProperties == false)) { continue; } childNodes.Add(comTreeNode); } } if (comPtr.TryIsCollection()) { List <ComTreeNode> collectionChildNodes = new List <ComTreeNode>(); int count = comPtr.TryGetItemCount(); int foundCount = 0; try { ComFunctionInfo comFunctionInfo = comTypeInfo.Methods.Where(x => x.Name.Equals("Item", StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); if (comFunctionInfo != null) { object returnValue = null; // Solid Edge is supposed to be 1 based index. for (int i = 1; i <= count; i++) { returnValue = null; if (MarshalEx.Succeeded(comPtr.TryInvokeMethod("Item", new object[] { i }, out returnValue))) { ComPtr pItem = returnValue as ComPtr; if ((pItem != null) && (pItem.IsInvalid == false)) { ComPtrItemTreeNode comPtrItemTreeNode = new ComPtrItemTreeNode((ComPtr)returnValue, comFunctionInfo); comPtrItemTreeNode.Caption = String.Format("{0}({1})", comFunctionInfo.Name, i); comPtrItemTreeNode.Nodes.Add("..."); collectionChildNodes.Add(comPtrItemTreeNode); foundCount++; } } } try { // Some collections are 0 based. // Application->Customization->RibbonBarThemes seems to be 0 based. if (foundCount == (count - 1)) { returnValue = null; if (MarshalEx.Succeeded(comPtr.TryInvokeMethod("Item", new object[] { 0 }, out returnValue))) { ComPtr pItem = returnValue as ComPtr; if ((pItem != null) && (pItem.IsInvalid == false)) { ComPtrItemTreeNode comPtrItemTreeNode = new ComPtrItemTreeNode((ComPtr)returnValue, comFunctionInfo); comPtrItemTreeNode.Caption = String.Format("{0}({1})", comFunctionInfo.Name, 0); comPtrItemTreeNode.Nodes.Add("..."); collectionChildNodes.Insert(0, comPtrItemTreeNode); } } } } catch { } } } catch { GlobalExceptionHandler.HandleException(); } childNodes.AddRange(collectionChildNodes.ToArray()); } if (_showMethods) { foreach (ComFunctionInfo comFunctionInfo in comTypeInfo.GetMethods(true)) { if (comFunctionInfo.IsRestricted) { continue; } ComMethodTreeNode comMethodTreeNode = new ComMethodTreeNode(comFunctionInfo); childNodes.Add(comMethodTreeNode); } } } catch { GlobalExceptionHandler.HandleException(); } return(childNodes.ToArray()); }