public void CreateShape(Visio.Application VApp, Visio.IVDocument drawingDocument) { Visio_shape = VisioInterface.CreateVisioShape(VApp, drawingDocument, X_coord, Y_coord, stencilName, masterNameU); if (Visio_shape == null) { DebugEx.WriteLine(string.Format("Error creating Visio shape for {0}", FullName)); } }
//CONNECT TO SHAPES public static Visio.IVShape CreateVisioShape(Visio.Application vApp, Visio.IVDocument drawingDocuemnt, double X_in, double Y_in, string stencilName, string masterNameU) { // Find the stencil in the Documents collection by name. Visio.IVDocuments visioDocuments = vApp.Documents; Visio.IVShape droppedShape = null; Visio.IVMaster masterInStencil; Visio.IVPage page = drawingDocuemnt.Pages.First(); //get width and height of the sheet double Sheet_Width = page.PageSheet.get_CellsU("PageWidth").ResultIU; double Sheet_Height = page.PageSheet.get_CellsU("PageHeight").ResultIU; Sheet_Width = Sheet_Width - 3; Sheet_Height = Sheet_Height - 3; Visio.IVDocument stencil; try { stencil = visioDocuments[stencilName]; } catch (System.Runtime.InteropServices.COMException) { // The stencil is not in the collection; open it as a // docked stencil. stencil = visioDocuments.OpenEx(stencilName, (short)VisOpenSaveArgs.visOpenDocked); } // Get a master from the stencil by its universal name. try { masterInStencil = stencil.Masters.get_ItemU(masterNameU); double actual_xposition = (Sheet_Width * X_in) + 2; double actual_yposition = (Sheet_Height * Y_in) + 2; droppedShape = page.Drop(masterInStencil, actual_xposition, actual_yposition); } catch (Exception Ex) { System.Windows.Forms.MessageBox.Show(string.Format("Cannot create Visio shape. Error is : {0} {1}", Ex.Message, Ex.InnerException?.Message), "Visio interface error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand); } return(droppedShape); }
public Form1() { InitializeComponent(); Visio.Application application = new Visio.Application(); application.Visible = true; var doc = application.Documents.Add(""); Visio.IVPage page = application.ActivePage; var shape = page.DrawRectangle(0, 0, 2, 3); shape.Text = "With Microsoft.Office.Interop.Visio"; doc.Saved = true; var SID_SRCStream = new short[4]; SID_SRCStream[0] = (short)shape.ID16; SID_SRCStream[1] = (short)VisSectionIndices.visSectionObject; SID_SRCStream[2] = (short)VisRowIndices.visRowFill; SID_SRCStream[3] = (short)VisCellIndices.visFillForegnd; try { object[] a = null;// new Array[4]; page.GetFormulasTest(SID_SRCStream, out a); // page.GetFormulas(SID_SRCStream, out a); } catch (Exception exception) { Console.WriteLine(exception.ToString()); } try { application.Quit(); application.Dispose(); } catch { // may closed by user } }
private void CreateOfficeApplication() { switch (_officeApp) { case "Excel": _excelApplication = new Excel.Application("Excel.Application"); break; case "Word": _wordApplication = new Word.Application("Word.Application"); break; case "Outlook": _outlookApplication = new Outlook.Application("Outlook.Application"); break; case "Power Point": _powerpointApplication = new PowerPoint.Application("PowerPoint.Application"); break; case "Access": _accessApplication = new Access.Application("Access.Application"); break; case "Project": _projectApplication = new Project.Application("MSProject.Application"); break; case "Visio": _visioApplication = new Visio.Application("Visio.Application"); break; default: throw new ArgumentOutOfRangeException("officeApp"); } }
public NetOfficeSupportTable() { Project.Application app1 = null; Visio.Application app2 = null; Console.WriteLine(app1); Console.WriteLine(app2); AssemblyName[] referencedAssemblies = _thisAssembly.GetReferencedAssemblies(); foreach (AssemblyName item in referencedAssemblies) { { if (item.Name.StartsWith("OfficeApi")) { string assemblyPath = GetPhysicalPath(item); Stream stream = System.IO.File.OpenRead(assemblyPath); _assOffice = AssemblyDefinition.ReadAssembly(stream); } else if (item.Name.StartsWith("ExcelApi")) { string assemblyPath = GetPhysicalPath(item); Stream stream = System.IO.File.OpenRead(assemblyPath); _assExcel = AssemblyDefinition.ReadAssembly(stream); } else if (item.Name.StartsWith("WordApi")) { string assemblyPath = GetPhysicalPath(item); Stream stream = System.IO.File.OpenRead(assemblyPath); _assWord = AssemblyDefinition.ReadAssembly(stream); } else if (item.Name.StartsWith("OutlookApi")) { string assemblyPath = GetPhysicalPath(item); Stream stream = System.IO.File.OpenRead(assemblyPath); _assOutlook = AssemblyDefinition.ReadAssembly(stream); } else if (item.Name.StartsWith("OutlookApi")) { string assemblyPath = GetPhysicalPath(item); Stream stream = System.IO.File.OpenRead(assemblyPath); _assOutlook = AssemblyDefinition.ReadAssembly(stream); } else if (item.Name.StartsWith("PowerPointApi")) { string assemblyPath = GetPhysicalPath(item); Stream stream = System.IO.File.OpenRead(assemblyPath); _assPowerPoint = AssemblyDefinition.ReadAssembly(stream); } else if (item.Name.StartsWith("AccessApi")) { string assemblyPath = GetPhysicalPath(item); Stream stream = System.IO.File.OpenRead(assemblyPath); _assAccess = AssemblyDefinition.ReadAssembly(stream); } else if (item.Name.StartsWith("MSProjectApi")) { string assemblyPath = GetPhysicalPath(item); Stream stream = System.IO.File.OpenRead(assemblyPath); _assMSProject = AssemblyDefinition.ReadAssembly(stream); } else if (item.Name.StartsWith("VisioApi")) { string assemblyPath = GetPhysicalPath(item); Stream stream = System.IO.File.OpenRead(assemblyPath); _assVisio = AssemblyDefinition.ReadAssembly(stream); } } } }
private void MainRibbon_Load(object sender, RibbonUIEventArgs e) { this.group1.Visible = false; var defaultitem = Globals.Factory.GetRibbonFactory().CreateRibbonDropDownItem(); defaultitem.Label = "none"; this.ModelTargetDropDown.Items.Add(defaultitem); startupTask = Task.Run(() => { //get current application this.application = NetOffice.VisioApi.Application.GetActiveInstance(); this.spesapp = new SpesActivities(this.application); //add modelverifiers modelverifiers.Add(new ScenarioNetwork(application)); modelverifiers.Add(new FunktionsnetzNetwork(application)); modelverifiers.Add(new ZielmodellNetwork(application)); //new ones modelverifiers.Add(new WissenskontextNetwork(application)); modelverifiers.Add(new StrukturellerKontextNetwork(application)); modelverifiers.Add(new FunktionellerKontextNetwork(application)); modelverifiers.Add(new SzenarioUseCasesNetwork(application)); modelverifiers.Add(new StrukturellePerspektiveNetwork(application)); modelverifiers.Add(new FunktionellePerspektiveNetwork(application)); modelverifiers.Add(new VerhaltensperspektiveNetwork(application)); modelverifiers.Add(new LogicalViewpointNetwork(application)); modelverifiers.Add(new TechnicalViewpointNetwork(application)); //add modelverifiers to dropdown menu and subscribe to events foreach (var obj in modelverifiers) { //dropdown var item = Globals.Factory.GetRibbonFactory().CreateRibbonDropDownItem(); item.Label = obj.ModelName; this.ModelTargetDropDown.Items.Add(item); //sub to log messages etc. obj.OnErrorReceivedEvent += delegate(Exception pEx) { //move to most inner exception while (pEx.InnerException != null) { pEx = pEx.InnerException; } System.Windows.Forms.MessageBox.Show(pEx.Message); }; //obj.OnLogMessageReceivedEvent += delegate (String pMessage) { System.Windows.Forms.MessageBox.Show(pMessage); }; } //init stencils for modelverifiers modelverifiers.ForEach(t => t.CheckStencils()); //call selection changed for init shape load (only if document is loaded) if (application.ActiveDocument != null) { ModelTargetDropDown_SelectionChanged(null, null); } //subscribe to application events application.DocumentCreatedEvent += Application_DocumentLoadedOrCreated; application.DocumentOpenedEvent += Application_DocumentLoadedOrCreated; application.EnterScopeEvent += delegate(IVApplication app, int id, string description) { //4490 = hyperlink event if (id == 4490) { this.initialized = false; } }; }); startupTask.ContinueWith(t => { this.group1.Visible = true; this.ModelTargetDropDown.Enabled = true; this.VerifyButton.Enabled = true; this.ImportButton.Enabled = true; this.ExportButton.Enabled = true; this.CreateNewSPESProject.Enabled = true; this.GenerateSubmodelsButton.Enabled = true; this.CompleteInterfaceAutomata.Enabled = true; this.CreateNewEngineeringPath.Enabled = true; ModelTargetDropDown_SelectionChanged(null, null); } ); }
void IDTExtensibility2.OnConnection(object Application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom) { try { this.Application = new Visio.Application(null, Application); } catch (System.Exception exception) { NetOffice.DebugConsole.WriteException(exception); bool handled = false; RaiseErrorHandlerMethod(exception, ref handled); if (!handled) throw exception; } RaiseOnConnection(Application, ConnectMode, AddInInst, ref custom); }