2016-03-14 2 views
1

Кто-нибудь знает, как использовать метод visio insertListMember (см. Ниже) в C#? https://msdn.microsoft.com/en-us/library/office/ff768115.aspxvisio insertlistmember в C#

Я попытался выполнить метод с помощью следующих команд, но это дает «Run Time error- 424 объект, необходимый» я также использовал метод dropIntoList и он работает нормально, но для конкретных целей нужно использовать метод insertListMember. (Для определения высоты списка)

static void Main(string[] args) 
    { 
     //create the object that will do the drawing 
     visioDrawing.VisioDrawer Drawer = new visioDrawing.VisioDrawer(); 
     Drawer.setUpVisio(); 

     Visio.Shape testShape; 
     Visio.Shape testShape1; 


     testShape = Drawer.DropShape("abc", "lvl1Box"); 
     testShape1 = Drawer.DropShape("ccc", "Capability"); 
     Drawer.insertListMember(testShape, testShape1, 1); 
    } 


    public void insertListMember(Visio.Shape outerlist, Visio.Shape innerShape, int position) 
    { 
     ActiveDoc.ExecuteLine(outerlist + ".ContainerProperties.InsertListMember" + innerShape + "," + position); 
    } 

Чтобы получить форму:

public Visio.Shape DropShape(string rectName, string masterShape) 
    { 
     //get the shape to drop from the masters collection 
     Visio.Master shapetodrop = GetMaster(stencilPath, masterShape); 
     // drop a shape on the page 
     Visio.Shape DropShape = acPage.Drop(shapetodrop, 1, 1); 
     //put name in the shape 
     Visio.Shape selShape = selectShp(DropShape.ID); 
     selShape.Text = rectName; 
     return DropShape; 
    } 

    private Visio.Master GetMaster(string stencilName, string mastername) 
    { 
     // open the page holding the masters collection so we can use it 
     MasterDoc = MastersDocuments.OpenEx(stencilName, (short)Visio.VisOpenSaveArgs.visOpenDocked); 
     // now get a masters collection to use 
     Masters = MasterDoc.Masters; 
     return Masters.get_ItemU(mastername); 
    } 

ответ

1

С вашего кода, «Ящик» выглядит какой-то Visio приложение обертку, но по существу InsertListMember позволяет для добавления фигур в список, который уже существует на странице. Вот пример метода и альтернативный Page.DropIntoList, если вы просто хотите отказаться от непосредственно из трафарета:

void Main() 
{ 
    // 'GetRunningVisio' as per 
    // http://visualsignals.typepad.co.uk/vislog/2015/12/getting-started-with-c-in-linqpad-with-visio.html 
    // but all you need is a reference to the app 
    var vApp = MyExtensions.GetRunningVisio(); 

    var vDoc = vApp.Documents.Add("wfdgm_m.vstx"); 
    var vPag = vDoc.Pages[1]; 
    var vCtrlsStencil = vApp.Documents["WFCTRL_M.VSSX"]; 
    var vListMst = vCtrlsStencil?.Masters["List box"]; 
    if (vListMst != null) 
    { 
     var vListShp = vPag.Drop(vListMst, 2, 6); 
     var vListItemMst = vCtrlsStencil.Masters["List box item"]; 

     var insertPosition = vListShp.ContainerProperties.GetListMembers().Length - 1; 

     //Use InsertListMember method 
     var firstListItem = vPag.Drop(vListItemMst, 4, 6); 
     vListShp.ContainerProperties.InsertListMember(firstListItem, insertPosition); 
     firstListItem.CellsU["FillForegnd"].FormulaU = "3"; //Green 

     //or use DropIntoList method on Page instead 
     var secondListItem = vPag.DropIntoList(vListItemMst, vListShp, insertPosition); 
     secondListItem.CellsU["FillForegnd"].FormulaU = "2"; //Red 
    } 
} 

Это использует шаблон каркасной Диаграммы (в Visio Professional) и должно привести к следующим результатам:

enter image description here

0

В случае, если люди задавались вопросом, я в конечном итоге установил метод вверх. Однако я считаю, что этот метод не требуется, если вы используете сборки Visio Interop v15. (Я использую v14)

public void insertListMember(int outerShpID, int innerShpID, int position) 
    { 
     acWindow.DeselectAll(); 
     Visio.Page page = acWindow.Page; 
     acWindow.Select(page.Shapes.get_ItemFromID(innerShpID), (short)Microsoft.Office.Interop.Visio.VisSelectArgs.visSelect); 
     Debug.WriteLine("Application.ActivePage.Shapes.ItemFromID(" + outerShpID + ").ContainerProperties.InsertListMember ActiveWindow.Selection," + position); 
     ActiveDoc.ExecuteLine("Application.ActivePage.Shapes.ItemFromID(" + outerShpID + ").ContainerProperties.InsertListMember ActiveWindow.Selection," + position); 
    } 
Смежные вопросы