Visio Guy

Visio Discussions => Programming & Code => Topic started by: le-no on October 10, 2011, 06:58:29 PM

Title: Add new master to stencil with VB .NET
Post by: le-no on October 10, 2011, 06:58:29 PM
Hi folks,

As a relative newbie, I have created a Ribbon-Add-In for Microsoft Visio with Visual Studio 2010 and I really like doing this so far, but I have one major problem that I can't get over.

I try to dynamically change the stencil by reacting to events like ShapeAdded. I managed to delete a master from the stencil by doing something like this:

vsoMaster.Delete()

However, if I want to add a new master to an empty stencil (after all masters have been deleted) I do this:

Dim vMaster = vsApplication.Documents.Item("test.vss").Masters.Add()

This produces an empty master in the stencil.
Now, if I want this master to have a shape, I always get COMExceptions, e.g. when I try to do stuff like this:

vMaster.Shapes.Item(1).CellsSRC(Visio.VisSectionIndices.visSectionObject, Visio.VisRowIndices.visRowLine, Visio.VisCellIndices.visLineColor).FormulaU = "THEMEGUARD(RGB(0,0,0))"

It seems plausible for the program to react like that because there is no shape yet that I could edit like that, but I can't find a way to assign a shape to the master.
Does anyone know a way to do that?

Thanks in advance for your help and best regards from Osnabrueck, Germany.

Lennard
Title: Re: Add new master to stencil with VB .NET
Post by: aledlund on October 10, 2011, 09:07:37 PM
before we get too far into this, did you check this out?

http://www.visguy.com/2008/02/25/edit-visio-masters-programmaticallythe-right-way/

and before you attempt to edit the internal shape of the master, ensure that one was returned..

al
Title: Re: Add new master to stencil with VB .NET
Post by: le-no on October 11, 2011, 07:41:40 AM
Thanks for the quick reaction.
I tried the above but I struggled to define a master that I could copy and open (since the stencil is empty).

I think I figured out the heart of my problem though.
I can't manage to get new instances of any Visio entities, such as Master, Shape etc.

If I try to initialize a new Shape:
vsShape = New Visio.Shape()

I get a COMException, telling me that the class was not registered:
HRESULT: 0x80040154 REGDB_E_CLASSNOTREG

What class do I have to register? And how do I do that?
Please help me, I'm really stuck here. Thanks.
Title: Re: Add new master to stencil with VB .NET
Post by: Jumpy on October 11, 2011, 09:42:53 AM
Afaik you can't create a new shape in Visio like that.
You can drop a shape from another stencil or you can draw a new shape, for example as rectangle and then modify it.