Visio NameUID

L

LadySnowWhite

I’m writing a program to automatically draw Visio diagrams from data in a
database. As we update the database, hundreds of diagrams will be drawn. I
have used this example as a reference to get started:
http://msdn.microsoft.com/en-us/library/aa722522.aspx. So far the program is
working perfectly with an exception; I cannot edit the shapes I am using.
Even though I have told the program where to connect to the Visio template
that is holding the proper stencil, it does not seem to be reading the
correct shapes.

In the example, we call the shapes this way:

//declare shape
private const string _VisioItemMaster = “Itemâ€;

//Later in program, use shape
Visio.Master itemMaster = drawingPage.Document.Masters[Item];


In my program, I have changed the stencil, but Visio is not recognizing the
changes; it keeps placing default rectangles.

The auto help says that within the brackets, you need to place either the
NameUID or Index. How can I find a shape’s NameUID (it does not appear to be
the name in the Shape Sheet from Visio, or at least putting in that name
causes an object not found error), or how can I find the shape’s Index?
Putting in numbers 1 through 10 works without errors, but it does not place
the shapes that I want.
And how can I tell my program to connect to the right stencil to find my
shapes?

Here is how I connect to the template:

private const string _VisioTemplateName = "MyItemsSample.vst";
private const string _VisioStencilName = "MyStencilSample.vss";


The files are saved in the same location as my program and I have placed a
copy of the stencil in the Visio folder under my Program Files
 
A

AlEdlund

Let's look at a couple of these...

"The files are saved in the same location as my program and I have placed a
copy of the stencil in the Visio folder under my Program Files ", Is your
program files(?) path in the visio stencil path configuration? Or, are you
appending the directory path to the stencil/template path before trying to
open the file?

"In my program, I have changed the stencil, but Visio is not recognizing the
changes; it keeps placing default rectangles. " Are you changing the
stencil(and path), or, the object in the stencil? Changing objects in
stencils does not automatically update existing copies that are in
documents.

"How can I find a shape’s NameUID (it does not appear to be
the name in the Shape Sheet". When you drop the master on the page as a new
shape, you should rename it so that it can be found in the future. GUIDs are
not in the shapesheet and must be explicitly assigned.

Set visShape = visApp.ActivePage.Drop(vsoMaster, 0,
0)
visShape.NameU = strRack
visShape.Name = strRack
visShape.Text = strRack

HTH,
al


LadySnowWhite said:
I’m writing a program to automatically draw Visio diagrams from data in a
database. As we update the database, hundreds of diagrams will be drawn.
I
have used this example as a reference to get started:
http://msdn.microsoft.com/en-us/library/aa722522.aspx. So far the program
is
working perfectly with an exception; I cannot edit the shapes I am using.
Even though I have told the program where to connect to the Visio template
that is holding the proper stencil, it does not seem to be reading the
correct shapes.

In the example, we call the shapes this way:

//declare shape
private const string _VisioItemMaster = “Itemâ€;

//Later in program, use shape
Visio.Master itemMaster = drawingPage.Document.Masters[Item];


In my program, I have changed the stencil, but Visio is not recognizing
the
changes; it keeps placing default rectangles.

The auto help says that within the brackets, you need to place either the
NameUID or Index. How can I find a shape’s NameUID (it does not appear to
be
the name in the Shape Sheet from Visio, or at least putting in that name
causes an object not found error), or how can I find the shape’s Index?
Putting in numbers 1 through 10 works without errors, but it does not
place
the shapes that I want.
And how can I tell my program to connect to the right stencil to find my
shapes?

Here is how I connect to the template:

private const string _VisioTemplateName = "MyItemsSample.vst";
private const string _VisioStencilName = "MyStencilSample.vss";


The files are saved in the same location as my program and I have placed a
copy of the stencil in the Visio folder under my Program Files
 
L

LadySnowWhite

Thank you very much for your help, AlEdlund. I’m not sure if I fully
understand what you’re asking, but I’ll try my best to answer.

“Is your program files(?) path in the visio stencil path configuration? Or,
are you
appending the directory path to the stencil/template path before trying to
open the file? â€

I don’t know how to set the Visio stencil path configuration (if I could
learn how to do that, it might help), so I don’t think I’m doing that. I
think I am appending the directory path to the stencil/template path before
trying to open the file by the connection string as I showed:
private const string _VisioTemplateName = "MyItemsSample.vst";
private const string _VisioStencilName = "MyStencilSample.vss";
where the path is in the quotations, except that since the files are in the
same folder as my program (also the same folder as my database which connects
without difficulty), the relative path is enough and an absolute path is not
needed. Should I try to change it to an absolute path?

This is how the MS example says to do it:
private const string _VisioTemplateName = "WhitePaperSample_Access.vst";

If there is more to connecting to the stencil and template than that example
shows, I do not know about it.

“Are you changing the stencil(and path), or, the object in the stencil?â€

I am changing the actual Master from the stencil. I do this my loading the
stencil, right clicking on the stencil and selecting edit, then double
clicking the master and editing it, finally closing the edit window and
selecting “update†for my master and saving the changes to my stencil. The
changes remain to the stencil and are available everything the template is
opened, but I don’t think my program is calling the correct stencil.

“GUIDs are not in the shapesheet.â€

Thank you for confirming that they are not in the shapesheet. Now I know
I’m not missing anything there.

“When you drop the master on the page as a new
shape, you should rename it so that it can be found in the future.
Set visShape = visApp.ActivePage.Drop(vsoMaster, 0, 0)
visShape.NameU = strRack
visShape.Name = strRack
visShape.Text = strRackâ€

I’m sorry but this statement doesn’t make any sense to me. Do you mean when
I create a new master, or each time a shape is used? Your code looks like
VBA, must I run a macro to do this? Doing this for every shape in every
diagram will be quite impossible since I must programmatically generate
hundreds of diagrams each with dozens of shapes. I can see doing this when
creating masters, but can you please be a little more specific with the
procedure?

Thanks again!
 
W

WapperDude

Regarding paths: menu bar > Tools > Options. Select the advanced tab.
Click the File Paths button.

Wapperdude
 
A

AlEdlund

A little more :)

"private const string _VisioTemplateName = "MyItemsSample.vst"; "
This is just the file name, it doesn't say where to find it. You must either
include the path in Visio (options=>Advanced=>FilePaths) or code it
explicitly. (mypath+myfilename). If you put it into Visio you have to ensure
your users all have it set up also......

Everytime you drop a shape (master) on the drawing page, Visio will assign a
default name to it (usually something like sheet1.21), it's up to the
programmer to keep track of it or add there own name. I usually rename the
shapes when they are dropped (shapename, universalname, and the text box all
get the same variable). You can code it anyway you want (I don't do C in any
of the derivitives, I'm a basic kinda guy).

Once again, changing a master will not change drawings that use the new
shape, it only will apply to new drawings. If you draw something on monday,
change the master on tuesday, the drawings on monday will have the old
shapes in them. Updating the master doesn't change mondays documents even if
you open them with the updated stencil. If your going to swap around
stencils make sure you clear the document stencil so that old shapes with
the same name don't get used (search help document stencil).

al
 
L

LadySnowWhite

Both of you have been a lot of help. I understand a bit better what’s
happening, but I still haven’t solved the problem.

I did mistakenly fail to post the correct connection segment, and I
apologize for that; it’s a bit embarrassing, but here it is. It’s the same
from the MSDN example here:
http://msdn.microsoft.com/en-us/library/aa722522.aspx.


private static Visio.Document setUpDocument()
{
Visio.Document newDocument = null;

try
{
// Open Visio.
Visio.Application visioApplication = new Visio.Application();

// Open a new document based on the template.
newDocument = visioApplication.Documents.OpenEx(
Application.StartupPath + "\\" + _VisioTemplateName,
(short)Visio.VisOpenSaveArgs.visOpenCopy);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}

return newDocument;
}



“Regarding paths: menu bar > Tools > Options. Select the advanced tab.
Click the File Paths button.â€

Wapperdude, your suggestion was brilliant! I had completely neglected that
operation. So I tried two things: first was to try adjusting the file path
from C#; however, the Visio path was pointing to the My Documents folder
located on the server. In order to point to it, I will need to use some
different connection code that I have yet to discover. So instead, I tried
changing the Visio path to point to my program. Again the program launches
the correct template, but it cannot see to find my shaped. Here is the code
to look for the shapes:


try
{
Visio.Master itemMasterA = drawingPage.Document.Masters[*];
}

where the * needs to be either the NameUID or the index. Now, in my Visio
stencil, I have crated a master called “ShapeA†and if I put that name in the
brackets, I get an, “object not found error,†but if I out in a random index
number, 1 through 10, I will get a shape from a previously created stencil.
I do not have access the source of the stencil from which the shapes are
being called, but no matter how I try to redirect it; the program can’t seem
to look at my stencil.

One of my coworkers was able to write a macro in VBA to find master and
shape’s GUID and NameU, but I still cannot edit the current shape (because I
don’t have access to the stencil containing the original master). What I
will do next is to run that macro against my masters from my stencil and get
the NameU those and try plugging that into the above code. (I know that the
NameU and the title of my master (as displayed on the stencil) are not always
the same.)

AlEdlund, you never explained it, but I think the code sample you posted
earlier should be a VBA macro to define some of the master’s parameters, can
you please confirm this, or if not, explain what and how that code functions?

Finally, even though I am telling the program (and Visio) to look at a
specific template which contains my stencil, is there a way to be sure that
my program is really looking inside the stencil to the masters? Because even
if my paths to the template are set correctly, if I cannot access the
stencil, the program still will not be able to find the masters.

You help is so very much appreciated.

Thanks again,
LadySnowWhite
 
L

LadySnowWhite

I finally found a work around solution!

It’s not a direct solution, but so far, it’s working well enough for me. It
turns out that connecting to the right files wasn’t really the problem at
all, I was able to verify that I was connecting to the correct file, but
there was still a problem with my being able to edit my Masters, so instead,
I created a new Visio Template with a new stencil containing the correct
masters that I wanted. After I created the new masters, I was not able to
edit them and have the changes hold when dropped, but at least now everything
is working.

I’m not sure if anyone else has ever experienced this before, but it’s quite
odd: when I go to my stencil where the masters were originally created, right
click the stencil and select edit, then right click on the master and select
Edit Master Shape, I can make all of the changes I like to the master, then
close is and say, Update master and save changes to the stencil and close
Visio; however, when I reopen Visio, and try to drop my shapes they revert
back to their original forms! Now what’s even weirder, if I right click the
stencil and select edit, then double click my master, all of the changes I
made previously are still there! But even so, when I drop them, they still
revert back.
I’m not certain, but I suspect that if those masters have been used already,
they won’t be changed. I haven’t tried this, but I wonder if I delete all
files on my computer (save backups externally if necessary) that contain that
master, will the changes then hold, or is the master permanent once used?

Anyway, thank you Wapperdude and AlEdlund, I appreciate your help!

Sincerely,
LadySnowWhite
 

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