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

Insert Mastershape by Macro

Started by TwoBeAss, March 13, 2024, 09:03:44 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

TwoBeAss

Hi,
is it possible to add a mastershape from the current stencil to the drawing in way regular shapes were drawn on the page ? I want to have the shape attached to the mouse pointer and place it with a click...

wapperdude

#1
By code you can use the drop method.  Sample code:

Sub dropMstr()
    Dim StnName As String
    Dim MstrName As String
    Dim docStn As Visio.Document
    Dim vMstr As Visio.Master
   
    StnName = "BASFLO_U.vssx"
    MstrName = "Decision"
    Set docStn = Application.Documents(StnName) ' Stencil must be loaded.
   
    ActiveWindow.Page.Drop docStn.Masters.ItemU(MstrName), 5.5, 4.25

End Sub


This places shape at fixed location.  It's possible to parameterize these coordinates. 
(1) capture event of mouse click.  That's above my pay grade
(2) preselect a shape near where you want the drop.  Modify code to read PinX and PinY coordinates, add some offset, and use those values for drop location.
Visio 2019 Pro

TwoBeAss

This is what I actually do, but I have a custom ribbon with the ability to add a master shape and I thought it would be nice to have it available like a regular drawing function... But it seems not to be worth the effort ;)

wapperdude

Ah.  So that's what you meant!  You want the shape (or a link to it) to be on the GUI. 

Hmmm.  Never tried.  Never gave it thought.  Initial reaction, no cannot do it.  Main obstacle...shape must always exist and Visio is aware of it's existence.
Visio 2019 Pro

TwoBeAss

I can handle the existence of the shape, as the ribbon is just loaded if the master stencil loads... Actually i have a button that places the shape on the top left corner, but i would like it to be placed after a click...

Thomas Winkel

If the master is in the same stencil as your code you can do this:

Public Sub CopyMasterToClipboard()
    ThisDocument.Masters.item("Name").Shapes(1).Copy
End Sub

And then: right click -> paste

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: 230 (show)
Files included: 32 - 1207KB. (show)
Memory used: 1092KB.
Tokens: post-login.
Cache hits: 13: 0.00145s for 26,722 bytes (show)
Cache misses: 3: (show)
Queries used: 17.

[Show Queries]