Visio Guy

Visio Discussions => Programming & Code => Topic started by: gruenefeder on August 14, 2008, 09:35:53 AM

Title: Converting a Hyperlink to a Smarttag
Post by: gruenefeder on August 14, 2008, 09:35:53 AM
Hello!

I have EPC-Models in Visio with a couple of hyperlinks behind the shapes. I have implemented an add-in with Visual Studio 2008 using c#. The add-in has an DocumentOpenedEventHandler noticing when a document is loaded and automatically adds smarttags to the shapes with the hyperlinks:

currentShape.AddNamedRow((short)Microsoft.Office.Interop.Visio.VisSectionIndices.visSectionAction, "Hinterlegungen", 0);
currentShape.get_CellsU("Actions.Hinterlegungen.Action").FormulaU = "RUNADDONWARGS(\"QueueMarkerEvent\",\"SOLUTION=SPVSO /EVENT=100\")";
currentShape.get_CellsU("Actions.Hinterlegungen.Menu").FormulaU = "\"Hinterlegungen\"";
currentShape.get_CellsU("Actions.Hinterlegungen.TagName").FormulaU = "\"Hinterlegungen\"";

currentShape.AddNamedRow((short)Microsoft.Office.Interop.Visio.VisSectionIndices.visSectionSmartTag,
"Sharepoint", (short)Microsoft.Office.Interop.Visio.VisRowTags.visTagDefault);
currentShape.get_CellsU("SmartTags.Sharepoint.TagName").FormulaU = "\"Hinterlegungen\"";

The problem is that I have implemented the drawing control in a website and when i start the drawing control with a visio file the smarttags are created but they do not work. But when i copy the URL, close the browser window, open a new browser window, paste the URL and reload the page everything works fine. Is there anyone who has an idea solving the problem? Is there a way to directly start functions in the add-in from visio (e.g. in the action-sections of the shapesheets)

Best,
Daniel
Title: Re: Converting a Hyperlink to a Smarttag
Post by: Visio Guy on August 14, 2008, 06:38:53 PM
Servus Daniel!

I have not tried running the ActiveX control in a web site, but here are few items to get us closer to a solution:

You are queueing a marker event using: "RUNADDONWARGS(\"QueueMarkerEvent\",\"SOLUTION=SPVSO /EVENT=100\")";

I assume you have some code behind this web application. Is that code successfully intercepting the marker event? Does it even make sense what I am asking? :)


Also, a tip to make the code a bit easier to read and type: use an imports definition to make things shorter:

imports Vis = Microsoft.Office.Interop.Visio ;

Then, you can simply code, for example:

currentShape.AddNamedRow((short)Vis.VisSectionIndices.visSectionAction, "Hinterlegungen", 0);

instead of:

currentShape.AddNamedRow((short)Microsoft.Office.Interop.Visio.VisSectionIndices.visSectionAction, "Hinterlegungen", 0);

Title: Re: Converting a Hyperlink to a Smarttag
Post by: Visio Guy on August 14, 2008, 07:03:27 PM
Noch eine Idee,

I looked at what you are doing more closely. In the Action behind your Smart Tag, you might try using the HyperLink ShapeSheet function. ZB:



// Build a ShapeSheet function using HYPERLINK.
// Since function arguments need quote marks as well
// let's break it up into pieces:

string qt = "\"";
string targetAddr = qt + "http://www.somewhere.com" + qt;
string formula =  "HYPERLINK(" + targetAddr + ")";

// Set the formula in the shape:
currentShape.get_CellsU("Actions.Hinterlegungen.Action").FormulaU = formula;



I don't know if this will function in a web-based application, but perhaps you can try it.





Title: Re: Converting a Hyperlink to a Smarttag
Post by: Visio Guy on August 14, 2008, 07:05:28 PM
I'll post the .vsd I was using to test some of this as well, see the attached file.

Also note, the Visio file has VBA code in it that sets the Action-row ShapeSheet formula. This code isn't required, it is just there as an example--the shape is already built, with a Smart Tag that jumps to a web address.

The code looks like this:


Sub SetLinkAction()

  Dim shp As Visio.Shape
  Set shp = Visio.ActivePage.Shapes(1)
 
  Dim qt As String, targetAddr As String, formula As String
  qt = Chr ( 34 )
  targetAddr = qt & "http://www.visguy.com" & qt
  formula = "HYPERLINK(" & targetAddr & ")"
 
  shp.Cells("Actions.Action").FormulaForceU = formula
 
End Sub
Title: Re: Converting a Hyperlink to a Smarttag
Post by: gruenefeder on August 18, 2008, 09:44:17 AM
Many thanks for your help. I solved the problem with the drawing control using "QUEUEMARKEREVENT(...)" instead of "RUNADDONWARGS(...)" in the shapesheet.

Cheers,
Daniel
Title: Re: Converting a Hyperlink to a Smarttag
Post by: Visio Guy on August 18, 2008, 10:06:55 PM
Hmm,

Glad to see that it worked for you.

The RUNADDONWARGS(\"QueueMarkerEvent\"... was implemented in Visio 2002, before QUEUEMARKEREVENT exited in the Visio API. It may be that this add-on isn't available to only the Visio control. I haven't tried it myself, especially in a web site.