News:

BB code in posts seems to be working again!
I haven't turned on every single tag, so please let me know if there are any that are used/needed but not activated.

Main Menu

Find Complete Path: shapes and connectors

Started by wapperdude, February 05, 2019, 10:40:36 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

wapperdude

Chalk another one up for new Visio.  The following development finds all shapes and connectors that are interconnected.  It does not differentiate the direction of the connected.  Think of a circuit board or wiring diagram. Component A connects via trace 1 to Component B who's connected to Component C via trace2.  The code allows for connector to connector connections, shapes with multiple connections.

To use, select one object.  It may be either a 2D shape or a connector / 1D line.  Run macro.  All interconnected objects are highlighted.

The code consists of an interface model that determines the type of connection selected.  It then makes the appropriate call to either of two sub-modules.  One looks for shapes attached to a connector and the other looks for connectors that are attached to a shape.  These two modules call each other recursively.  Each sub-module uses the "highlight" color to avoid endless looping by eliminating already colored objects.  Both modules use the GluedShapes method.

Here's a test / evaluation file.
Visio 2019 Pro

joe.h

Hi, Undo resets one shape at a time. How do you reset (remove highlighting) all the shapes at once?
Thanks.

wapperdude

Seems to work fine on my desktop and laptop.  Both run Win11, V2019Pro.

Explain more about your setup and what steps you've taken.
Visio 2019 Pro

Nikolay

Joe most probably means that after (successfully) running the macro, you need to click "Undo" multiple times to get back to the initial diagram. I think this is how it is supposed to work though, not sure why this is a problem. You are not supposed to click Undo at all, to start with.

May be more interesting, the macro seems to trow an error on non-english system (i.e. does not work on non-US machines). Appears to be separator issue like always, Formula/FormulaU.

wapperdude

The way it works: select shape. Run macro, view results...end of process.  It was a demo.  A single undo will reset everything.  After Undo, you can make another selection, and hit Redo.  Macro will run using current selection.  The code only does highlighting.  No reports.
Visio 2019 Pro

wapperdude

I vaguely remember a similar post to this one, but, cannot recall what it is.  The file of this post was modified to search in a "from this point and more recent additions".  That is, it takes the selected shape ID and finds only shapes that were added and connected since its addition. It functions similarly to the current file. I add that file here.
Visio 2019 Pro

joe.h

Interesting, for me, a single undo will not reset everything. Have to hit undo multiple times, once for each shape/connector in the path. Not a big deal since it's a demo. I'm using Win 11 Pro, Microsoft® Visio® Plan 2 MSO (Version 2406 Build 16.0.17726.20206) 64-bit.

wapperdude

Interesting indeed.  My suspicion is that the undo is handled differently with Plan 2 vs the desktop version.

Perhaps other users can try this out and report back their experience?  There are reports that their are behavioral differences between desktop and Plan1 / Plan 2.
Visio 2019 Pro

Yacine

You'll need to add an error handling that ensures that the undoscope is closed whether with or without error.
Yacine

Nikolay

#9
To make sure undo works in one go, you can just wrap all operations between Application.BeginUndoScope and Application.EndUndoScope:

scope = Application.BeginUndoScope ("Highlight Shapes")

.... do a lot of things ...

Application.EndUndoScope(scope, True)



But I don't think this is needed for demo.

wapperdude

#10
Well, since I cannot verify the apparent problem, the proposed solution ought to solve the issue, but, I cannot demo it to be true.   

To misquote the Pakleds from Star trek TNG:  "Yacine and Nikolay are smart.  They make demo undo."
 ;D  ;D  ;D
Visio 2019 Pro

joe.h

#11
Quote from: Nikolay on September 04, 2024, 09:27:43 AMTo make sure undo works in one go, you can just wrap all operations between Application.BeginUndoScope and Application.EndUndoScope:

scope = Application.BeginUndoScope ("Highlight Shapes")

.... do a lot of things ...

Application.EndUndoScope(scope, True)



But I don't think this is needed for demo.

I got a syntax error so I looked here, https://learn.microsoft.com/en-us/office/vba/api/visio.application.endundoscope, the syntax below works. The method belongs in the Public sub (see below), if anyone else is interested.

Public Sub FindThePath()
scope = Application.BeginUndoScope("Highlight Shapes")
    Dim selShp As Visio.Shape
    Dim shpIDs() As Long
    Dim conIDs() As Long

    conClr = "RGB(255, 200, 0)"
    shpClr = "RGB(255, 255, 204)"
'    Debug.Print "conClr = ", conClr
'    Debug.Print "shpClr = ", shpClr
   
    Set selShp = ActiveWindow.Selection(1)
    If selShp.OneD Then            'If selected shape is 1D, then look for shapes
        Set conShp = selShp
        conShp.Cells("LineColor").Formula = conClr
        Call GluedShps(conShp)
    Else                            'Selected shape is 2D, look for connectors
        Set srcShp = selShp
        srcShp.Cells("LineColor").Formula = conClr
        srcShp.Cells("FillForegnd").Formula = shpClr
        Call GluedCons(srcShp)
    End If
Application.EndUndoScope scope, True
End Sub

Browser ID: smf (possibly_robot)
Templates: 4: index (default), Display (default), GenericControls (default), GenericControls (default).
Sub templates: 6: init, html_above, body_above, main, body_below, html_below.
Language files: 4: index+Modifications.english (default), Post.english (default), Editor.english (default), Drafts.english (default).
Style sheets: 4: index.css, attachments.css, jquery.sceditor.css, responsive.css.
Hooks called: 358 (show)
Files included: 34 - 1306KB. (show)
Memory used: 1221KB.
Tokens: post-login.
Cache hits: 13: 0.00436s for 26,734 bytes (show)
Cache misses: 2: (show)
Queries used: 15.

[Show Queries]