1

我有一个简单的代码来绘制形状。

Visio.Shape dropShape = ActivePage.Drop(GetMaster(@"Circle"), x, y);
Visio.Shape dropShape2 = ActivePage.Drop(GetMaster(@"Circle"), x + 3, y);

我想为这些形状添加容器

VisApp.ActiveWindow.Select(dropShape, (short)Visio.VisSelectArgs.visSelect);
VisApp.ActiveWindow.Select(dropShape2, (short)Visio.VisSelectArgs.visSelect);

object vsoSelection = VisApp.ActiveWindow.Selection;
Visio.Shape containerMaster = ActivePage.Drop(GetMaster(@"Square"), x -3, y-3);
Visio.Shape container = ActivePage.DropContainer(containerMaster, vsoSelection);

我在 Internet 上找到了这个示例,但它不起作用。有什么想法吗?

4

1 回答 1

0

您的代码中的问题是您不能在 DropContainer() 调用中使用任何随机 Master 作为容器。

相反,您必须加载一个包含容器的模板,然后在该模板中选择一个容器母版。

完整的代码如下:

var app = new IVisio.ApplicationClass();

var docs = app.Documents;
var doc = docs.Add("");
var page = app.ActivePage;
short flags = (short)
    ( IVisio.VisOpenSaveArgs.visOpenDocked | 
    IVisio.VisOpenSaveArgs.visOpenRO);

var basic_stencil = docs.OpenEx("basic_u.vss", flags);
var basic_masters = basic_stencil.Masters;
var rounded_rect_master = basic_masters["Rounded Rectangle"];

double x = 2.0;
double y = 3.0;

var shape1 = page.Drop(rounded_rect_master, x, y);
var shape2 = page.Drop(rounded_rect_master, x + 3.0, y+1.0);

var stenciltype = IVisio.VisBuiltInStencilTypes.visBuiltInStencilContainers;

var measurementsys = IVisio.VisMeasurementSystem.visMSDefault;
short containeropenflags = (short) IVisio.VisOpenSaveArgs.visOpenHidden;
string containerstencil_filename = app.GetBuiltInStencilFile(stenciltype, measurementsys);
var container_stencil = docs.OpenEx(containerstencil_filename, containeropenflags);
var containermasters = container_stencil.Masters;
var container = containermasters["Container 1"];

var activewindow = app.ActiveWindow;
short selectargs = (short)IVisio.VisSelectArgs.visSelect;
activewindow.Select(shape1, selectargs);
activewindow.Select(shape2, selectargs);

page.DropContainer(container, activewindow.Selection);
于 2013-04-20T06:02:45.687 回答