How to Make Visio Text Flash or Blink?

Started by jebuxx, June 29, 2015, 04:09:16 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

jebuxx

OK, I have another crazy question. We have a Visio Job Entry program made that also will create full blown graphic templates. What I would like to have happen is whan an error or entry is made that breaks a rule we have formated in that text that appears that notifies the error will flash or change colors
say from red to black every second or so. Anyone now how this can be done?? Maybe a VBA code?
I really apperciate the help.


Visio Guy

Hi Jebuxx,

Yes, it has to be done with automation code.

I've cobbled together an example that uses the Windows API timer to "tick" a certain amount of times. I didn't want to have it run forever.

Anyway, any shape that has an asterisk in its text will blink its text color from black to red to black when you click the button. I think it blinks 11 times, then stops.

If you're running 64-bit Visio, then you might have to tweak the MTimerAPI code with the "PtrSafe" stuff. See StackOverflow: http://stackoverflow.com/questions/5506912/how-should-i-make-my-vba-code-compatible-with-64-bit-windows

I didn't have my 64-bit Visio on hand to test.

For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

Visio Guy

Just a note: keep a watch and see if Visio is crashing. Mine seems to be, but I'm not sure if it is related to the Timer code or not.

It could be that I haven't stopped it properly nor cleaned things up in the right way.

There are probably other timer mechanisms, but this will at least show you how to flip the text color!
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

Visio Guy

For those interested in how to flip the color of shape text, I'll share the code that does just that here.

First, there is some code that I haven't shown that starts a Windows API Timer thingamajig, and passes the address of the m_handleTimerTick procedure to the timer. The timer ticks are then counted, and this handler stops the timer after 11 or so "blinks".

Not super-interesting code, but this is where we are starting:


Private Sub m_handleTimerTick()

  Debug.Print "Tick " & m_lBlinkCount;
 
  If (m_lBlinkCount > m_lMaxBlinkCount) Then
    '// Stop:
    Call MTimerAPI.StopTimer
    m_lBlinkCount = 0
  Else
    '// Continue:
    Call m_blinkShapes
    m_lBlinkCount = m_lBlinkCount + 1
  End If
 
End Sub


The timer handler then calls Visio-specific code, shown in the two procedures below. It is possible that this code takes longer to execute than the timer ticks, which might cause some issues.

An alternative architecture would be to pre-analyze the Visio drawing, find all of the shapes that should blink, save their Char.Color cells in an array, then blast them as fast as possible every time a tick occurs.


Private Sub m_blinkShapes()

  Dim pg As Visio.Page
  Set pg = Visio.ActivePage
 
  Dim shp As Visio.Shape
  For Each shp In pg.Shapes
    Call m_blinkShape(shp)
  Next shp
 
  '// Cleanup:
  Set shp = Nothing
  Set pg = Nothing

End Sub
Private Sub m_blinkShape(ByRef visShp As Visio.Shape)

  '// Use Characters.Text instead of .Text in
  '// case there is an inserted field:
  Dim t As String
  t = visShp.Characters.Text
 
  '// Bail if no asterisk in the text:
  If (InStr(1, t, "*", vbTextCompare) <= 0) Then Exit Sub
 
  '// Flip the color. Note: if the shape has text with
  '// multiple formats, then the shape will have multiple
  '// character rows. We are assuming just one row, where
  '// all the text has the same formatting:
  Dim visCell As Visio.Cell
  Set visCell = visShp.CellsU("Char.Color")
 
  '// Get the index to the color in the document:
  Dim iColIndex As Integer
  iColIndex = visCell.Result(Visio.VisUnitCodes.visUnitsColor)
 
  '// Get the Visio color object for the character:
  Dim visCol As Visio.Color
  Set visCol = visShp.Document.Colors(iColIndex)
 
  '// Note: since this toggles individual shapes, you could
  '// have some shapes going red-to-black, and others going
  '// black-to-red. This might be an issue, depending on the
  '// application.
 
  '// If IS BLACK:
  If (visCol.Red = 0 And _
      visCol.Green = 0 And _
      visCol.Blue = 0) Then
     
    '// Set to red:
    visCell.FormulaForceU = "RGB(255,0,0)"
   
  Else
 
    '// Set to black:
    visCell.FormulaForceU = "RGB(0,0,0)"
 
  End If
 
  '// Cleanup:
  Set visCell = Nothing
  Set visCol = Nothing

End Sub
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

wapperdude

Although I haven't looked in detail, but I'm pretty sure that in his most recent posts on gears, JuneTheSecond, uses a coded timer to do his animation.  Don't believe he has any crashing issues.   Might be worth exploring.

Wapperdude
Visio 2019 Pro

jebuxx

WOW! Super Duper job! Now I need to play with it to have it activate when an entry is made the violates any rules. Automate it in-place of a button.
If I am successful I will post my results.
I truly apperciate this website and all the help I have received over the past 7 months. Without it our project would be way behind schedule.
I have learned a ton! I hope I can be of the same assistance to all in the near future.