Hinzufügen von Formen zu einem Neuen Visio-Dokument

Habe ich diesen code erstellt eine neue Visio-Dokument und fügt ein Rechteck hinzu. Es funktioniert, aber ich mag es nicht, um ein anderes Dokument zu Holen Sie sich die Meister-Kollektion von ihm. Das Problem ist das neue Dokument enthält eine leere Master-shape-Kollektion. Ich konnte Sie nicht finden, eine Methode der Document-Klasse zum hinzufügen von Formen, um die Meister-Sammlung und alle die Beispiele, die ich finden konnte, für das hinzufügen von Formen angenommen, dass Sie ein vorhandenes Dokument. Gibt es eine bessere Weise, das zu tun, was ich will?

//create the new application
Visio.Application va = new Microsoft.Office.Interop.Visio.Application();

        //add a document
        va.Documents.Add(@"");

       //Visio.Documents vdocs = va.Documents;

        //we need this document to get its Masters shapes collection
        //since our new document has none 
        Visio.Document vu = vdocs.OpenEx(@"C:\Program Files (x86)\Microsoft       Office\Office12\1033\Basic_U.vss", (short)Microsoft.Office.Interop.Visio.VisOpenSaveArgs.visOpenDocked);

        //set the working  document to our new document
        Visio.Document vd = va.ActiveDocument;

        //set the working page to the active page
        Microsoft.Office.Interop.Visio.Page vp = va.ActivePage;

      //if we try this from the Masters collection from our new document
      //we get a run time since our masters collection is empty
     Visio.Master vm  = vu.Masters.get_ItemU(@"Rectangle");
    Visio.Shape visioRectShape = vp.Drop(vm, 4.25, 5.5);
        visioRectShape.Text = @"Rectangle text.";
InformationsquelleAutor David Green | 2012-02-27
Schreibe einen Kommentar