Visio Guy

Visio Discussions => Programming & Code => Topic started by: kiler40 on January 30, 2015, 11:20:48 AM

Title: Drop shape at cursor position and assign the macro to a function key
Post by: kiler40 on January 30, 2015, 11:20:48 AM
Hi Again
I feel that this must be something that i can find all over the net - but i really can`t figure it out.
I have a stencil with 2 shapes (one nod and one connector) i want to spread all over the page - hundreds of times.
As a background i have a map where what shape need to be.
So my goal is to point at the map, press a function key (if possible) and voilĂ  - the shape is there.
Can someone help and provide an example file - all i found on the internet I can`t make it work...

P.S.
Next step will be how to quick connect several connectors to one nod...  ;D ;D ;D 8)

Cheers
Title: Re: Drop shape at cursor position and assign the macro to a function key
Post by: kiler40 on January 31, 2015, 07:26:07 PM
Is it something wrong ? I receive mails about responses to the topic - but i cannot see nothing :/
Title: Re: Drop shape at cursor position and assign the macro to a function key
Post by: Yacine on January 31, 2015, 08:02:48 PM
Hi Andrei,
I did prepare an answer to your question, but withdrew it because it was not complete.
Well on Saturday it is still not complete, anyhow my advice would have been to change your strategy.


Instead of pressing a key, do a mouse click.
The mouse click would be trapped by a non-modal form and the mouse position would be recorded, then the right shape dropped at that position.



Now for the details ... and that's where I decided, your post could wait till next week.  ;D
Title: Re: Drop shape at cursor position and assign the macro to a function key
Post by: kiler40 on January 31, 2015, 08:23:23 PM
Fare enough :)
I get to the solution with mouse click. But it is giving a (i think) pixel position of the mouse - not position on drawing. And using a mouse click - i need to enable and disable this feature - i guess :)
Title: Re: Drop shape at cursor position and assign the macro to a function key
Post by: kiler40 on January 31, 2015, 08:24:12 PM
Anyhow. It can wait untill the weekend is over :) yes :)
Title: Re: Drop shape at cursor position and assign the macro to a function key
Post by: Yacine on February 01, 2015, 01:15:09 PM
Hi Andrei,
I'm so often too fast with my answers.
Basically both ways Click and Key press can be used.


The solution is to build a mouse listener for the activewindow and catch either a key press or a mouse down event.
This event catcher or listener will only be active when a toggle button on the form is pressed, this way you can switch between adding mode and normal working.
The form itself is set to non-modal to allow to work on the drawing whilst it is shown.

I enclose a stencil, in which the solution is shown. (The vsd is only to have a ready playground)
Drag one of the yellow shapes on the drawing to start the macro.


For fun I added a possibility to drop different masters. The only restriction is, that they must belong to the stencil. Otherwise you'd need to modify the code and add a routine to look in other stencils.


On the key press form, you could even add some text boxes to relate a certain key to a certain master. I'll leave that up to you.
Title: Re: Drop shape at cursor position and assign the macro to a function key
Post by: Yacine on February 01, 2015, 05:19:03 PM
As for the second question, I added also a stencil and uploaded a demo on Youtube.
http://youtu.be/hJYnLmxbhCs (http://youtu.be/hJYnLmxbhCs)
http://youtu.be/mH1tDvFrtq4 (http://youtu.be/mH1tDvFrtq4)
Title: Re: Drop shape at cursor position and assign the macro to a function key
Post by: kiler40 on February 02, 2015, 07:40:18 AM
Man - AGAIN !
This is amazing.
Now i have one question with this  :-[

in the shape i drop - there is a shape data that need be filled on drop. when i drag and drop from the stencil - the input window shows.
when i use the macro it is dropping without asking anything.
Why is that ?
Title: Re: Drop shape at cursor position and assign the macro to a function key
Post by: Yacine on February 02, 2015, 08:31:18 AM
Yes the "ask on drop" seems not to be working when the shape is dropped by a macro.
You can however add a "docmd(1312)" to the ondrop event cell in the events section.
Title: Re: Drop shape at cursor position and assign the macro to a function key
Post by: kiler40 on February 02, 2015, 08:34:19 AM
It cannot be more simple... Ofcourse .
Thanks again !
Title: Re: Drop shape at cursor position and assign the macro to a function key
Post by: Gustavo on May 29, 2017, 10:23:18 PM
Hi Yacine. I know this post has been around for quite some time. Anyway, I'm gonna ask for the sake of non repeating. Why I can only make it work with the shapes already in the stencil, and not with other shapes in the sheet, or shapes I import to the stencil? best regards.
Title: Re: Drop shape at cursor position and assign the macro to a function key
Post by: Yacine on May 30, 2017, 07:07:07 AM
Guess you mean the data dialog?
Actually you can call from other events. Just write the Docmd in the according field (eg: double click, action, data changed, etc.).
Title: Re: Drop shape at cursor position and assign the macro to a function key
Post by: Gustavo on May 30, 2017, 06:13:18 PM
Thank you for your answer Yacine, but I didn't mean the data dialog. I meant that, if I add other masters to the stencil, the macro doesn't work with them, even if I save the stencil with the masters added. What am I missing? best regards
Title: Re: Drop shape at cursor position and assign the macro to a function key
Post by: Yacine on May 31, 2017, 07:21:02 AM
That is just the simple way I implemented it.
You can easily extend the macro, to not only use masters in the stencil, but any one.

May be a button that asks the user to select the master to use.
Title: Re: Drop shape at cursor position and assign the macro to a function key
Post by: Gustavo on May 31, 2017, 05:04:29 PM
Brilliant solution for repetitive tasks of dropping multiple shape instances. Thank you.

Just take note other users of this wonderful macro. After some headscratching, I found the macro will only work with the masters universal name . If the local name of a master shape doesn't match the universal name, the master shape instance will not drop with this macro.

Best regards