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.

wapperdude

#15
Actually, does work with V2007.  Try this code:

Sub MoveShp2CntrView()

    Dim lVz As Double, tVz As Double, wVz As Double, hVz As Double
    Dim locX As Double, locY As Double
    Dim vsoShp As Shape
   
    Visio.ActiveWindow.GetViewRect lVz, tVz, wVz, hVz
'    Debug.Print "Current View Window: " & lVz, tVz, wVz, hVz

'Calculate center of View:
    locX = lVz + 0.5 * wVz
    locY = tVz - 0.5 * hVz
'    Debug.Print locX, locY

'Use shape based upon selection:
'    Set vsoShp = ActiveWindow.Selection(1)
'    vsoShp.CellsU("PinX").FormulaU = locX
'    vsoShp.CellsU("PinY").FormulaU = locY

'Use shape based upon ID:
    Set vsoShp = ActivePage.Shapes.ItemFromID(1)
    ActiveWindow.Select vsoShp, visSelect   'Optional:  this makes the shape ACTIVE
   
    vsoShp.CellsU("PinX").FormulaU = locX
    vsoShp.CellsU("PinY").FormulaU = locY
End Sub


Wapperdude
Visio 2019 Pro

perry59

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

do tell
what, me worry?

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

I'm not sure how the Window.GetWindowReectangle is going to help me.
I have already got my shapes dropped and grouped on the page. The thing I cant figure out is how to move them around on the page with the mouse cursor.
code like this does NOT work

'while mouse left button is NOT down...
        While mouseDownForConnector = False 'mouseDownForConnector is a global boolean variable
            'mouseDownForConnector is set to true and false by the mousehandler events
            groupShape.CellsU("PinX").FormulaU = mouseHandler.xPos.ToString() & " in"
            groupShape.CellsU("PinY").FormulaU = mouseHandler.yPos.ToString() & " in"
        End While


it just goes into an endless loop.
it seems that the group I create does not actually appear on the page until the function is completed.
maybe I should be trapping the shape drop event and trying to do my moving there (assuming the shape dropped is the one I want)
what, me worry?

Surrogate

Quote from: perry59 on March 01, 2017, 11:37:43 PMit just goes into an endless loop.
not sure that your task impossible in visio because there haven't special event for get mouse click coordinate.
For example AutoCAD have GetPoint Method which stoped code execution until then define point

perry59

Quote from: Surrogate on March 01, 2017, 11:52:04 PM
Quote from: perry59 on March 01, 2017, 11:37:43 PMit just goes into an endless loop.
not sure that your task impossible in visio because there haven't special event for get mouse click coordinate.
For example AutoCAD have GetPoint Method which stoped code execution until then define point

Good 'ole AutoCAD!
what, me worry?

wapperdude

@Perry59:  did you look at the code snippet I provided?  Well, please look at the attached file.

The macro draws two squares.  Then it groups them.  After grouping, the move shape macro is called.

To demonstrate:  start with just the oval shape visible.  More dramatic that way.  Then, zoom in on the oval, about 500X.  Reposition the window so the oval is NOT centered in the viewing window.  Now, run the macro.  Phoosh!  A group of 2 squares appears centered in the screen.  The group is still selected.  Mouse over, push left button down, drag the group to desired location.  NO mouse events necessary.

Wapperdude
Visio 2019 Pro

perry59

Quote from: wapperdude on March 02, 2017, 12:42:24 AM
@Perry59:  did you look at the code snippet I provided?  Well, please look at the attached file.

The macro draws two squares.  Then it groups them.  After grouping, the move shape macro is called.

To demonstrate:  start with just the oval shape visible.  More dramatic that way.  Then, zoom in on the oval, about 500X.  Reposition the window so the oval is NOT centered in the viewing window.  Now, run the macro.  Phoosh!  A group of 2 squares appears centered in the screen.  The group is still selected.  Mouse over, push left button down, drag the group to desired location.  NO mouse events necessary.

Wapperdude

Yes I have seen that. Thanks for posting.
Perhaps I have not been clear in what I am trying to achieve (which I am afraid is probably not possible in the visio API)
I have no problem in programmatically dropping shapes on the sheet, or moving them once they are there.
what I want to do is that immediately after the shape appears, it is "attached" to the mouse cursor and follows the mouse cursor until the user clicks, then it is set at that location.
Again, probably not possible, I may have to change my approach to the problem.
-Perry
what, me worry?

wapperdude

I think we're splitting hairs here.  I understand you know how to drop, group, and move.  The issue is attaching to the mouse.  Presumably, there are occasions when the drop/group may take place outside of user view, i.e., off screen.  And, the mouse will be within user view.  Hence, assign the group to the mouse and the group pops into view, attached to the mouse, and the user can drag to desired location and place.

I don't think you can do the attach to mouse, nor do I think it's necessary.  That was the point of the file and it's demo.  The macro replicates your drop/group, which, for the demo is off view screen.  Then, wherever the user is viewing, the group is moved to that location.  The group remains selected.  So, yes, the user must mouse over, left click, drag and position as desired.  That's minimal user interaction.  The user knows the shape will be center screen.  This ought to satisfy 98% of your requirements.  Plus, the code is quite simple.

Wapperdude
Visio 2019 Pro

perry59

Quote from: wapperdude on March 02, 2017, 05:01:52 PM
I think we're splitting hairs here.  I understand you know how to drop, group, and move.  The issue is attaching to the mouse.  Presumably, there are occasions when the drop/group may take place outside of user view, i.e., off screen.  And, the mouse will be within user view.  Hence, assign the group to the mouse and the group pops into view, attached to the mouse, and the user can drag to desired location and place.

I don't think you can do the attach to mouse, nor do I think it's necessary.  That was the point of the file and it's demo.  The macro replicates your drop/group, which, for the demo is off view screen.  Then, wherever the user is viewing, the group is moved to that location.  The group remains selected.  So, yes, the user must mouse over, left click, drag and position as desired.  That's minimal user interaction.  The user knows the shape will be center screen.  This ought to satisfy 98% of your requirements.  Plus, the code is quite simple.

Wapperdude

That's true.
what I originally wanted is probably not possible.
I'll have to modify my desires!
what, me worry?

wapperdude

Life is full of compromises!   :-\
Visio 2019 Pro

perry59

Quote from: wapperdude on March 02, 2017, 06:37:05 PM
Life is full of compromises!   :-\

That it is, but at least I can drop my shape where the user will see it!
Thanks
what, me worry?