我尝试使用以下代码连接几个形状:
Visio.Master ConnectionMaster = _masters.get_ItemU(connectorShapeName);
Visio.Shape Connector = _activePage.Drop(ConnectionMaster, 1, 1);
// get the start cell of connector
var b1 = (short) Visio.VisSectionIndices.visSectionObject;
var b2 = (short) Visio.VisRowIndices.visRowXForm1D;
var b3 = (short) Visio.VisCellIndices.vis1DBeginX;
Visio.Cell beginXCell = Connector.get_CellsSRC(b1, b2, b3);
// and the end one
var e1 = (short) Visio.VisSectionIndices.visSectionObject;
var e2 = (short) Visio.VisRowIndices.visRowXForm1D;
var e3 = (short) Visio.VisCellIndices.vis1DEndX;
Visio.Cell endXCell = Connector.get_CellsSRC(e1, e2, e3);
// get start point from first shape
var bt1 = (short) Visio.VisSectionIndices.visSectionObject;
var bt2 = (short) Visio.VisRowIndices.visRowXFormOut;
var bt3 = (short) Visio.VisCellIndices.visXFormPinX;
var toBegin = fromShape.get_CellsSRC(bt1, bt2, bt3);
// get start point of second shape
var et1 = (short) Visio.VisSectionIndices.visSectionObject;
var et2 = (short) Visio.VisRowIndices.visRowXFormOut;
var et3 = (short) Visio.VisCellIndices.visXFormPinX;
var toEnd = toShape.get_CellsSRC(et1, et2, et3);
// connect
beginXCell.GlueTo(toBegin);
endXCell.GlueTo(toEnd);
此代码非常适合使用以下代码添加到visio文档的形状:
Visio.Master shapeToDrop = _masters.get_ItemU(name);
Visio.Shape shape = _activePage.Drop(shapeToDrop, x, y);
但是,如果将shape拖放到doc中,然后添加到列表中,就像这样:
var shape = _activePage.DropIntoList(shapeToDrop, target, position);
我收到错误:“发生异常。” 在此代码中:
var toBegin = fromShape.get_CellsSRC(bt1, bt2, bt3);
那么,连接列表中形状的正确方法是什么?我在做什么错了?
谢谢!
答案 0 :(得分:0)
我怀疑您的问题与连接无关,但与将项目放入列表中时确保类别匹配有关。这是演示该问题的简短示例(从Visio中的空白图形开始):
# convert to data.table
setDT(df)
# order, group, filter
df[order(stopSequence)][, .SD[c(1, .N)], by = id]
id stopId stopSequence
1: 1 a 1
2: 1 c 3
3: 2 b 1
4: 2 c 4
5: 3 b 1
6: 3 a 3
您可能应该进行快速检查,以阅读项目形状中的void Main()
{
//Run this code against a blank drawing in Visio
var vApp = MyExtensions.GetRunningVisio();
var vDoc = vApp.ActiveDocument;
var stencilDoc = vDoc.Application.Documents.OpenEx("wfctrl_m.vssx",
(short)Visio.VisOpenSaveArgs.visOpenRO
+ (short)Visio.VisOpenSaveArgs.visOpenDocked);
var vPag = vApp.ActivePage;
var diagramServices = vDoc.DiagramServicesEnabled;
vDoc.DiagramServicesEnabled = (int)Visio.VisDiagramServices.visServiceVersion140
+ (int)Visio.VisDiagramServices.visServiceVersion150;
var shpList = vPag.Drop(stencilDoc.Masters.ItemU["List box"], 2.25, 9.5);
var itemMaster = stencilDoc.Masters.ItemU["List box item"];
// Drop two items in - this works because the item
// shapes have the correct required categories ('Grid')
vPag.DropIntoList(itemMaster, shpList, 1);
vPag.DropIntoList(itemMaster, shpList, 1);
// Now set the list's required categories to someting else
shpList.CellsU["User.msvSDListRequiredCategories"].FormulaU = $"\"Bob\"";
// Note an error is thrown here because the list item being
// inserted does not contain the category 'Bob'
try
{
vPag.DropIntoList(itemMaster, shpList, 1);
}
catch (COMException ex) when (ex.ErrorCode == -2032465763)
{
//Inappropriate source object for this action.
Console.WriteLine($"{ex.Message} - check matching categories in List and ListItem shapes");
}
vDoc.DiagramServicesEnabled = diagramServices;
}
单元格,然后检查它们是否在列表形状(User.msvShapeCategories
)中所需的类别中。有关更多详细信息,请参见此帖子的“ 控制容器成员身份”部分:Custom Containers, Lists and Callouts in Visio 2010。
只需添加一下,如果要连接列表中的形状,则可以根据需要的控制级别使用上面的方法或类似的方法:
User.msvSDListRequiredCategories