private void eventButton_CheckedChanged(object sender, EventArgs e) { try { if (eventButton.Checked) { if (_application == null) { _application = SolidEdgeCommunity.SolidEdgeUtils.Connect(true); _application.Visible = true; } ConnectApplicationEvents(); if (_application != null) { var documents = _application.Documents; if (documents.Count > 0) { var document = (SolidEdgeFramework.SolidEdgeDocument)_application.ActiveDocument; ConnectDocumentEvents(document); } } } else { DisconnectApplicationEvents(); } } catch (System.Exception ex) { MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
static void Main(string[] args) { SolidEdgeFramework.Application application = null; SolidEdgeFramework.Documents documents = null; SolidEdgePart.SheetMetalDocument sheetMetalDocument = null; SolidEdgePart.Model model = null; SolidEdgePart.Tabs tabs = null; SolidEdgePart.Tab tab = null; SolidEdgeFramework.SelectSet selectSet = null; try { // Register with OLE to handle concurrency issues on the current thread. SolidEdgeCommunity.OleMessageFilter.Register(); // Connect to or start Solid Edge. application = SolidEdgeCommunity.SolidEdgeUtils.Connect(true, true); // Bring Solid Edge to the foreground. application.Activate(); // Get a reference to the Documents collection. documents = application.Documents; // Create a new SheetMetal document. sheetMetalDocument = documents.AddSheetMetalDocument(); // Always a good idea to give SE a chance to breathe. application.DoIdle(); // Call helper method to create the actual geometry. model = SheetMetalHelper.CreateBaseTab(sheetMetalDocument); // Get a reference to the Tabs collection. tabs = model.Tabs; // Get a reference to the new Tab. tab = tabs.Item(1); // Get a reference to the ActiveSelectSet. selectSet = application.ActiveSelectSet; // Empty ActiveSelectSet. selectSet.RemoveAll(); // Add new Tab to ActiveSelectSet. selectSet.Add(tab); // Switch to ISO view. application.StartCommand(SolidEdgeConstants.SheetMetalCommandConstants.SheetMetalViewISOView); } catch (System.Exception ex) { Console.WriteLine(ex.Message); } finally { SolidEdgeCommunity.OleMessageFilter.Unregister(); } }
public static string ResolveCommandId(SolidEdgeFramework.Application application, int theCommandID) { ComVariableInfo variableInfo = null; if (_environmentConstantsMap.Count == 0) { Initialize(); } try { ComEnumInfo enumInfo = null; SolidEdgeFramework.Environment environment = application.GetActiveEnvironment(); Guid environmentGuid = environment.GetGuid(); if (_environmentConstantsMap.TryGetValue(environmentGuid, out enumInfo)) { variableInfo = enumInfo.Variables.Where(x => x.ConstantValue != null).Where(x => x.ConstantValue.Equals(theCommandID)).FirstOrDefault(); if (variableInfo != null) { return(String.Format("{0} [{1}.{2}]", theCommandID, variableInfo.ComTypeInfo.Name, variableInfo.Name)); } } } catch { GlobalExceptionHandler.HandleException(); } return(String.Format("{0} [Undefined]", theCommandID)); }
/// <summary> /// Asynchronous version of MainForm_Load. /// </summary> private void MainForm_Load_Async() { toolStripStatusLabel.Text = "Connecting to Solid Edge to get a copy of DraftPrintUtility settings."; SolidEdgeFramework.Application application = null; try { // Connect to or start Solid Edge. application = SolidEdgeUtils.Connect(true, true); // Minimize Solid Edge. //application.WindowState = (int)FormWindowState.Minimized; // Get a copy of the settings for use as a template. customListView._draftPrintUtilityOptions = new DraftPrintUtilityOptions(application); // Enable UI. toolStrip.Enabled = true; customListView.Enabled = true; } catch (System.Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { if (application != null) { Marshal.ReleaseComObject(application); } } toolStripStatusLabel.Text = "Tip: You can drag folders and files into the ListView."; }
/// <summary> /// Called when the addin is first loaded by Solid Edge. /// </summary> public override void OnConnection(SolidEdgeFramework.Application application, SolidEdgeFramework.SeConnectMode ConnectMode, SolidEdgeFramework.AddIn AddInInstance) { // If you makes changes to your ribbon, be sure to increment the GuiVersion or your ribbon // will not initialize properly. AddInEx.GuiVersion = 1; // Create an instance of the default connection point controller. It helps manage connections to COM events. _connectionPointController = new SolidEdgeCommunity.ConnectionPointController(this); // Uncomment the following line to attach to the Solid Edge Application Events. _connectionPointController.AdviseSink <SolidEdgeFramework.ISEApplicationEvents>(this.Application); // Not necessary unless you absolutely need to see low level windows messages. // Uncomment the following line to attach to the Solid Edge Application Window Events. //_connectionPointController.AdviseSink<SolidEdgeFramework.ISEApplicationWindowEvents>(this.Application); // Uncomment the following line to attach to the Solid Edge Feature Library Events. _connectionPointController.AdviseSink <SolidEdgeFramework.ISEFeatureLibraryEvents>(this.Application); // Uncomment the following line to attach to the Solid Edge File UI Events. //_connectionPointController.AdviseSink<SolidEdgeFramework.ISEFileUIEvents>(this.Application); // Uncomment the following line to attach to the Solid Edge File New UI Events. //_connectionPointController.AdviseSink<SolidEdgeFramework.ISENewFileUIEvents>(this.Application); // Uncomment the following line to attach to the Solid Edge EC Events. //_connectionPointController.AdviseSink<SolidEdgeFramework.ISEECEvents>(this.Application); // Uncomment the following line to attach to the Solid Edge Shortcut Menu Events. //_connectionPointController.AdviseSink<SolidEdgeFramework.ISEShortCutMenuEvents>(this.Application); }
static void Main(string[] args) { SolidEdgeFramework.Application application = null; SolidEdgePart.SheetMetalDocument document = null; try { // Register with OLE to handle concurrency issues on the current thread. SolidEdgeCommunity.OleMessageFilter.Register(); // Connect to or start Solid Edge. application = SolidEdgeCommunity.SolidEdgeUtils.Connect(); // Get a reference to the active document. document = application.GetActiveDocument <SolidEdgePart.SheetMetalDocument>(false); // Make sure we have a document. if (document != null) { VariablesHelper.ReportVariables(document); } else { throw new System.Exception("No active document."); } } catch (System.Exception ex) { Console.WriteLine(ex.Message); } finally { SolidEdgeCommunity.OleMessageFilter.Unregister(); } }
void SolidEdgeFramework.ISolidEdgeAddIn.OnConnection(object Application, SolidEdgeFramework.SeConnectMode ConnectMode, SolidEdgeFramework.AddIn AddInInstance) { if (IsDefaultAppDomain) { _application = (SolidEdgeFramework.Application)Application; _addInInstance = AddInInstance; // Notice that "\n" is prepended to the description. This allows the addin to have its own Ribbon Tabs. this.AddInEx.Description = String.Format("\n{0}", this.AddInEx.Description); InitializeIsolatedAddIn(); if (_isolatedAddIn != null) { // Forward call to isolated AppDomain. _isolatedAddIn.OnConnection(_application, ConnectMode, AddInInstance); } } else { Application = UnwrapTransparentProxy(Application); AddInInstance = UnwrapTransparentProxy <SolidEdgeFramework.AddIn>(AddInInstance); _instance = this; _application = (SolidEdgeFramework.Application)Application; _addInInstance = AddInInstance; _ribbonController = new RibbonController(this); _edgeBarController = new EdgeBarController(this); _viewOverlayController = new ViewOverlayController(); OnConnection(_application, ConnectMode, AddInInstance); } }
/// <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); }
static void Main(string[] args) { SolidEdgeFramework.Application application = null; SolidEdgePart.SheetMetalDocument sheetMetalDocument = null; try { // Register with OLE to handle concurrency issues on the current thread. SolidEdgeCommunity.OleMessageFilter.Register(); // Connect to or start Solid Edge. application = SolidEdgeCommunity.SolidEdgeUtils.Connect(true, true); // Get a reference to the active sheetmetal document. sheetMetalDocument = application.GetActiveDocument <SolidEdgePart.SheetMetalDocument>(); if (sheetMetalDocument != null) { sheetMetalDocument.Recompute(); } else { throw new System.Exception("No active document."); } } catch (System.Exception ex) { Console.WriteLine(ex.Message); } finally { SolidEdgeCommunity.OleMessageFilter.Unregister(); } }
static void Main(string[] args) { SolidEdgeFramework.Application application = null; SolidEdgeFramework.Documents documents = null; SolidEdgeDraft.DraftDocument draftDocument = null; SolidEdgeDraft.Sheet sheet = null; SolidEdgeFrameworkSupport.Lines2d lines2d = null; SolidEdgeFrameworkSupport.Line2d line2d = null; double lineLength = 3.0; // Inches try { // Register with OLE to handle concurrency issues on the current thread. SolidEdgeCommunity.OleMessageFilter.Register(); // Connect to or start Solid Edge. application = SolidEdgeCommunity.SolidEdgeUtils.Connect(true, true); // Get a reference to the documents collection. documents = application.Documents; // Create a new draft document. draftDocument = documents.AddDraftDocument(); // Get a reference to the active sheet. sheet = draftDocument.ActiveSheet; // Get a reference to the Lines2d collection. lines2d = sheet.Lines2d; // Work with angle in degrees. for (int angle = 0; angle < 360; angle += 45) { // {x1, y1, x2, y2} double[] startPoint = { 0.2, 0.2 }; double[] endPoint = { 0.3, 0.2 }; // Add the line. line2d = lines2d.AddBy2Points( x1: startPoint[0], y1: startPoint[1], x2: endPoint[0], y2: endPoint[1]); // Set the line length by converting inches to meters. line2d.Length = lineLength * 0.0254; // Set the angle by converting degrees to radians. line2d.Angle = (Math.PI / 180) * angle; } } catch (System.Exception ex) { Console.WriteLine(ex.Message); } finally { SolidEdgeCommunity.OleMessageFilter.Unregister(); } }
static void Main(string[] args) { SolidEdgeFramework.Application application = null; SolidEdgeFramework.Window window = null; try { // Register with OLE to handle concurrency issues on the current thread. SolidEdgeCommunity.OleMessageFilter.Register(); // Connect to Solid Edge. application = SolidEdgeCommunity.SolidEdgeUtils.Start(); // 3D windows are of type SolidEdgeFramework.Window. window = application.ActiveWindow as SolidEdgeFramework.Window; if (window != null) { WindowHelper.SaveAsImageUsingBitBlt(window); } else { throw new System.Exception("No active 3D window."); } } catch (System.Exception ex) { Console.WriteLine(ex.Message); } finally { SolidEdgeCommunity.OleMessageFilter.Unregister(); } }
static void Main(string[] args) { SolidEdgeFramework.Application application = null; SolidEdgeDraft.DraftDocument draftDocument = null; SolidEdgeDraft.Sheet sheet = null; SolidEdgeFrameworkSupport.DrawingObjects drawingObjects = null; try { // Register with OLE to handle concurrency issues on the current thread. SolidEdgeCommunity.OleMessageFilter.Register(); // Connect to or start Solid Edge. application = SolidEdgeCommunity.SolidEdgeUtils.Connect(true, true); // Get a reference to the active draft document. draftDocument = application.GetActiveDocument <SolidEdgeDraft.DraftDocument>(); // Get a reference to the active Sheet. sheet = draftDocument.ActiveSheet; // Get a reference to the drawing objects collection. drawingObjects = sheet.DrawingObjects; // Disable screen updating for performance. application.ScreenUpdating = false; // Loop until count is 0. while (drawingObjects.Count > 0) { // Leverage dynamic keyword to allow invoking Delete() method. dynamic drawingObject = drawingObjects.Item(1); if (drawingObject is SolidEdgeDraft.TablePage) { // TablePage does not have a Delete() method but its parent does. dynamic drawingObjectParent = drawingObject.Parent; drawingObjectParent.Delete(); } else { drawingObject.Delete(); } } // Turn screen updating back on. application.ScreenUpdating = true; // Fit the view. application.StartCommand(SolidEdgeConstants.DetailCommandConstants.DetailViewFit); } catch (System.Exception ex) { Console.WriteLine(ex.Message); } finally { SolidEdgeCommunity.OleMessageFilter.Unregister(); } }
private void UpdateExternalValue() { SolidEdgeFramework.Application application = null; SolidEdgeFramework.SolidEdgeDocument document = null; SolidEdgeFramework.UnitsOfMeasure unitsOfMeasure = null; try { application = (SolidEdgeFramework.Application)Marshal.GetActiveObject("SolidEdge.Application"); document = (SolidEdgeFramework.SolidEdgeDocument)application.ActiveDocument; unitsOfMeasure = document.UnitsOfMeasure; _externalValue = unitsOfMeasure.FormatUnit((int)_unitType, _internalValue, _precision); } catch (System.Exception ex) { _externalValue = ex.Message; } finally { if (unitsOfMeasure != null) { Marshal.ReleaseComObject(unitsOfMeasure); } if (document != null) { Marshal.ReleaseComObject(document); } if (application != null) { Marshal.ReleaseComObject(application); } } }
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); } }
static void Main(string[] args) { SolidEdgeFramework.Application application = null; SolidEdgeFramework.SelectSet selectSet = null; try { // Register with OLE to handle concurrency issues on the current thread. SolidEdgeCommunity.OleMessageFilter.Register(); // Connect to or start Solid Edge. application = SolidEdgeCommunity.SolidEdgeUtils.Start(); // Get a reference to the active select set. selectSet = application.ActiveSelectSet; // Clear the SelectSet. selectSet.RemoveAll(); } catch (System.Exception ex) { Console.WriteLine(ex.Message); } finally { SolidEdgeCommunity.OleMessageFilter.Unregister(); } }
private void button1_Click(object sender, EventArgs e) { // Disable the button. button1.Enabled = false; // Toggle the label visible state. label1.Visible = !label1.Visible; // Get a reference to Solid Edge if we don't already have one. if (_application == null) { try { // Attempt to connect to a running instace. _application = (SolidEdgeFramework.Application)Marshal.GetActiveObject(SolidEdge.PROGID.Application); } catch { } } // See what AppDomain we're currently executing in. var currentAppDomain = AppDomain.CurrentDomain; // This will always be the default AppDomain at this point. var isDefaultAppDomain = currentAppDomain.IsDefaultAppDomain(); backgroundWorker1.RunWorkerAsync(_application); }
private void eventButton_Click(object sender, EventArgs e) { try { if (eventButton.Checked) { if (_application == null) { _application = SolidEdgeUtils.Connect(true); _application.Visible = true; } HookEvents(_application, typeof(SolidEdgeFramework.ISEApplicationEvents).GUID); } else { UnhookEvents(); _application = null; } } catch (System.Exception ex) { MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
static void Main(string[] args) { SolidEdgeFramework.Application application = null; SolidEdgeFramework.Documents documents = null; SolidEdgePart.PartDocument partDocument = 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; Console.WriteLine("Creating a new part document."); // Create a new part document. partDocument = (SolidEdgePart.PartDocument) documents.Add("SolidEdge.PartDocument"); // Always a good idea to give SE a chance to breathe. application.DoIdle(); Console.WriteLine("Creating geometry."); // Create geometry. CreateFiniteExtrudedProtrusion(partDocument); Console.WriteLine("Creating holes with user defined patterns."); // Create holes. CreateHolesWithUserDefinedPattern(partDocument); Console.WriteLine("Switching to ISO view."); // Switch to ISO view. application.StartCommand((SolidEdgeFramework.SolidEdgeCommandConstants)SolidEdgeConstants.PartCommandConstants.PartViewISOView); } catch (System.Exception ex) { #if DEBUG System.Diagnostics.Debugger.Break(); #endif Console.WriteLine(ex.Message); } }
static void Main(string[] args) { SolidEdgeFramework.Application application = null; SolidEdgeFramework.Documents documents = null; SolidEdgeDraft.DraftDocument draftDocument = null; SolidEdgeDraft.ModelLinks modelLinks = null; SolidEdgeDraft.ModelLink modelLink = null; SolidEdgeDraft.Sheet sheet = null; SolidEdgeDraft.DrawingViews drawingViews = null; SolidEdgeDraft.DrawingView drawingView = null; string filename = null; try { // Register with OLE to handle concurrency issues on the current thread. SolidEdgeCommunity.OleMessageFilter.Register(); // Connect to or start Solid Edge. application = SolidEdgeCommunity.SolidEdgeUtils.Connect(true, true); // Get a reference to the documents collection. documents = application.Documents; // Create a new draft document. draftDocument = documents.AddDraftDocument(); // Get a reference to the active sheet. sheet = draftDocument.ActiveSheet; // Build path to part file. filename = System.IO.Path.Combine(SolidEdgeCommunity.SolidEdgeUtils.GetTrainingFolderPath(), "Coffee Pot.asm"); // Get a reference to the ModelLinks collection. modelLinks = draftDocument.ModelLinks; // Add a new model link. modelLink = modelLinks.Add(filename); // Get a reference to the DrawingViews collection. drawingViews = sheet.DrawingViews; // Add a new part drawing view. drawingView = drawingViews.AddAssemblyView( From: modelLink, Orientation: SolidEdgeDraft.ViewOrientationConstants.igDimetricTopBackLeftView, Scale: 1.0, x: 0.4, y: 0.4, ViewType: SolidEdgeDraft.AssemblyDrawingViewTypeConstants.seAssemblyDesignedView); } catch (System.Exception ex) { Console.WriteLine(ex.Message); } finally { SolidEdgeCommunity.OleMessageFilter.Unregister(); } }
static void Main(string[] args) { SolidEdgeFramework.Application application = null; SolidEdgeFramework.Documents documents = null; SolidEdgeDraft.DraftDocument draftDocument = null; SolidEdgeDraft.Sheet sheet = null; SolidEdgeFrameworkSupport.Circles2d circles2d = null; SolidEdgeFrameworkSupport.Circle2d circle2d = null; SolidEdgeFrameworkSupport.Dimensions dimensions = null; try { // Register with OLE to handle concurrency issues on the current thread. SolidEdgeCommunity.OleMessageFilter.Register(); // Connect to or start Solid Edge. application = SolidEdgeCommunity.SolidEdgeUtils.Connect(true, true); // Get a reference to the documents collection. documents = application.Documents; // Create a new draft document. draftDocument = documents.AddDraftDocument(); // Get a reference to the active sheet. sheet = draftDocument.ActiveSheet; // Get a reference to the Circles2d collection. circles2d = sheet.Circles2d; // Get a reference to the Dimensions collection. dimensions = (SolidEdgeFrameworkSupport.Dimensions)sheet.Dimensions; double x = 0.1; double y = 0.1; double radius = 0.01; for (int i = 0; i < 5; i++) { // Add the circle. circle2d = circles2d.AddByCenterRadius(x, y, radius); // Dimension the circle. dimensions.AddRadialDiameter(circle2d); x += 0.05; y += 0.05; radius += 0.01; } } catch (System.Exception ex) { Console.WriteLine(ex.Message); } finally { SolidEdgeCommunity.OleMessageFilter.Unregister(); } }
static void CleanSE() { if (application != null) { Marshal.ReleaseComObject(application); application = null; } }
/// <summary> /// Shows the form as a modal dialog box with the application main window as the owner. /// </summary> public static DialogResult ShowDialog(this SolidEdgeFramework.Application application, CommonDialog dialog) { if (dialog == null) { throw new ArgumentNullException("dialog"); } return(dialog.ShowDialog(application.GetNativeWindow())); }
static void Main(string[] args) { SolidEdgeFramework.Application application = null; SolidEdgeAssembly.AssemblyDocument assemblyDocument = null; SolidEdgeAssembly.Occurrences occurrences = null; try { // Register with OLE to handle concurrency issues on the current thread. SolidEdgeCommunity.OleMessageFilter.Register(); // Connect to or start Solid Edge. application = SolidEdgeCommunity.SolidEdgeUtils.Connect(true, true); // Get the active document. assemblyDocument = application.GetActiveDocument <SolidEdgeAssembly.AssemblyDocument>(false); if (assemblyDocument != null) { // Get a reference to the Occurrences collection. occurrences = assemblyDocument.Occurrences; foreach (var occurrence in occurrences.OfType <SolidEdgeAssembly.Occurrence>()) { Array MinRangePoint = Array.CreateInstance(typeof(double), 0); Array MaxRangePoint = Array.CreateInstance(typeof(double), 0); occurrence.GetRangeBox(ref MinRangePoint, ref MaxRangePoint); // Convert from System.Array to double[]. double[] is easier to work with. double[] a1 = MinRangePoint.OfType <double>().ToArray(); double[] a2 = MaxRangePoint.OfType <double>().ToArray(); // Report the occurrence matrix. Console.WriteLine("{0} range box:", occurrence.Name); Console.WriteLine("|MinRangePoint: {0}, {1}, {2}|", a1[0], a1[1], a1[2]); Console.WriteLine("|MaxRangePoint: {0}, {1}, {2}|", a2[0], a2[1], a2[2]); } } else { throw new System.Exception("No active document."); } } catch (System.Exception ex) { Console.WriteLine(ex.Message); } finally { SolidEdgeCommunity.OleMessageFilter.Unregister(); } }
static void Main(string[] args) { SolidEdgeFramework.Application application = null; SolidEdgeFramework.Documents documents = null; SolidEdgeDraft.DraftDocument draftDocument = null; SolidEdgeDraft.Sections sections = 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) && (application.ActiveDocumentType == SolidEdgeFramework.DocumentTypeConstants.igDraftDocument)) { // Get a reference to the documents collection. draftDocument = (SolidEdgeDraft.DraftDocument)application.ActiveDocument; } else { throw new System.Exception("Draft file not open."); } sections = draftDocument.Sections; // Update all views in the working section. UpdateAllViewsInWorkingSection(sections.WorkingSection); // Update all views in all sheets. //UpdateAllViewsInAllSheets(draftDocument.Sheets); } catch (System.Exception ex) { #if DEBUG System.Diagnostics.Debugger.Break(); #endif Console.WriteLine(ex.Message); } }
static void Main(string[] args) { SolidEdgeFramework.Application application = null; SolidEdgeFramework.Documents documents = null; SolidEdgeDraft.DraftDocument draftDocument = null; SolidEdgeDraft.Sheet sheet = null; SolidEdgeFrameworkSupport.Lines2d lines2d = null; SolidEdgeFrameworkSupport.Line2d line2d = null; SolidEdgeFrameworkSupport.Dimensions dimensions = null; SolidEdgeFrameworkSupport.Dimension dimension = null; SolidEdgeFrameworkSupport.DimStyle dimStyle = null; try { // Register with OLE to handle concurrency issues on the current thread. SolidEdgeCommunity.OleMessageFilter.Register(); // Connect to or start Solid Edge. application = SolidEdgeCommunity.SolidEdgeUtils.Connect(true, true); // Get a reference to the documents collection. documents = application.Documents; // Create a new draft document. draftDocument = documents.AddDraftDocument(); // Get a reference to the active sheet. sheet = draftDocument.ActiveSheet; // Get a reference to the Lines2d collection. lines2d = sheet.Lines2d; // Draw a new line. line2d = lines2d.AddBy2Points( x1: 0.2, y1: 0.2, x2: 0.3, y2: 0.2); // Get a reference to the Dimensions collection. dimensions = (SolidEdgeFrameworkSupport.Dimensions)sheet.Dimensions; // Add a dimension to the line. dimension = dimensions.AddLength(line2d); // Get a reference to the dimension style. // DimStyle has a ton of options... dimStyle = dimension.Style; } catch (System.Exception ex) { Console.WriteLine(ex.Message); } finally { SolidEdgeCommunity.OleMessageFilter.Unregister(); } }
/// <summary> /// Shows the form as a modal dialog box with the application main window as the owner. /// </summary> public static DialogResult ShowDialog(this SolidEdgeFramework.Application application, System.Windows.Forms.Form form) { if (form == null) { throw new ArgumentNullException("form"); } return(form.ShowDialog(application.GetNativeWindow())); }
static void Main(string[] args) { SolidEdgeFramework.Application application = null; SolidEdgeFramework.Documents documents = null; SolidEdgeDraft.DraftDocument draftDocument = null; SolidEdgeDraft.Sheet sheet = null; SolidEdgeFrameworkSupport.TextBoxes textBoxes = null; SolidEdgeFrameworkSupport.TextBox textBox = null; SolidEdgeFrameworkSupport.Leaders leaders = null; SolidEdgeFrameworkSupport.Leader leader = null; SolidEdgeFrameworkSupport.DimStyle dimStyle = null; try { // Register with OLE to handle concurrency issues on the current thread. SolidEdgeCommunity.OleMessageFilter.Register(); // Connect to or start Solid Edge. application = SolidEdgeCommunity.SolidEdgeUtils.Connect(true, true); // Get a reference to the documents collection. documents = application.Documents; // Create a new draft document. draftDocument = documents.AddDraftDocument(); // Get a reference to the active sheet. sheet = draftDocument.ActiveSheet; // Get a reference to the TextBoxes collection. textBoxes = (SolidEdgeFrameworkSupport.TextBoxes)sheet.TextBoxes; // Add a new text box. textBox = textBoxes.Add(0.25, 0.25, 0); textBox.TextScale = 1; textBox.VerticalAlignment = SolidEdgeFrameworkSupport.TextVerticalAlignmentConstants.igTextHzAlignVCenter; textBox.Text = "Leader"; // Get a reference to the Leaders collection. leaders = (SolidEdgeFrameworkSupport.Leaders)sheet.Leaders; Console.WriteLine("Creating a new leader. "); // Add a new leader. leader = leaders.Add(0.225, 0.225, 0, 0.25, 0.25, 0); dimStyle = leader.Style; dimStyle.FreeSpaceTerminatorType = SolidEdgeFrameworkSupport.DimTermTypeConstants.igDimStyleTermFilled; } catch (System.Exception ex) { Console.WriteLine(ex.Message); } finally { SolidEdgeCommunity.OleMessageFilter.Unregister(); } }
/// <summary> /// Shows the form with the application main window as the owner. /// </summary> public static void Show(this SolidEdgeFramework.Application application, System.Windows.Forms.Form form) { if (form == null) { throw new ArgumentNullException("form"); } form.Show(application.GetNativeWindow()); }
void PrintInternal(string filename, DraftPrintUtilityOptions options) { SolidEdgeFramework.Application application = null; SolidEdgeFramework.Documents documents = null; SolidEdgeDraft.DraftDocument draftDocument = null; SolidEdgeDraft.DraftPrintUtility draftPrintUtility = null; try { // Register with OLE to handle concurrency issues on the current thread. SolidEdgeCommunity.OleMessageFilter.Register(); // Connect to or start Solid Edge. application = SolidEdgeCommunity.SolidEdgeUtils.Connect(true); // Make sure Solid Edge is visible. application.Visible = true; // Get a reference to the Documents collection. documents = application.Documents; // Get a reference to the DraftPrintUtility. draftPrintUtility = (SolidEdgeDraft.DraftPrintUtility)application.GetDraftPrintUtility(); // Copy all of the settings from DraftPrintUtilityOptions to the DraftPrintUtility object. CopyOptions(draftPrintUtility, options); // Open the document. draftDocument = (SolidEdgeDraft.DraftDocument)documents.Open(filename); // Give Solid Edge time to process. application.DoIdle(); // Add the draft document to the queue. draftPrintUtility.AddDocument(draftDocument); // Print out. draftPrintUtility.PrintOut(); // Cleanup queue. draftPrintUtility.RemoveAllDocuments(); } catch { throw; } finally { // Make sure we close the document. if (draftDocument != null) { draftDocument.Close(); } SolidEdgeCommunity.OleMessageFilter.Register(); } }
static void Main(string[] args) { SolidEdgeFramework.Application application = null; SolidEdgeFramework.Documents documents = null; SolidEdgePart.PartDocument partDocument = null; SolidEdgePart.Model model = null; SolidEdgePart.RevolvedProtrusions revolvedProtrusions = null; SolidEdgePart.RevolvedProtrusion revolvedProtrusion = null; SolidEdgeFramework.SelectSet selectSet = null; try { // Register with OLE to handle concurrency issues on the current thread. SolidEdgeCommunity.OleMessageFilter.Register(); // Connect to or start Solid Edge. application = SolidEdgeCommunity.SolidEdgeUtils.Connect(true, true); // Get a reference to the Documents collection. documents = application.Documents; // Create a new PartDocument. partDocument = documents.AddPartDocument(); // Always a good idea to give SE a chance to breathe. application.DoIdle(); // Call helper method to create the actual geometry. model = PartHelper.CreateFiniteRevolvedProtrusion(partDocument); // Get a reference to the RevolvedProtrusions collection. revolvedProtrusions = model.RevolvedProtrusions; // Get a reference to the new RevolvedProtrusion. revolvedProtrusion = revolvedProtrusions.Item(1); // Get a reference to the ActiveSelectSet. selectSet = application.ActiveSelectSet; // Empty ActiveSelectSet. selectSet.RemoveAll(); // Add new RevolvedProtrusion to ActiveSelectSet. selectSet.Add(revolvedProtrusion); // Switch to ISO view. application.StartCommand(SolidEdgeConstants.PartCommandConstants.PartViewISOView); } catch (System.Exception ex) { Console.WriteLine(ex.Message); } finally { SolidEdgeCommunity.OleMessageFilter.Unregister(); } }
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 Main(string[] args) { SolidEdgeFramework.Application application = null; SolidEdgeFramework.Documents documents = null; SolidEdgeFramework.SolidEdgeDocument document = null; SolidEdgeFramework.Variables variables = 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; // This check is necessary because application.ActiveDocument will throw an // exception if no documents are open... if (documents.Count > 0) { // Attempt to connect to ActiveDocument. document = (SolidEdgeFramework.SolidEdgeDocument)application.ActiveDocument; } // Make sure we have a document. if (document == null) { throw new System.Exception("No active document."); } variables = (SolidEdgeFramework.Variables)document.Variables; ProcessVariables(variables); } catch (System.Exception ex) { #if DEBUG System.Diagnostics.Debugger.Break(); #endif Console.WriteLine(ex.Message); } }
private void MainForm_Load(object sender, EventArgs e) { _uiContext = SynchronizationContext.Current; imageList1.Images.Add(Resources.Event_16x16); // Register with OLE to handle concurrency issues on the current thread. SolidEdgeCommunity.OleMessageFilter.Register(); try { _application = SolidEdgeCommunity.SolidEdgeUtils.Connect(); eventButton.Checked = true; } catch { } }
private void UpdateTreeView() { if (_application == null) { try { _application = SolidEdgeUtils.Connect(); } catch { MessageBox.Show("Solid Edge is not running.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } if (_document == null) { try { _document = (SolidEdgeFramework.SolidEdgeDocument)_application.ActiveDocument; } catch { } } if (_document != null) { try { _documentEvents = (SolidEdgeFramework.ISEDocumentEvents_Event)_document.DocumentEvents; _documentEvents.BeforeClose += _documentEvents_BeforeClose; _documentEvents.SelectSetChanged += _documentEvents_SelectSetChanged; UpdateTreeView(_application.ActiveSelectSet); } catch (System.Exception ex) { _document = null; MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void button1_Click(object sender, EventArgs e) { // Toggle the label visible state. label1.Visible = !label1.Visible; // Get a reference to Solid Edge if we don't already have one. if (_application == null) { try { // Attempt to connect to a running instace. _application = (SolidEdgeFramework.Application)Marshal.GetActiveObject(SolidEdge.PROGID.Application); } catch { // On a system where Solid Edge is installed, the COM ProgID will be // defined in registry: HKEY_CLASSES_ROOT\SolidEdge.Application Type t = Type.GetTypeFromProgID(SolidEdge.PROGID.Application, throwOnError: true); // Using the discovered Type, create and return a new instance of Solid Edge. _application = (SolidEdgeFramework.Application)Activator.CreateInstance(type: t); } } // Make sure Solid Edge is visible. _application.Visible = true; // See what AppDomain we're currently executing in. var currentAppDomain = AppDomain.CurrentDomain; // This will always be the default AppDomain at this point. var isDefaultAppDomain = currentAppDomain.IsDefaultAppDomain(); // Create a separate AppDomain and execute our code. CreateSeparateAppDomainAndExecuteIsolatedTask(_application); // Toggle the label visible state. label1.Visible = !label1.Visible; }
private void buttonStartCommand_Click(object sender, EventArgs e) { try { _application = SolidEdgeCommunity.SolidEdgeUtils.Connect(); _command = _application.CreateCommand((int)SolidEdgeConstants.seCmdFlag.seNoDeactivate); _command.Terminate += command_Terminate; _command.Start(); _mouse = _command.Mouse; _mouse.LocateMode = comboBoxLocateModes.SelectedIndex; _mouse.EnabledMove = (bool)comboBoxEnableMouseMoveEvent.SelectedItem; _mouse.ScaleMode = 1; // Design model coordinates. _mouse.WindowTypes = 1; // Graphic window's only. foreach (ListViewItem listViewItem in listViewFilters.CheckedItems) { int filter = (int)listViewItem.Tag; _mouse.AddToLocateFilter(filter); } _mouse.MouseDown += mouse_MouseDown; _mouse.MouseMove += mouse_MouseMove; outputTextBox.Clear(); comboBoxEnableMouseMoveEvent.Enabled = false; buttonStopCommand.Enabled = true; buttonStartCommand.Checked = true; buttonStartCommand.Enabled = false; comboBoxLocateModes.Enabled = false; listViewFilters.Enabled = false; } catch (System.Exception ex) { MessageBox.Show(ex.Message); } }
private void eventButton_CheckedChanged(object sender, EventArgs e) { try { if (eventButton.Checked) { if (_application == null) { _application = SolidEdgeCommunity.SolidEdgeUtils.Connect(true); _application.Visible = true; } ConnectApplicationEvents(); } else { DisconnectApplicationEvents(); } } catch (System.Exception ex) { MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
static void StartSE() { Console.WriteLine("Démarrage de Solid Edge"); try { type = Type.GetTypeFromProgID("SolidEdge.Application"); application = (SolidEdgeFramework.Application)Activator.CreateInstance(type); // Make Solid Edge visible application.Visible = true; Console.WriteLine("Solid edge démarré"); } catch (System.Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine("Solid non installer sur ce poste"); } }
private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { // Unhook events. DisconnectApplicationEvents(); _application = null; }
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; }
void command_Terminate() { this.Do(frm => { frm.HandleCommandTerminate(); }); _mouse = null; _command = null; _application = null; }
private void DisconnectFromSolidEdge(bool resetStartupTimer) { _connectionPointController.UnadviseAllSinks(); HandleAutoResetEvent(); globalParameterBrowser.SelectedObject = null; try { Marshal.FinalReleaseComObject(_application); } catch { GlobalExceptionHandler.HandleException(); } startupTimer.Enabled = resetStartupTimer; _application = null; }
private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (_applicationEventWatcher != null) { _applicationEventWatcher.Dispose(); _applicationEventWatcher = null; } _application = null; }
private void eventButton_Click(object sender, EventArgs e) { try { if (eventButton.Checked) { if (_application == null) { // On a system where Solid Edge is installed, the COM ProgID will be // defined in registry: HKEY_CLASSES_ROOT\SolidEdge.Application Type t = Type.GetTypeFromProgID(SolidEdge.PROGID.Application, throwOnError: true); // Using the discovered Type, create and return a new instance of Solid Edge. _application = (SolidEdgeFramework.Application)Activator.CreateInstance(type: t); // Show Solid Edge. _application.Visible = true; } _applicationEventWatcher = new ApplicationEventWatcher(this, _application); } else { _applicationEventWatcher.Dispose(); _applicationEventWatcher = null; _application = null; } } catch (System.Exception ex) { MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void eventButton_CheckedChanged(object sender, EventArgs e) { try { if (eventButton.Checked) { if (_application == null) { _application = SolidEdgeCommunity.SolidEdgeUtils.Connect(true); _application.Visible = true; } ConnectApplicationEvents(); if (_application != null) { var documents = _application.Documents; if (documents.Count > 0) { var document = (SolidEdgeFramework.SolidEdgeDocument)_application.ActiveDocument; ConnectDocumentEvents(document); } } } else { DisconnectApplicationEvents(); } } catch (System.Exception ex) { MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
static void Main(string[] args) { try { // Get the type from the Solid Edge ProgID type = Type.GetTypeFromProgID("SolidEdge.Application"); // Connect to a running instance of Solid Edge application = (SolidEdgeFramework.Application)Marshal.GetActiveObject("SolidEdge.Application"); Console.Write("Connecté a Solid Edge \n"); } catch (System.Exception) { Console.WriteLine("Solid Edge non actif..."); StartSE(); } //OuvrirAsm(); IterateFolder(); // faire la magie icitte //CreateDraft(); //CreateDoc(); }
public void OnBeforeQuit() { eventLogTextBox.AppendText("OnBeforeQuit"); eventLogTextBox.AppendText(Environment.NewLine); _applicationEventWatcher.Dispose(); _applicationEventWatcher = null; _application = null; }
static void CreateDraft() { //draft = (SolidEdgeDraft.DraftDocument)documents.Add("SolidEdge.DraftDocument", Missing.Value); try { //add a draft document documents = application.Documents; draft = (SolidEdgeDraft.DraftDocument)documents.Add("SolidEdge.DraftDocument", Missing.Value); // Get a reference to the sheets collection sheets = draft.Sheets; // Add sheets to draft document // Loop thru list of wall - to do // Add a new sheet sheet = sheets.Item(1); sheet.Activate(); sheet.Name = "MUR A"; // Add wall drawings //Insert next wall sheet = sheets.AddSheet("MUR B", SheetSectionTypeConstants.igWorkingSection, Missing.Value, Missing.Value); sheet.Activate(); // Add wall drawing //Insert next wall sheet = sheets.AddSheet("MUR C", SheetSectionTypeConstants.igWorkingSection, Missing.Value, Missing.Value); sheet.Activate(); // Add wall drawings //Insert next wall sheet = sheets.AddSheet("MUR D", SheetSectionTypeConstants.igWorkingSection, Missing.Value, Missing.Value); sheet.Activate(); // Add wall drawings //Insert next wall sheet = sheets.AddSheet("CHEVRONS", SheetSectionTypeConstants.igWorkingSection, Missing.Value, Missing.Value); sheet.Activate(); // Add wall drawings } catch (System.Exception ex) { Console.WriteLine(ex.Message); } finally { if (sheet != null) { Marshal.ReleaseComObject(sheet); sheet = null; } if (sheets != null) { Marshal.ReleaseComObject(sheets); sheets = null; } if (sectionSheets != null) { Marshal.ReleaseComObject(sectionSheets); sectionSheets = null; } if (section != null) { Marshal.ReleaseComObject(section); section = null; } if (draft != null) { Marshal.ReleaseComObject(draft); draft = null; } if (documents != null) { Marshal.ReleaseComObject(documents); documents = null; } if (application != null) { Marshal.ReleaseComObject(application); application = null; } } }
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(); } }
private bool ConnectToSolidEdge() { ComPtr pApplication = IntPtr.Zero; try { if (MarshalEx.Succeeded(MarshalEx.GetActiveObject("SolidEdge.Application", out pApplication))) { _application = pApplication.TryGetUniqueRCW<SolidEdgeFramework.Application>(); HookEvents(_application, typeof(SolidEdgeFramework.ISEApplicationEvents).GUID); globalParameterBrowser.RefreshGlobalParameters(); objectBrowser.Connect(); processBrowser.ProcessId = _application.ProcessID; return true; } } catch { GlobalExceptionHandler.HandleException(); } finally { pApplication.Dispose(); } return false; }