Creating and adding Custom Patterns Programmatically

C

CyberBhai

I am using the Visio Activex Control 2003 with VB.Net 2003.
I want to create a custom pattern either from an existing image or from a
master present in the current stencil.
I am able to do this manually but not able to do thru code.
My application allows one to create a new file and in that the line pattern
to be used.
Plz. Help.
Thanking you,
CyberBhai
 
C

Chris [Visio MVP]

CyberBhai,

I've never done this, suprisingly! But knowing the history of Visio, my
guess is to check this property: Master.PatternFlags.

So the steps are probably something like this:

1. Create a master that holds your custom pattern graphics
2. Set the Master.PatternFlags

The reason I am guessing this is that custom patterns are stored as masters.
In earlier versions of Visio, you actually created masters, then set a
pattern flag in a dialog box. If you don't know this history, then the API
looks really stupid, as you have discovered.
 
C

CyberBhai

Chris,
Can you plz. help me with a sample code template. I am having a
stencil which has some masters. One of the masters I will take as a pattern
(Example : Let's take Basic Shapes (Metric) as the Stencil of which Star 5
is the master to be used as a pattern for Dynamic Connector, means when I
will select Format->Line->Pattern on Dynamic Connector, I should be able to
see a pattern which represents Star 5).

Plz. Help.

CyberBhai
 
C

Chris [Visio MVP]

Here's some VBA to get you started.

It changes a master in the Document Stencil (File > Shapes > Show Document
Stencil) with the name of "pattern1" into a fill pattern. Then it draws a
rectangle and applies the fill pattern.

So you need to copy some masters into your document, then rename them, if
necessary (ie: "fillPatternStar")

Sub ConvertMasterToPattern()

Dim doc As Visio.Document
Set doc = ThisDocument

doc.Masters("pattern1").PatternFlags = visMasIsFillPat + visMasFPTile

Dim shp As Visio.Shape
Set shp = doc.Pages(1).DrawRectangle(0, 0, 5, 5)
shp.CellsU("FillPattern").FormulaU = "Use(""pattern1"")"

End Sub

When you drag a master from a stencil, it gets copied into the Document
Stencil. Many developers aren't aware of this. Once you understand this,
things make more sense, and you'll stop trying to work with separate
documents. Ie: when you open the Block template, you have two documents: the
Block stencil and the Block template. The template has no masters in it
until you start dragging shapes onto the page from the stencil.
 

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