drop master here

Started by perry59, February 21, 2017, 11:17:44 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

perry59

there are a number of examples of dropping master shapes on a document, so that is pretty easy and straightforward.
They all have in common one thing though, you have to supply coordinates to place it. i.e.  page.Drop(master, 4, 4)
My question is:
Is there any way to programmatically drop a master, but have the shape attached to the mouse cursor as if you were dragging it off a stencil?

Surrogate

#1
that code can get click coordinates.
QuoteThis code is part of code which originally posted at
https://translate.google.ru/translate?sl=ru&tl=en&js=y&prev=_t&hl=ru&ie=UTF-8&u=http%3A%2F%2Fvisio.getbb.ru%2Fviewtopic.php%3Ff%3D15%26t%3D671&edit-text=&act=url
Dim WithEvents myapp As Visio.Application
Dim x As Double, y As Double

'Start-up procedure
Sub Start ()
Set myapp = Application
End Sub

'Beginning of the intersecting separation frame - storing coordinates
Private Sub myapp_MouseDown (ByVal Button As Long, ByVal KeyButtonState As Long, ByVal x1 As Double, ByVal y1 As Double, CancelDefault As Boolean)
If Button = 1 Then 'Left mouse button
x = x1: y = y1
End If
End Sub
but i haven't idea how make the program wait when the user clicks ?

perry59

Thanks Surrogate
I know how to get the mouse coordinates, but I don't think there is a way to drop a shape without supplying coordinates in the function call.
what I would like to do is something like drop shape function where the shape follows the mouse cursor until it is clicked, then completes.

wapperdude

#3
I'm probably the last person to comment on something like this...have no idea how to use events...but what strikes me about  is that mouse events are reactionary, that is, the mouse does something and an event fires.  I don't think there are mouse command objects or properties, so you can't attach the shape to the mouse.

Wapperdude
Visio 2019 Pro

Hey Ken

Perry:

    I do this trick all the time with my stencil-based macros.

    I start with a Mouse Up window event in the stencil's ThisDocument module that stores the mouse X and Y in the document's shapesheet as follows:



Public WithEvents EventWindow As Visio.Window

Private Sub EventWindow_MouseUp(ByVal Button As Long, ByVal KeyButtonState As Long, ByVal x As Double, ByVal y As Double, CancelDefault As Boolean)

Dim TheDocument      As Document
Dim TheDocumentSheet As Shape

Set TheDocument = ActiveDocument
Set TheDocumentSheet = TheDocument.DocumentSheet

If Not TheDocumentSheet.CellExists("User.MouseX", 0) Then
    TheDocumentSheet.AddNamedRow(visSectionUser, "MouseX", 0)
    End If
If Not TheDocumentSheet.CellExists("User.MouseY", 0) Then
    TheDocumentSheet.AddNamedRow(visSectionUser, "MouseY", 0)
    End If

TheDocumentSheet.Cells("User.MouseX").Formula = x
TheDocumentSheet.Cells("User.MouseY").Formula = y

End Sub



    Next, on the master shape, on its shapesheet, in the EventDrop cell, I have a call to a stencil macro, =CALLTHIS("ThisDocument.Dropped","Kencil"), where "Kencil" is the name of my stencil , and "Dropped" is defined in the stencil's ThisDocument module as follows:



Public Sub Dropped(ByRef TheDroppedShape As Visio.Shape)

Dim TheDocument      As Document
Dim TheDocumentSheet As Shape

Set TheDocument = ActiveDocument
Set TheDocumentSheet = TheDocument.DocumentSheet

TheDroppedShape.Cells("PinX").Formula = TheDocumentSheet.Cells("User.MouseX").Formula
TheDroppedShape.Cells("PinY").Formula = TheDocumentSheet.Cells("User.MouseY").Formula

End Sub



   My apologies, but I did not test this code.  I'd post the original out of my Kencil, but it has a lot of other stuff that obfuscates the simplicity of the task. But this should point you in the right direction--I hope.

    - Ken


Ken V. Krawchuk
Author
No Dogs on Mars - A Starship Story
http://astarshipstory.com

perry59

Quote from: Hey Ken on February 23, 2017, 02:15:48 PM
Perry:

    I do this trick all the time with my stencil-based macros.

    I start with a Mouse Up window event in the stencil's ThisDocument module that stores the mouse X and Y in the document's shapesheet as follows:



Public WithEvents EventWindow As Visio.Window

Private Sub EventWindow_MouseUp(ByVal Button As Long, ByVal KeyButtonState As Long, ByVal x As Double, ByVal y As Double, CancelDefault As Boolean)

Dim TheDocument      As Document
Dim TheDocumentSheet As Shape

Set TheDocument = ActiveDocument
Set TheDocumentSheet = TheDocument.DocumentSheet

If Not TheDocumentSheet.CellExists("User.MouseX", 0) Then
    TheDocumentSheet.AddNamedRow(visSectionUser, "MouseX", 0)
    End If
If Not TheDocumentSheet.CellExists("User.MouseY", 0) Then
    TheDocumentSheet.AddNamedRow(visSectionUser, "MouseY", 0)
    End If

TheDocumentSheet.Cells("User.MouseX").Formula = x
TheDocumentSheet.Cells("User.MouseY").Formula = y

End Sub



    Next, on the master shape, on its shapesheet, in the EventDrop cell, I have a call to a stencil macro, =CALLTHIS("ThisDocument.Dropped","Kencil"), where "Kencil" is the name of my stencil , and "Dropped" is defined in the stencil's ThisDocument module as follows:



Public Sub Dropped(ByRef TheDroppedShape As Visio.Shape)

Dim TheDocument      As Document
Dim TheDocumentSheet As Shape

Set TheDocument = ActiveDocument
Set TheDocumentSheet = TheDocument.DocumentSheet

TheDroppedShape.Cells("PinX").Formula = TheDocumentSheet.Cells("User.MouseX").Formula
TheDroppedShape.Cells("PinY").Formula = TheDocumentSheet.Cells("User.MouseY").Formula

End Sub



   My apologies, but I did not test this code.  I'd post the original out of my Kencil, but it has a lot of other stuff that obfuscates the simplicity of the task. But this should point you in the right direction--I hope.

    - Ken

Thanks Ken, but that is not really what I am looking for

perry59

Quote from: wapperdude on February 23, 2017, 02:18:51 AM
I'm probably the last person to comment on something like this...have no idea how to use events...but what strikes me about  is that mouse events are reactionary, that is, the mouse does something and an event fires.  I don't think there are mouse command objects or properties, so you can't attach the shape to the mouse.

Wapperdude

Yeah, it's dumb that the DROP method requires pre-defined coordinates.
what if those pre-defined coordinates are the upper left corner of the drawing and the user is zoomed into the lower right corner. when he runs the command he'll never see the shape get dropped.
Lame!

perry59

One may wonder why I want to do this in code, since you can just drag a master off a stencil with the effect that I want.
What I need to do is pull one master out of the stencil, then pull another shape off the stencil and place it into the first one, thereby creating a group which I then want to drag to its location on the page. The configuration of this group can change depending on user input so I cant just put all these grouped objects in the stencil.
An idea occurred to me, but haven't tried in code yet. Maybe this could work. I will try to drop the master in some location way off the page where it likely wont be seen, then drop the other shapes into it, make the group. Then with the group selected, constantly update its PinX and PinY cells based on input from a mouse listener. When the user clicks, quit updating those cells and turn off the mouse listener.
Does this sound do-able?

wapperdude

Well, why did cross my mind.

Using the Window.GetWindowReectangle method ought to allow you to determine a set of coordinates within the viewing window.  You could drop your shapes to desired coordinate, group, and since viewable, grab and locate as needed.  This is for newer Visio versions, so, I can't discuss it.  https://msdn.microsoft.com/en-us/library/office/ff765668.aspx

Wapperdude
Visio 2019 Pro

AndyW

Can't you drag your initial shape from the stencil and drop it where you want it, then programatically take your other shape from the stencil and group it into the original dropped shape.
Live life with an open mind

perry59

Quote from: AndyW on February 24, 2017, 02:12:01 PM
Can't you drag your initial shape from the stencil and drop it where you want it, then programatically take your other shape from the stencil and group it into the original dropped shape.

You could do that, of course, but that is not what I want to do.
This is going to be a command function in a larger visio addin for adding electrical connectors to a sheet.
the user selects a connector from the database and it is inserted.
I don't want the command to ask the user to select a connector from the database and then ask him to drag stuff from a stencil (which may or may not be loaded/visible)

wapperdude

Connectors say you.  Tell us a little more or show a couple examples of variants.  This might be do-able with a single smartshape.  There have been several different style/versions done on the forum. 

Wapperdude
Visio 2019 Pro

AndyW

You could use OLE drag-n-drop, drag something off your form, then tracking the mouse events put your shape at the drop location on you diagram.

https://youtu.be/apUZ1Xt3EKc
Live life with an open mind

perry59

#13
Quote from: wapperdude on February 25, 2017, 12:12:57 AM
Connectors say you.  Tell us a little more or show a couple examples of variants.  This might be do-able with a single smartshape.  There have been several different style/versions done on the forum. 

Wapperdude

These are connectors used in aviation equipment. Typically Mil Spec or our custom D-subs. they can have a few as 9 contacts or over 100.
The contacts (pins or sockets) and the connector symbol will be part of a group with custom properties. A sql database will track how many contacts are shown. A connector can be "broken", i.e. part of it shown on one page, another part of it shown somewhere else but it would still be considered the same physical connector by the database. The user may choose to show all the contacts or just some. So unused contacts can still be used later by inserting another portion of the connector. When a visio connector object is attached to a contact, it sets a flag for that contact in the database as being used. This allows for creating reports on how many connectors are in a project and how many of their contacts are "hooked up". I also generate wire reports on all visio connector objects which are "wires" and their to-from.
I have attached a small drawing showing a couple of variations.

perry59

Quote from: wapperdude on February 24, 2017, 12:28:56 AM
Well, why did cross my mind.

Using the Window.GetWindowReectangle method ought to allow you to determine a set of coordinates within the viewing window.  You could drop your shapes to desired coordinate, group, and since viewable, grab and locate as needed.  This is for newer Visio versions, so, I can't discuss it.  https://msdn.microsoft.com/en-us/library/office/ff765668.aspx

Wapperdude

looks like that wont work with visio 2007, which I am stuck with.
I am busy with a Solidworks project right now. when I'm done I will get back to my mad visio experiments!