Visio

2011-06-06 9 views
6

में आकार के गुणों को कैसे पढ़ा जाए मेरे पास निम्न कार्य है। मैं स्टूडियो 2010 में सी # पर विज़ियो 2010 के लिए ऐड-इन लिख रहा हूं। मान लें कि मेरे पास एक आरेख खोला गया है। और मेरे पास इस आरेख में किसी भी तरह का आकार है (चलो शुरुआत के लिए एक आकार का प्रबंधन करने की कोशिश करें)। सवाल यह है कि मैं इस आकार के किसी भी गुण को कैसे पढ़ सकता हूं? मुझे किस एपीआई का उपयोग करना चाहिए?Visio

बेसिक एल्गोरिथ्म:

  1. स्कैन आकार के लिए दस्तावेज़ खोला
  2. अगर कोई आकार दस्तावेज़ में, तो सभी आकृति की एक सरणी (या एक सूची) वापसी (शून्य कोई आकार के मामले में दिया जाता है कर रहे हैं वर्तमान दस्तावेज़ में)
  3. भागो आकार सरणी पर और प्रत्येक तत्व के लिए किसी भी संपत्ति को पढ़ने के (है कि लिखने के लिए एक मौका/संपत्ति

(कोड उदाहरण के लिए संशोधित) बहुत एक होगा बहुत अच्छा होगा ppreciated)

उत्तर

8

मुझे लगता है कि गुणों से आप आकार डेटा का जिक्र कर रहे हैं, जिसे यूआई में कस्टम प्रॉपर्टी कहा जाता था और अभी भी एपीआई में उस नाम से पता है।

यदि आप आकार की शीट से परिचित नहीं हैं तो आपको आकार की परिभाषाओं को परिभाषित करने के लिए पहले आकार के कस्टम गुणों के साथ एक आकार को देखना चाहिए था। Visio 2010 में आकार बदलने के तरीके को जानने के लिए "What happened to the ShapeSheet?" देखें।

निम्नलिखित उदाहरण प्रोग्राम आपको प्रारंभ करना चाहिए। यह उदाहरण मानता है कि आपके पास पीसी पर Visio Primary Interop Assembly इंस्टॉल है और आपने अपनी प्रोजेक्ट में Microsoft.Office.Interop.Visio में रेफरी शामिल की है।

namespace VisioEventsExample 
{ 
    using System; 
    using Microsoft.Office.Interop.Visio; 

    class Program 
    { 
     public static void Main(string[] args) 
     { 
      // Open up one of Visio's sample drawings. 
      Application app = new Application(); 
      Document doc = app.Documents.Open(
       @"C:\Program Files\Microsoft Office\Office14\visio content\1033\ASTMGT_U.VST"); 

      // Get the first page in the sample drawing. 
      Page page = doc.Pages[1]; 

      // Start with the collection of shapes on the page and 
      // print the properties we find, 
      printProperties(page.Shapes); 
     } 

     /* This function will travel recursively through a collection of 
     * shapes and print the custom properties in each shape. 
     * 
     * The reason I don't simply look at the shapes in Page.Shapes is 
     * that when you use the Group command the shapes you group become 
     * child shapes of the group shape and are no longer one of the 
     * items in Page.Shapes. 
     * 
     * This function will not recursive into shapes which have a Master. 
     * This means that shapes which were created by dropping from stencils 
     * will have their properties printed but properties of child shapes 
     * inside them will be ignored. I do this because such properties are 
     * not typically shown to the user and are often used to implement 
     * features of the shapes such as data graphics. 
     * 
     * An alternative halting condition for the recursion which may be 
     * sensible for many drawing types would be to stop when you 
     * find a shape with custom properties. 
     */ 
     public static void printProperties(Shapes shapes) 
     { 
      // Look at each shape in the collection. 
      foreach (Shape shape in shapes) 
      {    
       // Use this index to look at each row in the properties 
       // section. 
       short iRow = (short) VisRowIndices.visRowFirst; 

       // While there are stil rows to look at. 
       while (shape.get_CellsSRCExists(
        (short) VisSectionIndices.visSectionProp, 
        iRow, 
        (short) VisCellIndices.visCustPropsValue, 
        (short) 0) != 0) 
       { 
        // Get the label and value of the current property. 
        string label = shape.get_CellsSRC(
          (short) VisSectionIndices.visSectionProp, 
          iRow, 
          (short) VisCellIndices.visCustPropsLabel 
         ).get_ResultStr(VisUnitCodes.visNoCast); 

        string value = shape.get_CellsSRC(
          (short) VisSectionIndices.visSectionProp, 
          iRow, 
          (short) VisCellIndices.visCustPropsValue 
         ).get_ResultStr(VisUnitCodes.visNoCast); 

        // Print the results. 
        Console.WriteLine(string.Format(
         "Shape={0} Label={1} Value={2}", 
         shape.Name, label, value)); 

        // Move to the next row in the properties section. 
        iRow++; 
       } 

       // Now look at child shapes in the collection. 
       if (shape.Master == null && shape.Shapes.Count > 0) 
        printProperties(shape.Shapes); 
      } 
     } 
    } 
} 
+0

हैलो पैट अपने विस्तृत करने के लिए धन्यवाद जवाब। उसने मुझे कुछ विचार दिए। मैं आपकी मदद और कई पुस्तकों के साथ अपने काम के साथ आगे बढ़ने में कामयाब रहा। मैं अगले महीने या दो के लिए Visio के साथ मिलकर काम करने की योजना बना रहा हूं। क्या मैं आपको लिंक्डइन में अपने संपर्कों में जोड़ सकता हूं क्योंकि मुझे आपकी मदद और सलाह की आवश्यकता हो सकती है? (मैंने एक निमंत्रण भेजा है) फिर से धन्यवाद। दान –

+0

डेनििल, यदि आपके पास सॉफ्टवेयर विकास संबंधी प्रश्न हैं तो कृपया उन्हें स्टैक ओवरफ़्लो पर पूछें। अगर आपको मुझसे निजी तौर पर संपर्क करने की ज़रूरत है तो कृपया मेरे प्रोफाइल में मेरे ईमेल पते का उपयोग करें। - पैट –

4

मैं a library that makes this a easier

लिखा एकाधिक आकृतियों के लिए गुण प्राप्त करने के लिए:

var shapes = new[] {s1, s2}; 
var props = VA.CustomProperties.CustomPropertyHelper.GetCustomProperties(page, shapes); 

वापसी रंगमंच की सामग्री में संग्रहीत मूल्य शब्दकोशों की एक सूची हो जाएगा। प्रत्येक शब्दकोश निर्दिष्ट आकार के गुणों से मेल खाता है। गुणों के नाम शब्दकोश में कुंजी हैं।

पहले आकार के लिए "फू" संपत्ति प्राप्त करने के लिए ...

props[0]["Foo"] 

जो एक वस्तु है जो एक संपत्ति के इन पहलुओं के लिए सूत्र & परिणाम होता है पुन: प्राप्त करता:

  • कैलेंडर
  • स्वरूप
  • अदृश्य
  • लेबल
  • LangID
  • शीघ्र
  • SortKey
  • प्रकार
  • मूल्य
  • उन सभी, जो बाद में इस प्रश्न पर कोड मदद की जरूरत होगी करने के लिए
+0

हैलो सेवनेर। मैं आपकी मदद करने के लिए तैयार की सराहना करता हूं। आपका बहुत बहुत धन्यवाद। –

+0

ग्रेट लाइब्रेरी। धन्यवाद! –

0

सत्यापित करें:

... 
using Visio = Microsoft.Office.Interop.Visio; 

namespace RibbonCustomization 
{ 
    [ComVisible(true)] 
    public class Ribbon1 : Office.IRibbonExtensibility 
    { 

     public void ReadShapes(Microsoft.Office.Core.IRibbonControl control) 
     { 
     ExportElement exportElement; 
     ArrayList exportElements = new ArrayList(); 

     Visio.Document currentDocument = Globals.ThisAddIn.Application.ActiveDocument; 
     Visio.Pages Pages = currentDocument.Pages; 
     Visio.Shapes Shapes; 

     foreach(Visio.Page Page in Pages) 
     { 
      Shapes = Page.Shapes; 
      foreach (Visio.Shape Shape in Shapes) 
      { 
       exportElement = new ExportElement(); 
       exportElement.Name = Shape.Master.NameU; 
       exportElement.ID = Shape.ID;    
       exportElement.Text = Shape.Text; 
       ... 
       // and any other properties you'd like 

       exportElements.Add(exportElement); 
      } 
     } 
.... 
संबंधित मुद्दे