HowTo: draw shapes by using VC and automation?

L

Lars

I try to write an application in VC++ which performs the
following steps by automation:

1. run Visio
2. create a new document
3. drawing some shapes
4. link them together
5. save the document
6. quit visio

I only have problems with steps 3 and 4. Seems like such
an easy task but how can I create a shape (from standard
floatdiagrams)
and put it onto the page/document. The shapes should have
a special ID, more than tree data fields and a specific
text.
How will work this? And how can link two shapes together?
I used the following code. I would be very happy if
anyone could help me. I'm a newby in this case, so code
samples will be very helpfull.

if(!app.CreateDispatch("Visio.Application"))
{
AfxMessageBox("Couldn't start Visio and get
Application object.");
return;
}
else
{
// this work
app.GetApplication();
app.SetAutoLayout(TRUE);
docs = app.GetDocuments();
doc = docs.Open("BASFLO_M.vst");

// this doesn't work
shape.Import("BASFLO_M.vss");
shape.SetStyle("Process");
shape.SetName("This is a Test Shape");
shape.SetData1("First value");
shape.SetData2("Second value");
shape.SetData3("Third value");
page.Drop(shape, 10, 10);

// this work
doc.SaveAs("C:\\Temp\\test.vsd");
app.Quit();
}

thanks for your help,

regards Lars
 
C

Chris Roth [ Visio MVP ]

You open a stencil file to get a shape. In VB(A) it looks like this:

dim stn as visio.document
set stn = Visio.Documents.Open( full_path )

Then you need to get a master object from the stencil:

dim mst as visio.master
set mst = stn.Masters( master_name )

Now you can drop an instance of the master on a page:

dim shp as visio.shape
set shp = Visio.ActivePage.Drop( mst, 5, 5 )

--

Hope this helps,

Chris Roth
Visio MVP
 

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