Visio Guy

Visio Discussions => Programming & Code => Topic started by: Miguel on April 04, 2017, 06:44:37 AM

Title: How can I do a test to know when a shape is selected or no in VBA?
Post by: Miguel on April 04, 2017, 06:44:37 AM
Hello people!

How can I do a test to know when a shape is selected or no in VBA?

Thank you !
Title: Re: How can I do a test to know when a shape is selected or no in VBA?
Post by: Surrogate on April 04, 2017, 07:53:46 AM
Hola amigo!

How will you define the Shape: by ID, by Name ?
Sub test()
Dim tst As Boolean
Dim id_ As Integer
Dim name_ As String
id_ = InputBox("Enter shape ID")
tst = CheckByID(id_)
MsgBox "Shape with ID " & id_ & " is selected ? " & tst
name_ = InputBox("Enter shape Name")
tst = CheckByName(name_)
MsgBox "Shape with Name " & name_ & " is selected ? " & tst
End Sub
Function CheckByID(idn As Integer) As Boolean
Dim sh As Shape, shp As Shape
CheckByID = False
Set sh = ActivePage.Shapes(1)
Dim sl As Selection
Set sl = ActiveWindow.Selection
If sl.Count = 0 Then MsgBox "No shapes selected !": Exit Function
For Each shp In ActiveWindow.Selection
If shp.ID = idn Then CheckByID = True: Exit Function
Next
End Function
Function CheckByName(shn As String) As Boolean
CheckByName = False
Dim sh As Shape, shp As Shape
Set sh = ActivePage.Shapes(1)
Dim sl As Selection
Set sl = ActiveWindow.Selection
If sl.Count = 0 Then MsgBox "No shapes selected !": Exit Function
For Each shp In ActiveWindow.Selection
If shp.Name = shn Then CheckByName = True: Exit Function
Next
End Function

Title: Re: How can I do a test to know when a shape is selected or no in VBA?
Post by: Miguel on April 04, 2017, 08:12:31 AM
Tkx amigo!

My shape are defined by the name!  ;D

But I have this code :

  If vsoSelection.Count <> 1 Then  'Une Shape doit etre sélectionné
        MsgBox "Select a shape, then re-run macro."
        Exit Sub
    Else
        Set vsoShape = ActiveWindow.Selection(1)
    End If
End Sub


Title: Re: How can I do a test to know when a shape is selected or no in VBA?
Post by: Surrogate on April 04, 2017, 11:10:40 AM
You code just set shape variable for single selected shape ! Without test :)
Title: Re: How can I do a test to know when a shape is selected or no in VBA?
Post by: Miguel on April 04, 2017, 11:35:47 AM
Yes, it's a good job!
You are of great help to me!  ::)

And do you know if there is a method which could know when Z shapes are glued or not ?
Title: Re: How can I do a test to know when a shape is selected or no in VBA?
Post by: Surrogate on April 04, 2017, 11:38:15 AM
Quote from: Miguel on April 04, 2017, 11:35:47 AM
Z shapes
what is it ?
Title: Re: How can I do a test to know when a shape is selected or no in VBA?
Post by: Miguel on April 04, 2017, 11:44:57 AM
Typping error. Sorry.

I'm talking about a method or little code which check if a 2 shapes are glued together.
Title: Re: How can I do a test to know when a shape is selected or no in VBA?
Post by: Surrogate on April 04, 2017, 12:13:02 PM
There are great articles about connections in Visio by David J Parker (https://mvp.microsoft.com/ru-ru/PublicProfile/21090?fullName=David%20John%20Parker)

Listing Connections in Visio 2010 (https://blog.bvisual.net/2009/09/16/listing-connections-in-visio-2010/)
Getting the Name of Glued Connection Points (https://blog.bvisual.net/2013/05/21/getting-the-name-of-glued-connection-points/)
Title: Re: How can I do a test to know when a shape is selected or no in VBA?
Post by: Surrogate on April 05, 2017, 07:59:36 AM
Quote from: Miguel on April 04, 2017, 11:44:57 AMwhich check if a 2 shapes are glued together
how you want specify these shapes: by IDs, by Names or just select shapes at page ? Does it matter who to whom is glued?
Title: Re: How can I do a test to know when a shape is selected or no in VBA?
Post by: Miguel on April 05, 2017, 12:52:06 PM
Hum I will be more precise.

I have 2 shapes : a rectangle and a triangle. There are very simple. The Rectangle has 16 point of controls and the triangle 2. All of the points of controls are Inward&Outward!.
So when one of a point of controls of my triangle touch one of the point of controls of the rectangle, my 2 shape glue together. So the bonding is done manually.

Now, I would like to write a little code which check if the bonding exist. For example, if the bonding exist so i colour my triangle in red.

If   MY SHAPES ARE GLUED   then
             xxxxxxxxxx
              xxxxxxxxxx



I hope that you understand now my problem :) ::)
Thank you
Title: Re: How can I do a test to know when a shape is selected or no in VBA?
Post by: Surrogate on April 05, 2017, 01:00:50 PM
But how you specify that rectangle and triangle ?
Title: Re: How can I do a test to know when a shape is selected or no in VBA?
Post by: Miguel on April 05, 2017, 01:05:00 PM
Quote from: Surrogate on April 05, 2017, 01:00:50 PM
But how you specify that rectangle and triangle ?
This 2 shapes there are in my stencil. The shapes contain data imported from an excel table. 
Title: Re: How can I do a test to know when a shape is selected or no in VBA?
Post by: Surrogate on April 05, 2017, 01:11:35 PM
Quote from: Miguel on April 05, 2017, 01:05:00 PMThis 2 shapes there are in my stencil
Your stencil is certain document ! And masters Rectangle and Triangle are different.
We can check connections ONLY on page !
Quote from: Miguel on April 05, 2017, 01:05:00 PMThe shapes contain data imported from an excel table.
NEVERMIND !
Title: Re: How can I do a test to know when a shape is selected or no in VBA?
Post by: Miguel on April 05, 2017, 01:15:58 PM
Yes of course, the masters are different!

Quote from: Surrogate on April 05, 2017, 01:11:35 PM
We can check connections ONLY on page !

Can you give me an example please ?
Title: Re: How can I do a test to know when a shape is selected or no in VBA?
Post by: Surrogate on April 05, 2017, 01:31:33 PM
Quote from: Surrogate on April 05, 2017, 01:11:35 PMWe can check connections ONLY on page !
I wrong ! i mean that check connections and glue shape to shape are different task. I want know what you want ?
Quote from: Miguel on April 05, 2017, 01:15:58 PMCan you give me an example please ?
Quote from: Surrogate on April 04, 2017, 12:13:02 PMListing Connections in Visio 2010 (https://blog.bvisual.net/2009/09/16/listing-connections-in-visio-2010/)
Getting the Name of Glued Connection Points (https://blog.bvisual.net/2013/05/21/getting-the-name-of-glued-connection-points/)
Title: Re: How can I do a test to know when a shape is selected or no in VBA?
Post by: Miguel on April 05, 2017, 01:42:30 PM
Quote from: Surrogate on April 05, 2017, 01:31:33 PM
I wrong ! i mean that check connections and glue shape to shape are different task. I want know what you want ?

I would like to check the connections between the two shapes thanks to the connections points.


Quote from: Surrogate on April 04, 2017, 12:13:02 PMListing Connections in Visio 2010 (https://blog.bvisual.net/2009/09/16/listing-connections-in-visio-2010/)
Getting the Name of Glued Connection Points (https://blog.bvisual.net/2013/05/21/getting-the-name-of-glued-connection-points/)

I already read it thx.
Title: Re: How can I do a test to know when a shape is selected or no in VBA?
Post by: wapperdude on April 05, 2017, 02:42:23 PM
@Miguel: 
QuoteAll of the points of controls are Inward&Outward!
These are connections, not controls.  It's confusing when incorrect terms are used.

Is this what you're saying?  Manually, you drag and drop a rectangle onto a drawing page.  Then you drag and drop a triangle.  The triangle is moved over to the rectangle and you want to know if it glued using code?   What is the purpose behind this?  There are several possibilities:
1)  as you move two shapes together, you should see connection point turn red, that means glued.  If not red, not glued.
2)  By code, you 1st have to select both shapes, then run code to check all connected shapes to see if these chosen ones both are connected together.  Then, color the shape.
3)  is that all you want)

Use the macro recorder:  you have to decide when to start the recorder...before shapes are dropped, after they are dropped, whatever.  Assume both shapes are already on page, start recorder, select triangle, slide it over and glue to rectangle, color triangle, stop recorder.  That gives process of gluing to shapes together. 

You might look at this:  https://msdn.microsoft.com/en-us/library/office/ff767122.aspx (https://msdn.microsoft.com/en-us/library/office/ff767122.aspx)
and this:  https://msdn.microsoft.com/en-us/library/office/ff765584.aspx (https://msdn.microsoft.com/en-us/library/office/ff765584.aspx)
and this:  https://blog.bvisual.net/2013/05/21/getting-the-name-of-glued-connection-points/ (https://blog.bvisual.net/2013/05/21/getting-the-name-of-glued-connection-points/)

Wapperdude


Title: Re: How can I do a test to know when a shape is selected or no in VBA?
Post by: Surrogate on April 06, 2017, 05:18:11 AM
(http://forum.aktuell.ru/images/smilies/ot.gif)
Quote from: Miguel on April 04, 2017, 06:44:37 AMHow can I do a test to know when a shape is selected or no in VBA?
I think it will be great test it via shapesheet ! If you aggry vote for this advice IsSelected and IsMouseOver ShapeSheet cell (https://visio.uservoice.com/forums/368205-visio-for-developers/suggestions/5960855-isselected-and-ismouseover-shapesheet-cell) at Visio Suggestion Box (https://visio.uservoice.com/)
Title: Re: How can I do a test to know when a shape is selected or no in VBA?
Post by: Miguel on April 06, 2017, 09:15:52 AM
Thank you for your help  8)