automatic line color in visio

Started by shinji7800, July 08, 2012, 08:01:02 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

shinji7800

Hello everyone,

I'm glad to have found this website.

I'm French and VBA developing on visio is not something common.

I know some basics on VBA for Excel but VBA for visio is something new to me.

So if you can help me to put me I the right way

I have a project on an existing diagram. This diagram symbolizes an optic fiber network.

On this drawing we can find different sites, for example site A, B C ...

Between each site there are links for example:

•   Between site A & B we can find 3 links  AR1 AR2 & AR3
•   Between site B & C we can find 4 links AR1 AR3 AR4 & AN1

I would like to create an userform to demand at one user to put 3 informations:

•   The first extremity site
•   The second extremity site
•   And the name of a link ,(AR1, AR2, AR3 ...)

I would like to change automatically the color of all links.

For example, if the user chooses site A, site B and AR3

my (future) macro change the link between site A & B into red color. And all of link who has in their name AR3 into yellow color.

So I tried to make a macro with the macro recorder, I obtain this :


'Enable diagram services
    Dim DiagramServices As Integer
    DiagramServices = ActiveDocument.DiagramServicesEnabled
    ActiveDocument.DiagramServicesEnabled = visServiceVersion140

    Dim UndoScopeID1 As Long
    UndoScopeID1 = Application.BeginUndoScope("Couleur de trait")
    Application.ActiveWindow.Page.Shapes.ItemFromID(5).CellsSRC(visSectionObject, visRowLine, visLineColor).FormulaU = "THEMEGUARD(RGB(255,0,0))"
    Application.EndUndoScope UndoScopeID1, True

    Dim UndoScopeID2 As Long
    UndoScopeID2 = Application.BeginUndoScope("Couleur de trait")
    Application.ActiveWindow.Page.Shapes.ItemFromID(3).CellsSRC(visSectionObject, visRowLine, visLineColor).FormulaU = "THEMEGUARD(RGB(255,255,0))"
    Application.EndUndoScope UndoScopeID2, True

    'Restore diagram services
    ActiveDocument.DiagramServicesEnabled = DiagramServices



it is an huge program just for change color of two links.

So I think this code is enough to do what I want:

Application.ActiveWindow.Page.Shapes.ItemFromID(3).CellsSRC(visSectionObject, visRowLine, visLineColor).FormulaU = "THEMEGUARD(RGB(255,255,0))"

Application.ActiveWindow.Page.Shapes.ItemFromID(5).CellsSRC(visSectionObject, visRowLine, visLineColor).FormulaU = "THEMEGUARD(RGB(255,0,0))"


My first question is : Do you think my project is realistic ?

my second it's possible to reduce this :

Application.ActiveWindow.Page.Shapes.ItemFromID(5).CellsSRC(visSectionObject, visRowLine, visLineColor).FormulaU = "THEMEGUARD(RGB(255,0,0))" ?

I tried this but it don't works :

Sub testcolor()

Dim ThisShapes As Shape

Set TheShapes = ActivePage.Shapes
For Each ThisShape In TheShapes
If ThisShape.Name = "SiteA-SiteB-AR2" Then

ThisShape.FormulaU = "THEMEGUARD(RGB(255,255,0))"


End If

Next



Thank you for helping me.


PS: I'm French so I apologize for my English mistakes, be kind :)

vojo

its up to you....but you dont need VBA to do all that

play with the shape below (right click will get you going)....then look at the shape sheet to see how down.

Wont kidd you...its a pretty complex shapesheet.....but if VBA is an issue (security, complexity, unfamiliarity, etc)...this is a path to consider.

aledlund

what version of visio are you using (the hope would be v2007 professional or above, no standard edition)?
al

Jumpy


Sub testcolor()
  Dim TheShapes as Shapes
  Dim shp As Shape

  Set TheShapes = ActivePage.Shapes

  For Each shp In TheShapes
    If shp.Name = "SiteA-SiteB-AR2" Then
      'ThisShape.FormulaU = "THEMEGUARD(RGB(255,255,0))"
      'You can't give a shape a color. What color would it be? Background? Foreground? Linecolor?
      'you must select the cell from the shapes ShapeSheet that is responsible for the linecolor
      'and give that cell a new FormulaU:
      'Either:
      'shp.CellsSRC(visSectionObject, visRowLine, visLineColor).FormulaU= "THEMEGUARD(RGB(255,255,0))"
      'or:
      shp.Cells("LineColor").FormulaU= "THEMEGUARD(RGB(255,255,0))"
    End If
  Next shp
End Sub


That is only the answer to your code above.
Vojo's and Al's suggestion/question are important for your overall project.

shinji7800

Thank you for answering me !

At work we have visio 2003 (I don't know if it is standard or professional version) but I think it is professional version

At home I have visual studio 2010 ultimate edition and visio 2010 professional edition

My project must be compatible with visio 2003 :/

Is it too hard to realize my project by VBA? Or is it not necessary to lost time in development because shape sheet can do this easily ?

aledlund

Both v2003 and v2007/v2010 have a color_by_value function that allows you to do a (in most cases) solution that does not require any code at all. The later versions do it with data-graphics, in v2003 there is an add-in. Both of them rely on having custom properties configured for what you want. I use it a lot for color coding data links between sites (although I usually apply it to technologies).
al

shinji7800

Hello

I tried something if you can check what I have done to make a comment, thanks.


If you you also show me some example with an alternative way to do the same thing, because I don't know very well visio.
it seems very powerful, but without skills powerful is nothing ;)

I have tried to put annotation/comments on links but I don't succeed. I think I miss the part of coordinates and I don't kwon how I can do this. An idea ?


thank you so much to participate

best regards


vojo

tried and inspected your macro....does not do anything and not sure what you are trying to do here

If its something like "pick start shape and end shape and which link...fire macro....append some sort of text field on it"   then my initial reaction would be to do something like this

- Build your shapes and links
- Build a text box or callout
- place a copy textbox or callout where you want it on each link (ideally pin it via connection point on the link)
    (if need be, go into link and manually add a connection point for given link where you want to attach textbox/callout)
- edit text box or callout to set geometry.noshow to be true
- Have your macro ask the questions to determine shape/link (note if each link has unique name...dont really need to ask about shapes....macro would know or can interrogate link to find what
  its attached to
- Macro would then go into text box for each and set geometry.noshow to false (that makes the textbox/callout show up)

Since shape names are cryptic and change based on current shape situation....may want to use a custom prop that has link name...could even use that approach to map callout to link
(walk thru all shapes looking at each user or prop cell to find user friendly name to determine what to work on...post msg if not found).

Taking a step back....not sure why you dont add a action each link where user would right click link of interest, check the action, and use the checked action as a trigger to change link color.
(that would require no VBA at all....if you want multiple colors or select color to use, can use custom props or multiple actions...user fills in custom props or checks the right action).
(This would require user to turn of explicity...otherwise need VBA to enforce if only 1 link is "highlighted"....but maybe you are after setting each link type a specific color so dont care about
(manual turn off).

See below...right click the links....double click the shape

shinji7800

Thank you for your response !
I'm not sure if we understand each other. It's probably because I don't express myself correctly, I'm sorry :/

I'm in vacation actually, Monday I'll you show the original and the complete visio schematics.

I will try to explain my issue differently.

I work for a company who had his own optical fiber network.
we make an visio draw who represents all sites all around France and between all sites, there are optical fibers.
we need to know in which state the network is and will be for works planification on this network.

so I plained to animate the existing visio draw. all shapes and all link are drawn I just want to change color and put comments on link.


the user of my macro needs to put 2 sites and 1 fiber ... that indicate between site A and B the fiber is cut down, so it turns red.


but if physically one fiber is cut, logically it impact some other fibers, that is why some other fiber turn in yellow, that indicate, logically the fiber is "de-secure "

so we can make maintenance work on it ...

I  tried to explain simply, but trust me it is enough tedious to think about make a macro (or something else) to facilitate work. because on the originate visio draw,there are too many sites and links and it would take too long to change color one by one.

thank you vojo to try to help me !


aledlund

What you're asking for can obviously be accomplished at a couple of different levels. Unfortunately it will probably require more than just a simple macro. Maybe these will give you an idea.
http://www.youtube.com/playlist?list=PLBAFAAC68D36484CA&feature=g-list

al

vojo

agree.   If this is some sort of real time dashboard or a dashboard updated periodically from other sources.....this is going to take some heavy lifting of VBA et al.
For example, I would think you would need to coalesce all the data from all sites/links into say a text or excell file.....VBA in visio would have to read that file, parse it, then update
the visio shapes/icons.

Are you planning on keeping visio open on some system 24 hours a day.....or....open it when you want an update.
If the former, may be better tools (java, web, etc) for that.....if later, probably need macros for like "update upon open", "save uniquely on close", etc

For what its worth (and not worth all that much), I played around with a full screen animation template for visio about 2 years.   Posted it in this forum.   You can download that
and get a rank amateur's view of how complex this will get.

wapperdude

Let me see if I understand...

You have this "master" Visio drawing which represents all of the company's deployed fiber optic networks.  The goal is to show the impact on the network when one fiber link goes down.  The bad link is shown in red, and the subsequently affected links are shown in yellow.  In addition, the bad and affected links need some text added. 

The drawing you provided with macro does the first part:  user chooses the 1st site in the path, then the 2nd, and finally the link that went down.  Execute the macro and it does exactly what's desired:  makes the "parent" link red, and the "children" links yellow.  Doesn't add the text.  (The lines may need more weight, it's difficult to see the changes.  Also, a dark background might help, especially with the yellow.)

I did not look at your macro in detail, so, here are some comments and questions:
1.)  Is the line coloring behavior satisfactory, or did you need more "automation"-- macro needs to automatically read the the connectivities between all the sites on the real master drawing.

2.)  Need to add the ability to the macro to pop up text on the affected lines.

3.)  All of this can be done in Visio, but, it's a "static" network analysis tool.  Requires (a) user intervention, (b) requires someway to keep various "offices" updated when problems occur -- not easy, (c) if there are changes to the network, the drawing must be updated manually and then all of the offices need to be updated -- logistically this has problems (introduction of errors, not everyone using the same drawing version, etc.)

4.)  There may be better solutions other than Visio for this.
Visio 2019 Pro

shinji7800

Hi, Thanks all of you for your interest !

Quote from: vojo on July 12, 2012, 01:44:01 PM
agree.   If this is some sort of real time dashboard or a dashboard updated periodically from other sources.....this is going to take some heavy lifting of VBA et al.
For example, I would think you would need to coalesce all the data from all sites/links into say a text or excell file.....VBA in visio would have to read that file, parse it, then update
the visio shapes/icons.

Are you planning on keeping visio open on some system 24 hours a day.....or....open it when you want an update.
If the former, may be better tools (java, web, etc) for that.....if later, probably need macros for like "update upon open", "save uniquely on close", etc

For what its worth (and not worth all that much), I played around with a full screen animation template for visio about 2 years.   Posted it in this forum.   You can download that
and get a rank amateur's view of how complex this will get.

my purpose is not to create a real time or semi real time app'.

it's more for a vision to plan, or make a quick decision.

Indeed ever week we have some physical interventions we need to plan this intervention if a ring is cut, a plan intervention can be delayed/postponed to a later date (a ring is a logical route/path. A ring is composed of multiple fibers).

An other example, when failure comes (a cut on fiber) we need to make a quick decision for rerouting operation to assure a continuity of service.

that's why we think visio is the best alternative than just a database like Excel, because this is a visual aid. faster to interpret.


we doesn't plan to keep visio open 24/24 but just actualize it at the end of the day.

that's why your idea to make triggers is good maybe not enough, because like wapperdude as understood, when a link is cut, some other links depend in part of the link cut. that why in my macro when one link named AN1 (for example) is cut the other one turned in yellow, because there left one "road" possible to reach a particular site.

Quote from: wapperdude on July 12, 2012, 02:48:15 PM
Let me see if I understand...

You have this "master" Visio drawing which represents all of the company's deployed fiber optic networks.  The goal is to show the impact on the network when one fiber link goes down.  The bad link is shown in red, and the subsequently affected links are shown in yellow.  In addition, the bad and affected links need some text added. 

The drawing you provided with macro does the first part:  user chooses the 1st site in the path, then the 2nd, and finally the link that went down.  Execute the macro and it does exactly what's desired:  makes the "parent" link red, and the "children" links yellow.  Doesn't add the text.  (The lines may need more weight, it's difficult to see the changes.  Also, a dark background might help, especially with the yellow.)

I did not look at your macro in detail, so, here are some comments and questions:
1.)  Is the line coloring behavior satisfactory, or did you need more "automation"-- macro needs to automatically read the the connectivities between all the sites on the real master drawing.

2.)  Need to add the ability to the macro to pop up text on the affected lines.

3.)  All of this can be done in Visio, but, it's a "static" network analysis tool.  Requires (a) user intervention, (b) requires someway to keep various "offices" updated when problems occur -- not easy, (c) if there are changes to the network, the drawing must be updated manually and then all of the offices need to be updated -- logistically this has problems (introduction of errors, not everyone using the same drawing version, etc.)

4.)  There may be better solutions other than Visio for this.

I think wapperdude understand my issue.

and yes I thinks it must be necessary to add comment/annotation on a link to inform what's happen on this link .

I have tried to put some comments but nothing appears, I think I miss the coordinates part for the association of the link and the comment.



I have search if there exist an other solution. I don't find it, maybe I don't have the right key word for my research. that's why finally I chose visio, because we have already the scheme draw. there is no chance today that the scheme evolves.

so we need to change the colors of links.


I will show you the original draw monday !







wapperdude

Ah!  So, your drawing is really a ring, my "parent" / "child" comments convey the intention but not really accurate for the context.

As far as text position goes, did you open one of the connector shapesheets?  Dynamic connectors have a control function that sets the text position.  If you scroll further down to the Text Transform section, then you can see how the TextPinX and TextPinY reference this location.  You should be able to do the same in a macro.

HTH
Wapperdude
Visio 2019 Pro