Locking Layers / Preventing ShapeAdd

D

Daniel Shookowsky

OK, I've pretty much given up on any Visio event allowing me to undo an
operation. As mentioned in an earlier post, I've disabled my UserControl
in .NET, but that has the side effect of preventing scrolling or viewing
different pages.

I did a quick test with layers, adding all of the shapes to a layer and
locking it/unlocking it depending on the checked-out state of the file.
Piece of cake and it works exactly the way I want....expect for one thing.

I need to prevent the user from adding new shapes while the layer is
locked and force any newly added shapes into the specified layer when it
is unlocked. I'm using a custom stencil, so I imagine that I can specify
a layer for each shape, but I can't for the life of me figure out how to
do this.

The $10,000,000 question:
How can I force my custom shapes into a specified layer?

Google searches have turned up nothing and the Visio Developer's
documentation is almost useless.
 
A

Al Edlund

you might consider something like this for your shape added event handler
(apologize, I haven't ported this over
to vb.net yet)....

Set objPage = Visio.ActivePage
Set objLayers = objPage.Layers
' remove any layer data from the shape
If objShape.LayerCount <> 0 Then
For iLayCt = 1 To objShape.LayerCount
Set objLayer = objShape.Layer(1)
objLayer.Remove objShape, 0
Next iLayCt
End If
' move it to the layer you want
Set objLayer = objLayers.item("SomeLayerName")
objLayer.Add objShape, 0

Al
 
D

Daniel Shookowsky

This is what I ended up doing:

1) My application already used a GetDragShape method to get the shape from
the stencil, I just return null from this if changes aren't allowed. This
prevents users from adding shapes while the file is checked in.

2) When I open a Visio file, I check to see if the page contains any
layers , if not, I add my lock layer and move all of the pages shapes to
that layer.
Visio.Layer layer = page.Layers[LOCK_LAYER]);

foreach(Visio.Shape shape in page.Shapes)
{
layer.Add(shape, 0);
}

3) In my ShapeAdded event, I get the layer and move
the shape from whatever layer it's currently in to my lock layer
Visio.Page page = _VisApp.ActivePage; Visio.Layer layer =
page.Layers[LOCK_LAYER]; layer.add(e.Shape, 0);

4) I have a timer that modifies the layer's lock formula based on the
checked out state of the file.

Visio.Page page = _VisApp.ActivePage;
Visio.Layer layer = page.Layers[LOCK_LAYER];
Visio.Cell lockCell =
layer.get_CellsC((short)Visio.VisCellIndices.visLayerLock);

if (ChangesAllowed())
{
lockCell.Formula = "0";
}
else
{
lockCell.Formula = "1";
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top