Main Menu

Recent posts

#1
@Chris, I saw the IsIdle property too, but the help said it gets only fired if you are listening to other events. Didn't understand and dropped this path.

But, and that is funny, I saw your answer in a google forum twenty years back and this inspired me to the following solution.

We don't need to handle the last event, but ONE event. So let it be the first one and block for a certain period all the following events.
We use a flag "Busy" to destroy the unwanted events, go in a loop with a doevents to prevent blocking other stuff and that's it.

Dim bBusy As Boolean
Dim counter As Long
Dim rejected As Long

Sub ConnPtAdjust(shp As Visio.Shape)
  Dim start As Double
  If bBusy Then
'    Debug.Print "Reject event"
      rejected = rejected + 1
    Exit Sub
  Else
    rejected = 0
    bBusy = True
    start = Timer
    counter = counter + 1
    Debug.Print "Start time: ", start
    While Timer - start < 1
      DoEvents
    Wend
    Debug.Print "Executing now @", Timer, "repetition", counter, "Rejected events", rejected
    actualRoutine shp
    bBusy = False
   
  End If
 
End Sub

Sub actualRoutine(shp As Visio.Shape)
  ' do stuff
End sub

#2
Without reading the post carefully, there's a way to handle this: your function ConnPtAdjust does one little thing:

bStuffChanged = TRUE

You might also want to note the shape's id, so you can find it later...

collChangedIds.Add(id)

...'later' happens when Visio.Application.NoEventsPending or  Visio.Application.IsIdle fire off. I can never remember which is the best event. When one of these fires, you process your que of IDs if bStuffChanged is true, and update your shapes.

This allows Visio to "settle down" after a flurry of events. So it matters less that your event is firing many, many times.

You'll have to figure out how to pass the id to your procedure. CALLTHIS allows for some arguments.

#3
Programming & Code / Re: RubberduckVBA
Last post by Visio Guy - Today at 05:19:31 PM
I made a tool years ago to help export and import VBA files, so that I would have text backups in case the Visio binaries got hosed. But every time I get a new machine, I have to remember how to install it (requires some weird reg settings).

It appears that RubberDuck is still being developed

Rubberduck Home Page - newest release is 2023.11.27

There's an interesting video from five years ago that appears to be a showcase project for RubberDuck:

Play Battleship in Excel!

#4
[quoteLost patience and dropped the idea][/quote]
I actually did spend a bit of time on this.  The concept seemed sound.  But ultimately, I think what happens is that the last event gets filtered by the timer too. After all, the system ought to be consistent in that regard.  Consequently, either all events are allowed to go thru or no events.  Using the timer did not allow the code to uniquely identify the last event.

What is it that makes the last event unique?  It is the mouse release (mouse up event) that immediately stops the dragging.  But there are a lot of mouse up events too.  So, the starting process is mouse down & shape selection & height change (& not 1D shape).  Followed by termination of mouse up.  What we take for granted is not a simple process.
#5
Isn't your solution handling only the first event?
We need to handle the last one.

Regarding the solution I posted, Wayne is right. The function gets called several times.

I consulted both ChatGPT and Gemini for a solution involving a timer object, but they did not manage to find a workable code.
In my idea the very first call would start the timer object and set a flag. As long as this flag is not reset do nothing.

A handler that the timer object triggers when the time is elapsed would then call the actual routine, then reset the flag.

Lost patience and dropped the idea. I don't know if someone else wants to pick it up.
#6
I store the status in a user field to prevent such feedback loops:
QuoteEventXFMod=IF(User.Processing,SETF(GetRef(User.Processing),FALSE),SETF(GetRef(User.Processing),TRUE)+CALLTHIS("DoSomething"))

And some demo VBA:
Sub DoSomething(shp As Visio.Shape)
    Debug.Print "Do something that triggers EventXFMod..."
    shp.Cells("Width").ResultIU = 2 * shp.Cells("Width").ResultIU
End Sub
#7
Well, the global delay thing doesn't work for me.  I did add a test for lastcall=0, which will occur 1st time code runs with new launch of Visio. The timing errors tend to be grouped together, but range all over the place.  Doesn't seem to be a pattern nor predictable.

#8
ShapeSheet & Smart Shapes / Re: SETATREF(Height) / EventXF...
Last post by wapperdude - April 25, 2024, 06:45:29 PM
Alrighty.  Copied / pasted the red code.  Variable declaration as global, the little IF timer is 1st executable in the macro.  Still doesn't execute properly.  I did tbhis with original code, located in Module1.,,

However, I did put a code break to pause the code before IF statement executed, then let code run, and all is well.  So, the If statement is being recognized.  Perhaps the test value needs adjusting. 

Seems to me, catching moluse button up event ought to be, perhaps less PC dependent, more reliable/predictable.

Edit:  Also need to test for initial case when lastcall = 0.  This would pass the IF test, but give incorrect multi-looping.
#9
Deployment / Re: Online Shapes Library
Last post by Thomas Winkel - April 25, 2024, 12:10:26 PM
Quote from: Nikolay on April 25, 2024, 01:07:44 AMIt requires that ".dll.config" if you use the Newtonsoft JSON (it overrides some old versions there).
At least that's my assumption.
I have another much bigger Visio AddIn project that also uses Newtonsoft.Json and project settings (but not WebView2).
And there I do not publish the dll.config.
I spent an hour trying to find the difference with no result... :-\
Maybe the difference is that the other AddIn does not access the project settings on load.

Quote from: Nikolay on April 25, 2024, 01:07:44 AMBTW Microsoft itself does not hesitate to charge for that $540 a year (via DigiCert)
And we are stupid enough to publish solutions for MS products for free... ;D
#10
Deployment / Re: Online Shapes Library
Last post by Thomas Winkel - April 25, 2024, 11:56:37 AM
Ok, next try:
https://github.com/Visio-Resources/VisioOnlineShapesLibrary/releases/tag/v0.1.3

Please test:
* Installation
* Drag the Shape from the default server
* Contribute some shapes to this server
You can also try to set-up your own server.
The AddIn now has the option to switch between servers.

The default server (www.visio-shapes.com) is only for testing.
So do not hesitate to contribute as much nonsense as you like ;D
I'm interested how it behaves if many people access it at the same time.

Next step is "user management".
But first I need to learn more about Flask:
https://www.youtube.com/playlist?list=PL7yh-TELLS1EyAye_UMnlsTGKxg8uatkM

Once we have user management I can go on with Rename / Edit / Delete / Public / Private.