我想在删除形状后重命名连接器。 假设我有一个shape1,我放下了一个与shape1连接的shape2。 我想要shape1和shape2之间的连接器形状,以便我可以重命名它。
答案 0 :(得分:1)
我想这取决于你拦截掉落的阶段。如果它立即执行,您可能会对可能涉及的连接器数量做出一些假设,但如果在丢弃之后的某个时间,您可能想要确定涉及多少个连接。
......你可以通过多种方式解决这个问题:
我肯定会尝试使用GluedShapes方法(在2010年进入Visio)而不是Connect对象,但我在这里添加它们,因为它们可能很有用,具体取决于您尝试实现的目标
以下是使用LINQPad的示例:
void Main()
{
var vApp = MyExtensions.GetRunningVisio();
var vPag = vApp.ActivePage;
//For demo purposes I'm assuming the following shape IDs
//but in reality you'd get a reference by other methods
//such as Window.Selection, Page index or ID
var shpOne = vPag.Shapes.ItemFromID[1];
var shpTwo = vPag.Shapes.ItemFromID[2];
Array gluedIds;
Console.WriteLine("1) using GluedShapes with the 'to' shape only");
gluedIds = shpTwo.GluedShapes(Visio.VisGluedShapesFlags.visGluedShapesIncoming1D,"");
IterateByIds(vPag, gluedIds);
Console.WriteLine("\n2) using GluedShapes with the 'to' and 'from' shapes");
gluedIds = shpTwo.GluedShapes(Visio.VisGluedShapesFlags.visGluedShapesIncoming1D, "", shpOne);
IterateByIds(vPag, gluedIds);
Console.WriteLine("\n3) using the Connects collection on Page");
var pageConns = from c in vPag.Connects.Cast<Visio.Connect>()
where c.FromSheet.OneD != 0
group c by c.FromSheet into connectPair
where connectPair.Any(p => p.ToSheet.ID == shpOne.ID) && connectPair.Any(p => p.ToSheet.ID == shpTwo.ID)
select connectPair.Key.Text;
pageConns.Dump();
Console.WriteLine("\n4) using FromConnects and Linq to navigate from shpOne to shpTwo finding the connector in the middle");
var shpConns = from c in shpOne.FromConnects.Cast<Visio.Connect>()
where c.FromSheet.OneD != 0
let targetConnector = c.FromSheet
from c2 in targetConnector.Connects.Cast<Visio.Connect>()
where c2.ToSheet.Equals(shpTwo)
select targetConnector.Text;
shpConns.Dump();
}
private void IterateByIds(Visio.Page hostPage, Array shpIds)
{
if (shpIds.Length > 0)
{
for (int i = 0; i < shpIds.Length; i++)
{
//Report on the shape text (or change it as required)
Console.WriteLine(hostPage.Shapes.ItemFromID[(int)shpIds.GetValue(i)].Text);
}
}
}
运行上述操作将导致此输出:
值得注意的是,连接代码(3和4)假设连接器形状(1D)正连接到到流程图形状(2D)而不是反过来(这是可能的)。
您可以将连接对象视为对连接点的分析,因此在图中,三个连接器形状会生成六个连接对象:
无论如何,希望能让你解开。
更新 - 为了清楚(并正确回答原始问题),从ShapeOne获取所有传出连接器的代码将是:
Console.WriteLine("using GluedShapes to report outgoing connectors");
gluedIds = shpOne.GluedShapes(Visio.VisGluedShapesFlags.visGluedShapesOutgoing1D, "");
IterateByIds(vPag, gluedIds);