/// <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) { _application = application; // If you makes changes to your ribbon, be sure to increment the GuiVersion or your ribbon // will not initialize properly. AddInEx.GuiVersion = 1; //krkmfkrnkj // 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); }
public Ribbon3d() { // Get a reference to the current assembly. This is where the ribbon XML is embedded. var assembly = System.Reflection.Assembly.GetExecutingAssembly(); // In this example, XML file must have a build action of "Embedded Resource". this.LoadXml(assembly, _embeddedResourceName); // Example of how to bind a local variable to a particular ribbon control. _buttonBoundingBox = GetButton(20); _buttonOpenGlBoxes = GetButton(21); _buttonGdiPlus = GetButton(22); _checkboxItemset = GetCheckBox(14); _checkNgram = GetCheckBox(15); _buttonHole = GetButton(4); _buttonCutout = GetButton(5); _buttonSlot = GetButton(6); // Example of how to bind a particular ribbon control click event. _buttonBoundingBox.Click += _buttonBoundingBox_Click; _buttonOpenGlBoxes.Click += _buttonOpenGlBoxes_Click; _buttonGdiPlus.Click += _buttonGdiPlus_Click; _buttonHole.Click += _buttonHole_Click; _buttonCutout.Click += _buttoncutout_Click; _buttonSlot.Click += _buttonSlot_Click; _checkboxItemset.Click += _itemset_Checked; _checkNgram.Click += _ngram_Checked; _checkboxItemset.Checked = true; // Get the Solid Edge version. var version = DemoAddIn.Instance.SolidEdgeVersion; _application = DemoAddIn.Instance.Application; // Create an instance of the default connection point controller. It helps manage connections to COM events. _connectionPointController = new SolidEdgeCommunity.ConnectionPointController(this); // View.GetModelRange() is only available in ST6 or greater. if (version.Major < 106) { _buttonBoundingBox.Enabled = false; } }
public SEECController(SolidEdgeFramework.Application SeAppObj) { _seec = SeAppObj.SolidEdgeTCE; }
static void Main(string[] args) { //string fileToOpen = @"C:\Users\wttcpchang\Downloads\3D CAD\03-22811_A~A.ASM"; XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.IndentChars = " "; settings.Encoding = Encoding.UTF8; XmlWriter writerXml = XmlWriter.Create("PhyProperty.xml", settings); SolidEdgeFramework.Application application = null; SolidEdgeFramework.Documents seDocuments = null; SolidEdgeAssembly.AssemblyDocument seAssemblyDocument = null; SolidEdgePart.PartDocument sePartDocument = null; SolidEdgePart.Models models = null; // collection of Methods SolidEdgePart.Model model = null; // 3d model //The variables for use int status; double volume, area, mass, density, accuracy, relativeAccuracyAchieved; // The matrix data Array centerOfGravity = Array.CreateInstance(typeof(double), 3); Array centerOfVolume = Array.CreateInstance(typeof(double), 3); Array globalMomentsOfInteria = Array.CreateInstance(typeof(double), 6); //Ixx, Iyy, Izz, Ixy, Iyz, Ixz Array principalMomentsOfInteria = Array.CreateInstance(typeof(double), 3); //Ixx, Iyy, Izz Array principalAxes = Array.CreateInstance(typeof(double), 9); Array radiiOfGyration = Array.CreateInstance(typeof(double), 9); FileStream ostrm; StreamWriter writer; TextWriter oldOut = Console.Out; try { ostrm = new FileStream("./SEinfo.txt", FileMode.Create, FileAccess.Write); writer = new StreamWriter(ostrm); Console.SetOut(writer); //OleMessageFilter.Register(); //application = SolidEdgeUtils.Connect(); //var assemblyDocument = application.GetActiveDocument<SolidEdgeAssembly.AssemblyDocument>(false); Console.WriteLine(args[0]); //Write the root element writerXml.WriteStartElement("RootAssemblyFile"); writerXml.WriteAttributeString("File", args[0]); ///////// open Solid Edge file in SE application = SolidEdgeCommunity.SolidEdgeUtils.Connect(true); seDocuments = application.Documents; //seAssemblyDocument = (AssemblyDocument)seDocuments.Open(fileToOpen); seAssemblyDocument = (AssemblyDocument)seDocuments.Open(args[0].ToString()); var assemblyDocument = application.GetActiveDocument <SolidEdgeAssembly.AssemblyDocument>(false); ///////// // Optional settings you may tweak for performance improvements. Results may vary. application.DelayCompute = true; application.DisplayAlerts = false; application.Interactive = false; application.ScreenUpdating = false; if (assemblyDocument != null) { var rootItem = new DocumentItem(); rootItem.FileName = assemblyDocument.FullName; // Begin the recurisve extraction process. PopulateDocumentItems(assemblyDocument.Occurrences, rootItem); // Write each DocumentItem to console. foreach (var documentItem in rootItem.AllDocumentItems) { String file = documentItem.FileName.ToString(); if (file.Substring(file.Length - 3) == "PAR" || file.Substring(file.Length - 3) == "par" || file.Substring(file.Length - 3) == "Par") { sePartDocument = (PartDocument)seDocuments.Open(documentItem.FileName.ToString()); // SE open the tree PAR var seActivePartDocument = application.GetActiveDocument <SolidEdgePart.PartDocument>(false); // connect to the active PAR } Console.WriteLine("=============================================================="); Console.WriteLine("connect to active file (within Document tree):"); //Console.WriteLine(seActivePartDocument.FullName); Console.WriteLine(documentItem.FileName); //if (application.ActiveDocumentType == DocumentTypeConstants.igPartDocument) if (file.Substring(file.Length - 3) == "PAR" || file.Substring(file.Length - 3) == "par" || file.Substring(file.Length - 3) == "Par") { writerXml.WriteStartElement("DocumentTree_Part"); writerXml.WriteAttributeString("File", documentItem.FileName); Console.WriteLine("-------- ## Physical Properties: ## --------"); // get the collection of models models = sePartDocument.Models; // get the model model = models.Item(1); // get the Volume, Area, Mass,.... model.GetPhysicalProperties( Status: out status, Density: out density, Accuracy: out accuracy, Volume: out volume, Area: out area, Mass: out mass, CenterOfGravity: ref centerOfGravity, CenterOfVolume: ref centerOfVolume, GlobalMomentsOfInteria: ref globalMomentsOfInteria, PrincipalMomentsOfInteria: ref principalMomentsOfInteria, PrincipalAxes: ref radiiOfGyration, RadiiOfGyration: ref radiiOfGyration, RelativeAccuracyAchieved: out relativeAccuracyAchieved ); // do anything what you want.... Console.WriteLine("\tVolume, \"" + volume + "\""); Console.WriteLine("\tArea, \"" + area + "\""); Console.WriteLine("\tMass, \"" + mass + "\""); //Console.ReadKey(); //writerXml.WriteStartElement("Volume"); writerXml.WriteElementString("Volume", volume.ToString()); writerXml.WriteElementString("Area", area.ToString()); writerXml.WriteElementString("Mass", mass.ToString()); // Write results to screen. Console.WriteLine("\tDensity, \"{0}\"", density); Console.WriteLine("\tAccuracy, \"{0}\"", accuracy); writerXml.WriteElementString("Density", density.ToString()); writerXml.WriteElementString("Accuracy", accuracy.ToString()); // Convert from System.Array to double[]. double[] is easier to work with. double[] m = centerOfGravity.OfType <double>().ToArray(); Console.WriteLine("CenterOfGravity:"); Console.WriteLine("\tCenterOfGravity_x, \"{0}\"", m[0]); Console.WriteLine("\tCenterOfGravity_y, \"{0}\"", m[1]); Console.WriteLine("\tCenterOfGravity_z, \"{0}\"", m[2]); writerXml.WriteElementString("CenterOfGravity_x", m[0].ToString()); writerXml.WriteElementString("CenterOfGravity_y", m[1].ToString()); writerXml.WriteElementString("CenterOfGravity_z", m[2].ToString()); //Console.WriteLine("\t|{0}, {1}, {2}|", m[0], m[1], m[2]); m = centerOfVolume.OfType <double>().ToArray(); Console.WriteLine("CenterOfVolume:"); Console.WriteLine("\tCenterOfVolume_x, \"{0}\"", m[0]); Console.WriteLine("\tCenterOfVolume_y, \"{0}\"", m[1]); Console.WriteLine("\tCenterOfVolume_z, \"{0}\"", m[2]); writerXml.WriteElementString("CenterOfVolume_x", m[0].ToString()); writerXml.WriteElementString("CenterOfVolume_y", m[1].ToString()); writerXml.WriteElementString("CenterOfVolume_z", m[2].ToString()); //Console.WriteLine("\t|{0}, {1}, {2}|", m[0], m[1], m[2]); m = globalMomentsOfInteria.OfType <double>().ToArray(); Console.WriteLine("GlobalMomentsOfInteria:"); Console.WriteLine("\tGlobalMomentsOfInteria_xx, \"{0}\"", m[0]); Console.WriteLine("\tGlobalMomentsOfInteria_yy, \"{0}\"", m[1]); Console.WriteLine("\tGlobalMomentsOfInteria_zz, \"{0}\"", m[2]); Console.WriteLine("\tGlobalMomentsOfInteria_xy, \"{0}\"", m[3]); Console.WriteLine("\tGlobalMomentsOfInteria_xz, \"{0}\"", m[4]); Console.WriteLine("\tGlobalMomentsOfInteria_yz, \"{0}\"", m[5]); writerXml.WriteElementString("GlobalMomentsOfInteria_xx", m[0].ToString()); writerXml.WriteElementString("GlobalMomentsOfInteria_yy", m[1].ToString()); writerXml.WriteElementString("GlobalMomentsOfInteria_zz", m[2].ToString()); writerXml.WriteElementString("GlobalMomentsOfInteria_xy", m[3].ToString()); writerXml.WriteElementString("GlobalMomentsOfInteria_xz", m[4].ToString()); writerXml.WriteElementString("GlobalMomentsOfInteria_yz", m[5].ToString()); //Console.WriteLine("\t|{0}, {1}, {2}|", m[0], m[1], m[2]); //Console.WriteLine("\t|{0}, {1}, {2}|", m[3], m[4], m[5]); m = principalMomentsOfInteria.OfType <double>().ToArray(); Console.WriteLine("PrincipalMomentsOfInteria:"); Console.WriteLine("\tPrincipalMomentsOfInteria_xx, \"{0}\"", m[0]); Console.WriteLine("\tPrincipalMomentsOfInteria_yy, \"{0}\"", m[1]); Console.WriteLine("\tPrincipalMomentsOfInteria_zz, \"{0}\"", m[2]); writerXml.WriteElementString("PrincipalMomentsOfInteria_xx", m[0].ToString()); writerXml.WriteElementString("PrincipalMomentsOfInteria_yy", m[1].ToString()); writerXml.WriteElementString("PrincipalMomentsOfInteria_zz", m[2].ToString()); //Console.WriteLine("\t|{0}, {1}, {2}|", m[0], m[1], m[2]); m = principalAxes.OfType <double>().ToArray(); Console.WriteLine("PrincipalAxes:"); Console.WriteLine("\tPrincipalAxes_xx, \"{0}\"", m[0]); Console.WriteLine("\tPrincipalAxes_xy, \"{0}\"", m[1]); Console.WriteLine("\tPrincipalAxes_xz, \"{0}\"", m[2]); Console.WriteLine("\tPrincipalAxes_yx, \"{0}\"", m[3]); Console.WriteLine("\tPrincipalAxes_yy, \"{0}\"", m[4]); Console.WriteLine("\tPrincipalAxes_yz, \"{0}\"", m[5]); Console.WriteLine("\tPrincipalAxes_zx, \"{0}\"", m[6]); Console.WriteLine("\tPrincipalAxes_zy, \"{0}\"", m[7]); Console.WriteLine("\tPrincipalAxes_zz, \"{0}\"", m[8]); writerXml.WriteElementString("PrincipalAxes_xx", m[0].ToString()); writerXml.WriteElementString("PrincipalAxes_xy", m[1].ToString()); writerXml.WriteElementString("PrincipalAxes_xz", m[2].ToString()); writerXml.WriteElementString("PrincipalAxes_yx", m[3].ToString()); writerXml.WriteElementString("PrincipalAxes_yy", m[4].ToString()); writerXml.WriteElementString("PrincipalAxes_yz", m[5].ToString()); writerXml.WriteElementString("PrincipalAxes_zx", m[6].ToString()); writerXml.WriteElementString("PrincipalAxes_zy", m[7].ToString()); writerXml.WriteElementString("PrincipalAxes_zz", m[8].ToString()); //Console.WriteLine("\t|{0}, {1}, {2}|", m[0], m[1], m[2]); //Console.WriteLine("\t|{0}, {1}, {2}|", m[3], m[4], m[5]); //Console.WriteLine("\t|{0}, {1}, {2}|", m[6], m[7], m[8]); m = radiiOfGyration.OfType <double>().ToArray(); Console.WriteLine("RadiiOfGyration:"); Console.WriteLine("\tRadiiOfGyration_xx, \"{0}\"", m[0]); Console.WriteLine("\tRadiiOfGyration_xy, \"{0}\"", m[1]); Console.WriteLine("\tRadiiOfGyration_xz, \"{0}\"", m[2]); Console.WriteLine("\tRadiiOfGyration_yx, \"{0}\"", m[3]); Console.WriteLine("\tRadiiOfGyration_yy, \"{0}\"", m[4]); Console.WriteLine("\tRadiiOfGyration_yz, \"{0}\"", m[5]); Console.WriteLine("\tRadiiOfGyration_zx, \"{0}\"", m[6]); Console.WriteLine("\tRadiiOfGyration_zy, \"{0}\"", m[7]); Console.WriteLine("\tRadiiOfGyration_zz, \"{0}\"", m[8]); writerXml.WriteElementString("RadiiOfGyration_xx", m[0].ToString()); writerXml.WriteElementString("RadiiOfGyration_xy", m[1].ToString()); writerXml.WriteElementString("RadiiOfGyration_xz", m[2].ToString()); writerXml.WriteElementString("RadiiOfGyration_yx", m[3].ToString()); writerXml.WriteElementString("RadiiOfGyration_yy", m[4].ToString()); writerXml.WriteElementString("RadiiOfGyration_yz", m[5].ToString()); writerXml.WriteElementString("RadiiOfGyration_zx", m[6].ToString()); writerXml.WriteElementString("RadiiOfGyration_zy", m[7].ToString()); writerXml.WriteElementString("RadiiOfGyration_zz", m[8].ToString()); //Console.WriteLine("\t|{0}, {1}, {2}|", m[0], m[1], m[2]); //Console.WriteLine("\t|{0}, {1}, {2}|", m[3], m[4], m[5]); //Console.WriteLine("\t|{0}, {1}, {2}|", m[6], m[7], m[8]); Console.WriteLine(); Console.WriteLine("\tRelativeAccuracyAchieved, \"{0}\"", relativeAccuracyAchieved); writerXml.WriteElementString("RelativeAccuracyAchieved", relativeAccuracyAchieved.ToString()); Console.WriteLine("\tStatus, \"{0}\"", status); writerXml.WriteElementString("Status", status.ToString()); Console.WriteLine(); writerXml.WriteEndElement(); } //Console.ReadKey(); } writerXml.WriteFullEndElement(); writerXml.Close(); Console.SetOut(oldOut); writer.Close(); ostrm.Close(); // Demonstration of how to save the BOM to various formats. // Convert the document items to JSON. string json = Newtonsoft.Json.JsonConvert.SerializeObject(rootItem, Newtonsoft.Json.Formatting.Indented); } } catch (System.Exception ex) { Console.WriteLine(ex.Message); Console.ReadKey(); } finally { if (application != null) { application.DelayCompute = false; application.DisplayAlerts = true; application.Interactive = true; application.ScreenUpdating = true; } OleMessageFilter.Unregister(); } }
// Restituisce string con il tipo di documento attivo public string TipoDocumentoAttivo() { string tipoDoc = ""; try { application = (SolidEdgeFramework.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("SolidEdge.Application"); } catch { tipoDoc = "Nessuna istanza attiva"; application = null; } if(application != null) // Se SE e` in funzione, cerca di leggere il tipo di documento attivo { try { document = (SolidEdgeFramework.SolidEdgeDocument)application.ActiveDocument; switch (document.Type) { case DocumentTypeConstants.igAssemblyDocument: tipoDoc = tipoAssembly; break; case DocumentTypeConstants.igDraftDocument: tipoDoc = tipoDraft; break; case DocumentTypeConstants.igPartDocument: tipoDoc = tipoPart; break; case DocumentTypeConstants.igSheetMetalDocument: tipoDoc = tipoSheetMetal; break; case DocumentTypeConstants.igUnknownDocument: tipoDoc = tipoSconosciuto; break; case DocumentTypeConstants.igWeldmentAssemblyDocument: tipoDoc = tipoWeldmentAssembly; break; case DocumentTypeConstants.igWeldmentDocument: tipoDoc = tipoWeldment; break; } } catch { tipoDoc = "Nessun documento attivo"; } finally { if (document != null) { Marshal.ReleaseComObject(document); document = null; } if (application != null) { Marshal.ReleaseComObject(application); application = null; } } } return tipoDoc; }
// Scrive singola prop text nel doc attivo public bool ScriviSingolaProprieta(string nomeP, string valoreP) { bool ret = false; try { application = (SolidEdgeFramework.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("SolidEdge.Application"); } catch { application = null; } if (application != null) { SolidEdgeFramework.PropertySets propertySets = null; // Proprieta` del documento aperto SolidEdgeFramework.Properties properties = null; SolidEdgeFramework.Property property = null; try { document = (SolidEdgeFramework.SolidEdgeDocument)application.ActiveDocument; propertySets = (SolidEdgeFramework.PropertySets)document.Properties; properties = propertySets.Item("Custom"); property = properties.Add(nomeP, valoreP); ret = true; } catch // Restituisce false se eccezione { ret = false; } finally { if (property != null) { Marshal.ReleaseComObject(property); property = null; } if (properties != null) { Marshal.ReleaseComObject(properties); properties = null; } if (propertySets != null) { Marshal.ReleaseComObject(propertySets); propertySets = null; } if (document != null) { Marshal.ReleaseComObject(document); document = null; } if (application != null) { Marshal.ReleaseComObject(application); application = null; } } } return ret; }
// Scrive lista prop nel doc attivo (in lista dati o tutte) public bool ScriviListaProprieta(bool bTutte) { bool ret = false; try { application = (SolidEdgeFramework.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("SolidEdge.Application"); } catch { application = null; } if(application != null) { SolidEdgeFramework.PropertySets propertySets = null; // Proprieta` del documento aperto (non del file) SolidEdgeFramework.Properties properties = null; SolidEdgeFramework.Property property = null; try { document = (SolidEdgeFramework.SolidEdgeDocument)application.ActiveDocument; propertySets = (SolidEdgeFramework.PropertySets)document.Properties; properties = propertySets.Item("Custom"); foreach(ProprietaSolidEdge pr in listaProprietaFile) // Percorre la lista proprieta` { if(listaProprietaDati.Contains(pr.Nome) || bTutte) // Copia se in lista o se flag property = properties.Add(pr.Nome, pr.Valore); } ret = true; } catch // Restituisce false se eccezione { ret = false; } finally { if (property != null) { Marshal.ReleaseComObject(property); property = null; } if (properties != null) { Marshal.ReleaseComObject(properties); properties = null; } if (propertySets != null) { Marshal.ReleaseComObject(propertySets); propertySets = null; } if (document != null) { Marshal.ReleaseComObject(document); document = null; } if (application != null) { Marshal.ReleaseComObject(application); application = null; } } } return ret; }
// Riempie la lista dei nomi file collegati e rest. string messaggio public string CreaListaModelli() { string messaggio = ""; // Cancella i dati preesistenti listaModelli.Clear(); try { application = (SolidEdgeFramework.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("SolidEdge.Application"); } catch { messaggio = "Nessuna istanza attiva"; application = null; } try { document = (SolidEdgeFramework.SolidEdgeDocument)application.ActiveDocument; if(document.Type == DocumentTypeConstants.igDraftDocument) // Se e` un draft... { int count, i; // ...estrae i documenti linkati modelLinks = ((SolidEdgeDraft.DraftDocument)document).ModelLinks; count = modelLinks.Count; for (i = 0; i < count; i++) // Li inserisce in una lista { modelLink = modelLinks.Item(i + 1); string nomeFile = modelLink.FileName; // Filename completo int indx = nomeFile.IndexOf(altSeparator); // Elimina alternate assembly if( indx != -1) { nomeFile = nomeFile.Remove(indx); // Tutto cio` dopo '!' } listaModelli.Add(nomeFile); } } else { messaggio = "Non e` un draft"; } } catch (System.Exception ex) // Messaggio se eccezione { messaggio = "Eccezione: " + ex.Message + " + Nessun documento attivo"; } finally { if (modelLinks != null) { foreach(SolidEdgeDraft.ModelLink modelLink in modelLinks) { Marshal.ReleaseComObject(modelLink); } } if (modelLinks != null) { Marshal.ReleaseComObject(modelLinks); modelLinks = null; } if (document != null) { Marshal.ReleaseComObject(document); document = null; } if (application != null) { Marshal.ReleaseComObject(application); application = null; } } return messaggio; }
// Imposta i nomi completi del file attivo... public bool PreparaNomifile() { // ...solo se e` una dft bool done = false; string simplenameDoc = ""; string pathDoc = ""; string codenameDoc = ""; fullnameDoc = ""; fullpdfDoc = ""; fulldwgDoc = ""; // Azzera i nomi try { application = (SolidEdgeFramework.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("SolidEdge.Application"); } catch { application = null; } if (application != null) // Se SE e` in funzione, cerca di leggere il tipo di documento attivo { try { document = (SolidEdgeFramework.SolidEdgeDocument)application.ActiveDocument; if(document.Type == DocumentTypeConstants.igDraftDocument) { fullnameDoc = document.FullName; // Nome completo string codice = ""; string[] split = document.Name.Split(new Char [] {'.'}); simplenameDoc = split[0]; // Nome senza estensioni pathDoc = document.Path + SolidEdgeUtils.pathSeparator; // Path con separatore CreaListaProprietaDaIstanzaSolidEdge(fullnameDoc); // Riempie lista proprieta` del doc attivo foreach (ProprietaSolidEdge pr in listaProprietaFile) // Legge le proprieta` { if(pr.Nome == listaProprietaDati[0]) // Estrae quelle con il primo nome { // del file di configurazione codice = pr.Valore; } } List<string>[] lst = Codici(codice); // Estrae codici ed estensioni foreach(string s in lst[0]) { codenameDoc += s; // Nomi senza estensione } if(codenameDoc != simplenameDoc) // Corrispondenza nomefile e codice nomecodicicorrispondono = false; else nomecodicicorrispondono = true; foreach(string s in lst[1]) // Aggiunge estensione { codenameDoc += s; } fullpdfDoc = pathDoc + "PDF" + SolidEdgeUtils.pathSeparator + codenameDoc + pdfExt; fulldwgDoc = pathDoc + "DWG" + SolidEdgeUtils.pathSeparator + codenameDoc; //+ dwgExt; //MessageBox.Show(fullnameDoc + "\n" + fullpdfDoc + "\n" + fulldwgDoc); done = true; } else { //MessageBox.Show(document.Type.ToString()); } } catch /*(System.Exception ex)*/ { fullnameDoc = ""; //MessageBox.Show(ex.Message); } finally { if (document != null) { Marshal.ReleaseComObject(document); document = null; } if (application != null) { Marshal.ReleaseComObject(application); application = null; } } } return done; }
// Restituisce il nome del foglio di background attivo public string NomeFoglioBackgroundAttivo() { string messaggio = ""; // Cancella i dati preesistenti try { application = (SolidEdgeFramework.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("SolidEdge.Application"); } catch { messaggio = "Nessuna istanza attiva"; application = null; } try { document = (SolidEdgeFramework.SolidEdgeDocument)application.ActiveDocument; if (document.Type == DocumentTypeConstants.igDraftDocument) // Se e` un draft... { messaggio = ((SolidEdgeDraft.DraftDocument)document).ActiveSheet.Background.Name; } else { messaggio = "Non e` un draft"; } } catch (System.Exception ex) // Messaggio se eccezione { messaggio = "Eccezione: " + ex.Message + " + Nessun documento attivo"; } finally { if (drawingViews != null) { foreach (SolidEdgeDraft.DrawingView drawingView in drawingViews) { Marshal.ReleaseComObject(drawingView); } } if (drawingViews != null) { Marshal.ReleaseComObject(drawingViews); drawingViews = null; } if (document != null) { Marshal.ReleaseComObject(document); document = null; } if (application != null) { Marshal.ReleaseComObject(application); application = null; } } return messaggio; }
// Restituisce il nome completo del doc attivo public string NomeDocumentoAttivo() { string nomeDoc = ""; try { application = (SolidEdgeFramework.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("SolidEdge.Application"); } catch { application = null; } if (application != null) // Se SE e` in funzione, cerca di leggere il tipo di documento attivo { try { document = (SolidEdgeFramework.SolidEdgeDocument)application.ActiveDocument; nomeDoc = document.FullName; } catch { nomeDoc = ""; } finally { if (document != null) { Marshal.ReleaseComObject(document); document = null; } if (application != null) { Marshal.ReleaseComObject(application); application = null; } } } return nomeDoc; }
// Restituisce true se il doc indicato e` aperto nella sessione SE public bool DocumentoAperto(string fullname) { bool ret = false; try { application = (SolidEdgeFramework.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("SolidEdge.Application"); } catch { application = null; } if (application != null) // Se SE e` in funzione, leggere i documenti aperti e li mette in una lista { try { foreach (SolidEdgeFramework.SolidEdgeDocument doc in application.Documents) { if(doc.FullName == fullname) { ret = true; break; } } } catch { ret = false; } finally { if (document != null) { Marshal.ReleaseComObject(document); document = null; } if (application != null) { Marshal.ReleaseComObject(application); application = null; } } } return ret; }
// Riempie una lista con le scale delle viste del draft public string CreaListaScale() { string messaggio = ""; // Cancella i dati preesistenti listaScale.Clear(); try { application = (SolidEdgeFramework.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("SolidEdge.Application"); } catch { messaggio = "Nessuna istanza attiva"; application = null; } try { document = (SolidEdgeFramework.SolidEdgeDocument)application.ActiveDocument; if (document.Type == DocumentTypeConstants.igDraftDocument) // Se e` un draft... { int count, i; // ... estrae le viste del foglio attivo double scala; string tScala; drawingViews = ((SolidEdgeDraft.DraftDocument)document).ActiveSheet.DrawingViews; count = drawingViews.Count; for (i = 0; i < count; i++) // Percorre le viste { drawingView = drawingViews.Item(i+1); scala = drawingView.ScaleFactor; if(scala >= 1.0) tScala = scala.ToString()+":1"; else tScala = "1:"+(1.0/scala).ToString(); listaScale.Add(tScala); } } else { messaggio = "Non e` un draft"; } } catch (System.Exception ex) // Messaggio se eccezione { messaggio = "Eccezione: " + ex.Message + " + Nessun documento attivo"; } finally { if (drawingViews != null) { foreach (SolidEdgeDraft.DrawingView drawingView in drawingViews) { Marshal.ReleaseComObject(drawingView); } } if (drawingViews != null) { Marshal.ReleaseComObject(drawingViews); drawingViews = null; } if (document != null) { Marshal.ReleaseComObject(document); document = null; } if (application != null) { Marshal.ReleaseComObject(application); application = null; } } return messaggio; }
// Lista da doc collegato aperto public string CreaListaProprietaDaIstanzaSolidEdge(string fullname) { string msg = ""; SolidEdgeFramework.SolidEdgeDocument activeDocument = null; // Documento attivo SolidEdgeFramework.PropertySets propertySets = null; // Proprieta` del documento aperto (non del file) SolidEdgeFramework.Properties properties = null; //SolidEdgeFramework.Property property = null; try { application = (SolidEdgeFramework.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("SolidEdge.Application"); } catch { application = null; } if (application != null) // Se SE e` in funzione... { listaProprietaFile.Clear(); // Cancella la lista delle proprieta attuale try { activeDocument = (SolidEdgeFramework.SolidEdgeDocument)application.ActiveDocument; // Salva il rif. al doc. attivo if(AttivaDocumento(fullname)) // Attiva il documento aperto con il nome file richiesto... { msg += " - "; application = (SolidEdgeFramework.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("SolidEdge.Application"); document = (SolidEdgeFramework.SolidEdgeDocument)application.ActiveDocument; // Ne legge i rif. alle proprieta` propertySets = (SolidEdgeFramework.PropertySets)document.Properties; properties = propertySets.Item("Custom"); foreach (SolidEdgeFramework.Property pr in properties) // Percorre le proprieta` { listaProprietaFile.Add(new ProprietaSolidEdge(pr.Name, pr.get_Value(), 0)); // e le mette in una lista if (pr != null) { Marshal.ReleaseComObject(pr); } } msg = "Lettura proprieta` completata"; } } catch (System.Exception ex) { msg += ex.Message + " in CreaListaProprietaDaIstanzaSolidEdge()"; } finally { if (document != null) { Marshal.ReleaseComObject(document); document = null; } if (application != null) { Marshal.ReleaseComObject(application); application = null; } activeDocument.Activate(); // Ripristina il doc che era attivo all'inizio della funzione } } return msg; }
// Salva e restituisce il nome completo del doc attivo public string SaveDocumentoAttivo() { string nomeDoc = ""; try { application = (SolidEdgeFramework.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("SolidEdge.Application"); } catch { application = null; } if (application != null) // Se SE e` in funzione, cerca di leggere il tipo di documento attivo { try { document = (SolidEdgeFramework.SolidEdgeDocument)application.ActiveDocument; // Di tipo Draft nomeDoc = document.FullName; document.Save(); document.SaveAs(fullpdfDoc); // Salva il documento come pdf //document.SaveAs(fulldwgDoc); // Salva solo il foglio attivo come dwg SolidEdgeDraft.Sheet ActiveSheet; // Memorizza il foglio attivo ActiveSheet = ((SolidEdgeDraft.DraftDocument)document).ActiveSheet; // Percorre i fogli e li salva singolarmente in dwg SolidEdgeDraft.Sections sections = null; SolidEdgeDraft.Section section = null; SolidEdgeDraft.SectionSheets sectionSheets = null; SolidEdgeDraft.Sheet sheet = null; sections = ((SolidEdgeDraft.DraftDocument)document).Sections; // Le sezioni del documento dft section = sections.WorkingSection; // Sezione con i fogli di lavoro (non background) sectionSheets = section.Sheets; // Ottiene la lista dei fogli for (int j = 1; j <= sectionSheets.Count; j++) // Percorre tutti i fogli { sheet = sectionSheets.Item(j); sheet.Activate(); string dwgSuffix = ""; // Se solo 1 foglio, nessuna estensione if(sectionSheets.Count> 1) dwgSuffix = dwgShExt + j.ToString(); document.SaveAs(fulldwgDoc + dwgSuffix + dwgExt); // Salva il foglio attivo come dwg con estensione } ActiveSheet.Activate(); // Riattiva il foglio memorizzato } catch { //nomeDoc = ""; } finally { if (document != null) { Marshal.ReleaseComObject(document); document = null; } if (application != null) { Marshal.ReleaseComObject(application); application = null; } } } return nomeDoc; }
async void ISEMouseEvents.MouseClick(short sButton, short sShift, double dX, double dY, double dZ, object pWindowDispatch, int lKeyPointType, object pGraphicDispatch) { if (checkhole) { try { //MessageBox.Show($"dx{1000 * dX}, dy{1000 * dY}, dz{1000 * dZ}"); _getting_suggestions = true; _application = SolidEdgeCommunity.SolidEdgeUtils.Connect(); PartDocument _doc = _application.ActiveDocument as PartDocument; Model _model = _doc.Models.Item(1); Holes _holes = _model.Holes; var cc = _holes.Count; var selected_face = pGraphicDispatch as SolidEdgeGeometry.Face; Array minparams = new double[2] as Array; Array maxparams = new double[2] as Array; selected_face.GetParamRange(ref minparams, ref maxparams); var mins = minparams as double[]; var maxs = maxparams as double[]; Array u = new double[2] { mins[0] + 0.5 * (maxs[0] - mins[0]), mins[1] + 0.5 * (maxs[1] - mins[1]) }; Array n = new double[3] as Array; //getting the normal vector of the selected face selected_face.GetNormal(1, ref u, ref n); var norm = n as double[]; int x = (int)Math.Round(norm[0]); int y = (int)Math.Round(norm[1]); int z = (int)Math.Round(norm[2]); int[] face_norm = new int[3] { x, y, z }; string Face_normal_vector = string.Format("{0:0}{1:0}{2:0}", x, y, z); //Accessing 3D mouse coordinates _mouse.PointOnGraphic(out int PointOnGraphicFlag, out double PointOnGraphic_X, out double PointOnGraphic_Y, out double PointOnGraphic_Z); MessageBox.Show($"PointonGraphic {PointOnGraphicFlag}, {PointOnGraphic_X}, {PointOnGraphic_Y}, {PointOnGraphic_Z}"); // create_hole(PointOnGraphic_X, PointOnGraphic_Y, PointOnGraphic_Z, selected_face, face_norm, Face_normal_vector); List <HoleInfo> _holeInfos = new List <HoleInfo>(); foreach (Hole hole in _holes) { HoleInfo _holeInfo = default(HoleInfo); SolidEdgePart.HoleData _holedata = hole.HoleData as SolidEdgePart.HoleData; _holeInfo.diameter = 1000 * _holedata.HoleDiameter; Profile profile = hole.Profile as Profile; Holes2d holes2d = profile.Holes2d as Holes2d; Hole2d hole2d = holes2d.Item(1); double x_2d, y_2d, x_3d, y_3d, z_3d; hole2d.GetCenterPoint(out x_2d, out y_2d); profile.Convert2DCoordinate(x_2d, y_2d, out x_3d, out y_3d, out z_3d); _holeInfo.xd = x_2d * 1000; _holeInfo.yd = y_2d * 1000; _holeInfo.x = x_3d * 1000; _holeInfo.y = y_3d * 1000; _holeInfo.z = z_3d * 1000; RefPlane plane = profile.Plane as RefPlane; Array normals = new double[3] as Array; plane.GetNormal(ref normals); double[] ns = normals as double[]; _holeInfo.nx = ns[0]; _holeInfo.ny = ns[1]; _holeInfo.nz = ns[2]; _holeInfos.Add(_holeInfo); // MessageBox.Show(string.Format("diam: {0:0.000} x: {1:0.000}, y: {2:0.000}, z: {3:0.000}, nx: {3:0.000}, ny: {3:0.000}, nz: {3:0.000}", // _holeInfo.diameter, _holeInfo.x, _holeInfo.y, _holeInfo.z, _holeInfo.nx, _holeInfo.ny, _holeInfo.nz)); } _holeInfos = _holeInfos.OrderBy(p => p.diameter).ToList(); string query = "http://trapezohedron.shapespace.com:9985/v1/suggestions?query={\"status\": {\"v\": ["; bool first = true; //adding the hole diameters to query foreach (HoleInfo hi in _holeInfos) { if (!first) { query += ", "; } first = false; string add_v = String.Format("\"{0:0.0}\"", hi.diameter); query += add_v; } query += "], \"e\": ["; double dist_bucket_size = 50; int v_source = 0; first = true; foreach (HoleInfo hi_source in _holeInfos) { int v_dest = 0; string bucket_dir_source = string.Format("{0:0.0000}{1:0.0000}{2:0.0000}", hi_source.nx, hi_source.ny, hi_source.nz); // MessageBox.Show($"Source {hi_source.x}, {hi_source.y}, {hi_source.z} --- {hi_source.nx}, {hi_source.ny}, {hi_source.nz} "); // MessageBox.Show($"{bucket_dir_source}"); foreach (HoleInfo hi_dest in _holeInfos) { if (v_dest > v_source) { //MessageBox.Show($"destination {hi_dest.x}, {hi_dest.y}, {hi_dest.z} --- {hi_dest.nx}, {hi_dest.ny}, {hi_dest.nz}"); if (!first) { query += ", "; } first = false; string bucket_dir_dest = string.Format("{0:0.0000}{1:0.0000}{2:0.0000}", hi_dest.nx, hi_dest.ny, hi_dest.nz); double e_dist = Math.Sqrt(Math.Pow(hi_source.x - hi_dest.x, 2) + Math.Pow(hi_source.y - hi_dest.y, 2) + Math.Pow(hi_source.z - hi_dest.z, 2)); //MessageBox.Show($"Bucket_dir_dest {bucket_dir_dest}, e_dist {e_dist}"); double e_dist_bucket = Math.Ceiling(e_dist / dist_bucket_size); //MessageBox.Show($"e_dist_bucket {e_dist_bucket}"); string add_e = string.Format("[[\"{0:0.0}\", \"{1:0.0}\"], \"{2:0}\"]", hi_source.diameter, hi_dest.diameter, e_dist_bucket); if (bucket_dir_source == bucket_dir_dest) { add_e += string.Format(",[[\"{0:0.0}\", \"{1:0.0}\"], \"co_dir\"]", hi_source.diameter, hi_dest.diameter); //add_e += string.Format("[[\"{0:0.0}\", \"{1:0.0}\"], \"co_dir\"]", hi_source.diameter, hi_dest.diameter); } query += add_e; } v_dest += 1; } v_source += 1; } // query += "]}, \"location\":[[[\"32.0\", \"*\"], \"co_dir\"],"; query += "]}, \"location\": ["; first = true; //Calculating distance from the mouse location to the hole center points foreach (HoleInfo H_dest in _holeInfos) { if (!first) { query += ", "; } first = false; double e_dest = Math.Sqrt(Math.Pow(H_dest.x - (1000 * PointOnGraphic_X), 2) + Math.Pow(H_dest.y - (1000 * PointOnGraphic_Y), 2) + Math.Pow(H_dest.z - (1000 * PointOnGraphic_Z), 2)); double e_dist_bucket = Math.Ceiling(e_dest / dist_bucket_size); string add_e = string.Format("[[\"{0:0.0}\", \"*\"], \"{1:0}\"]", H_dest.diameter, e_dist_bucket); string Hole_Normal_vector = string.Format("{0:0}{1:0}{2:0}", H_dest.nx, H_dest.ny, H_dest.nz); if (Hole_Normal_vector == Face_normal_vector) { add_e += string.Format(", [[\"{0:0.0}\", \"*\"], \"co_dir\"]", H_dest.diameter); //MessageBox.Show($"2D coordinates {H_dest.xd},{H_dest.yd}"); } query += add_e; } query += "]}"; MessageBox.Show($"{query}"); //string query = "http://trapezohedron.shapespace.com:9985/v1/suggestions?query={\"status\": {\"v\": [\"32.0\", \"57.0\"], \"e\": [[[\"32.0\", \"57.0\"], \"co_dir\"]]}, \"location\": [[[\"32.0\", \"*\"], \"co_dir\"]]}"; var values = new Dictionary <string, string> { }; var content = new FormUrlEncodedContent(values); var response = await _client.GetAsync(query); var responseString = await response.Content.ReadAsStringAsync(); MessageBox.Show(responseString); string pattern = @"\d*\.\d"; matchCollection = Regex.Matches(responseString, pattern); count = matchCollection.Count; Match = new double[count]; int i = 0; string match = ""; foreach (Match m in matchCollection) { match += string.Format("{0} ", m.Value); Match[i] = Convert.ToDouble(m.Value); i++; } // MessageBox.Show($"{match}"); create_hole(PointOnGraphic_X, PointOnGraphic_Y, PointOnGraphic_Z, selected_face, face_norm, Face_normal_vector); _getting_suggestions = false; } catch (Exception ex) { MessageBox.Show(ex.Message); } } if (checkcutout) { try { //MessageBox.Show("cutout feature selected"); _getting_suggestions = true; _application = SolidEdgeCommunity.SolidEdgeUtils.Connect(); PartDocument _doc = _application.ActiveDocument as PartDocument; Model _model = _doc.Models.Item(1); ExtrudedCutouts _extrudedCutouts = _model.ExtrudedCutouts; int a = _extrudedCutouts.Count; var selected_face = pGraphicDispatch as SolidEdgeGeometry.Face; Array minparams = new double[2] as Array; Array maxparams = new double[2] as Array; selected_face.GetParamRange(ref minparams, ref maxparams); var mins = minparams as double[]; var maxs = maxparams as double[]; Array u = new double[2] { mins[0] + 0.5 * (maxs[0] - mins[0]), mins[1] + 0.5 * (maxs[1] - mins[1]) }; Array n = new double[3] as Array; //getting the normal vector of the selected face selected_face.GetNormal(1, ref u, ref n); var norm = n as double[]; int x = (int)Math.Round(norm[0]); int y = (int)Math.Round(norm[1]); int z = (int)Math.Round(norm[2]); int[] face_norm = new int[3] { x, y, z }; string Face_normal_vector = string.Format("{0:0}{1:0}{2:0}", x, y, z); //Accessing 3D mouse coordinates _mouse.PointOnGraphic(out int PointOnGraphicFlag, out double PointOnGraphic_X, out double PointOnGraphic_Y, out double PointOnGraphic_Z); List <CutoutInfo> _Cutoutinfos = new List <CutoutInfo>(); foreach (ExtrudedCutout extrudedCutout in _extrudedCutouts) { CutoutInfo _cutoutInfo = default(CutoutInfo); _cutoutInfo.KeyPoints = new List <double>(); Profile profile = extrudedCutout.Profile as Profile; SolidEdgeFrameworkSupport.Lines2d lines2D = profile.Lines2d; double x_3d, y_3d, z_3d, x_3D, y_3D, z_3D; int handletype; SolidEdgeFramework.KeyPointType KeyPointType; int rc = lines2D.Count; for (int j = 1; j <= rc; j++) { var ii = lines2D.Item(j); int keycout = ii.KeyPointCount; for (int i = 0; i < keycout; i++) { ii.GetKeyPoint(i, out x_3d, out y_3d, out z_3d, out KeyPointType, out handletype); profile.Convert2DCoordinate(x_3d, y_3d, out x_3D, out y_3D, out z_3D); _cutoutInfo.KeyPoints.Add(x_3D * 1000); _cutoutInfo.KeyPoints.Add(y_3D * 1000); _cutoutInfo.KeyPoints.Add(z_3D * 1000); } } RefPlane plane = profile.Plane as RefPlane; Array normals = new double[3] as Array; plane.GetNormal(ref normals); //getting the normal vector of the cutout profile double[] ns = normals as double[]; _cutoutInfo.nx = ns[0]; _cutoutInfo.ny = ns[1]; _cutoutInfo.nz = ns[2]; _Cutoutinfos.Add(_cutoutInfo); } var dd = _Cutoutinfos[0].KeyPoints[0]; foreach (CutoutInfo info in _Cutoutinfos) { //MessageBox.Show($"{Math.Round(info.nx)},{Math.Round(info.ny)},{Math.Round(info.nz)}"); string Cutout_normal_vector = string.Format("{0:0}{1:0}{2:0}", Math.Round(info.nx), Math.Round(info.ny), Math.Round(info.nz)); if (Face_normal_vector == Cutout_normal_vector) { MessageBox.Show("Co-dir"); } } Create_Cutout(PointOnGraphic_X, PointOnGraphic_Y, PointOnGraphic_Z, selected_face, face_norm, Face_normal_vector); } catch (Exception ex) { MessageBox.Show(ex.Message); } } if (checkslot) { try { // MessageBox.Show("Slot feature selected"); _getting_suggestions = true; _application = SolidEdgeCommunity.SolidEdgeUtils.Connect(); PartDocument _doc = _application.ActiveDocument as PartDocument; Model _model = _doc.Models.Item(1); Slots slots = _model.Slots; int cc = slots.Count; var selected_face = pGraphicDispatch as SolidEdgeGeometry.Face; Array minparams = new double[2] as Array; Array maxparams = new double[2] as Array; selected_face.GetParamRange(ref minparams, ref maxparams); var mins = minparams as double[]; var maxs = maxparams as double[]; Array u = new double[2] { mins[0] + 0.5 * (maxs[0] - mins[0]), mins[1] + 0.5 * (maxs[1] - mins[1]) }; Array n = new double[3] as Array; //getting the normal vector of the selected face selected_face.GetNormal(1, ref u, ref n); var norm = n as double[]; int x = (int)Math.Round(norm[0]); int y = (int)Math.Round(norm[1]); int z = (int)Math.Round(norm[2]); int[] face_norm = new int[3] { x, y, z }; string Face_normal_vector = string.Format("{0:0}{1:0}{2:0}", x, y, z); //Accessing 3D mouse coordinates _mouse.PointOnGraphic(out int PointOnGraphicFlag, out double PointOnGraphic_X, out double PointOnGraphic_Y, out double PointOnGraphic_Z); List <Slotinfo> _Slotinfos = new List <Slotinfo>(); foreach (Slot slot in slots) { Slotinfo _SlotInfo = default(Slotinfo); _SlotInfo.KeyPoints = new List <double>(); Profile profile = slot.Profile as Profile; Lines2d lines2D = profile.Lines2d; int lincount = lines2D.Count; double x_3d, y_3d, z_3d, x_3D, y_3D, z_3D; int handletype; KeyPointType KeyPointType; int rc = lines2D.Count; for (int j = 1; j <= rc; j++) { var ii = lines2D.Item(j); int keycout = ii.KeyPointCount; for (int i = 0; i < keycout; i++) { ii.GetKeyPoint(i, out x_3d, out y_3d, out z_3d, out KeyPointType, out handletype); profile.Convert2DCoordinate(x_3d, y_3d, out x_3D, out y_3D, out z_3D); _SlotInfo.KeyPoints.Add(x_3D * 1000); _SlotInfo.KeyPoints.Add(y_3D * 1000); _SlotInfo.KeyPoints.Add(z_3D * 1000); } } RefPlane plane = profile.Plane as RefPlane; Array normals = new double[3] as Array; plane.GetNormal(ref normals); //getting the normal vector of the cutout profile double[] ns = normals as double[]; _SlotInfo.nx = ns[0]; _SlotInfo.ny = ns[1]; _SlotInfo.nz = ns[2]; _Slotinfos.Add(_SlotInfo); } var dd = _Slotinfos[0].KeyPoints[0]; foreach (Slotinfo info in _Slotinfos) { //Comparing the normal vector of the face to the slot normal vector string Slot_normal_vector = string.Format("{0:0}{1:0}{2:0}", Math.Round(info.nx), Math.Round(info.ny), Math.Round(info.nz)); if (Face_normal_vector == Slot_normal_vector) { MessageBox.Show("Co-dir"); } } Create_Slot(PointOnGraphic_X, PointOnGraphic_Y, PointOnGraphic_Z, selected_face, face_norm, Face_normal_vector); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
// Avvia SE, restituisce string con messaggio public string AvviaSolidEdge() { string messaggio = ""; // Legge eventuale istanza attiva. Eccezione se nessuna istanza try { application = (SolidEdgeFramework.Application)Marshal.GetActiveObject("SolidEdge.Application"); } catch { application = null; // Genera eccezione se SE non e` avviato } if (application != null) // Se non e` attivo, lancia l'istanza { messaggio = "Istanza Solid Edge gia` in funzione"; } else { try { // Prova avvio di Solid Edge type = Type.GetTypeFromProgID("SolidEdge.Application"); // Legge il tipo di appl. associato a SE application = (SolidEdgeFramework.Application)Activator.CreateInstance(type); // Lancia un'istanza application.Visible = true; messaggio = "Avviato"; } catch (System.Exception ex) // Messaggio se eccezione { messaggio = "Eccezione: " + ex.Message; } finally // Pulitura, eseguita sempre { if (application != null) { Marshal.ReleaseComObject(application); application = null; } } } return messaggio; }