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

Searching shapes and making stencils

Started by Reepi, November 25, 2024, 10:30:26 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Reepi

Hello, I'm using Visio 2016.  When I use the search bar for shapes and then shift click multiple results and right click it gives me the option to save.  If I do that I can automatically make a new stencil file that contains all the search results (across multiple other stencil files) in one place, which is what I want.  However, these stencils are not new stencils but shortcuts to the originals.  The same thing happens if I try copy pasting the search results into a new stencil file. 

I can make them into new stencils by dragging them onto the canvas and back into the stencil, but this adds a bunch of steps that are burdensome for the amount of stencil sets I need to make. 

Does anyone know a way to make this shortcut thing not happen?  It's only an issue when I am using search results, if I copy paste from a stencil that is open in my library to another it doesn't make shortcuts.  It would save me a huge amount of time if I could make it behave the same way with search results.

Thank you for your consideration.

wapperdude

#1
I'm including this link for reference:  https://support.microsoft.com/en-us/office/create-save-and-share-custom-stencils-a4c2235c-677d-4117-9673-1fef0a0ee22f

There are 3 ways to add shapes to custom stencils.  The 1st 2 are given in the link. 
Method 1, was drag and drop from drawing page to stencil.  Not very efficient as you've noticed.

Direct from stencil to stencil:
Method 2,  For your case, to make this efficient, do not park your custom stencil to the left, but allow it to float in the drawing window.  This alllows several stencil windows to be opened concurrently.  Now you can drag and drop directly to your custom stencil from an existing stencil.  This will add a copy of the shape, not a link.  This is probably best method.  You may <shift> + click on shapes 1 @ time to make multiple selection before dropping.

Method 3, In the "original" stencil, right click on the shape you desire.  This brings up a pop-up menu which has entry that asks Add to My Shapes.  Expand this entry to get a selection of stencil choices.  Click on the name of your custom stencil.  Done.  This is quite direct and easy.  This also works for multiple shape selections.

One additional comment.  Copy / paste also works in addition to drag / drop.  Select shape(s) of interest,...copy.  Then, hover over your custom stencil, right click, choose Paste, or <cntl>+ V to save. 

I did verify that all of these steps  create actual copies and not links.
Visio 2019 Pro

Reepi

Opening multiple floating windows will speed up my process, so thank you.  I just wish I could use the search function!  The source files these stencils are coming from are very big and finding the specific ones I want to isolate is a huge pain.

Thank you for your response, I really do appreciate it.

wapperdude

#3
The search copy/paste works fine.  From the Shapes window, in the search box, I typed arrow.  The window presents all manner of arrow shapes found.  Pressing <cntl> + clicking on various shapes Also allows  multiple selections which then can be dragged and dropped onto custom stencil.

Are you not able to do this?
Visio 2019 Pro

Reepi

Every time I do it the result is a shortcut.  I follow those exact steps and it looks like it works, but when I right-click the new stencil it's giving me options like "edit master shortcut" rather than "edit master > edit master shape" like I want.

wapperdude

Ah.  I finally replicated your issue.  It does seem to be restricted to the search results.
Visio 2019 Pro

wapperdude

Well,, it would appear that some code is likely necessary to capture the shapes from the search results.  Possibly 2 options.

The 1st would be to automate the process you've discovered to work.  That is, search, select, copy/drop to drawing page, then re-copy/drop to stencil.

The 2nd approach, which probably only works in some cases, would be to identify the stencil which contains the shapes desired, and then drag/drop to new stencil.  This is OK if all search results are from a single common stencil.  That seems quite unlikely.

For now, that's the best recommendation that I have.
Visio 2019 Pro

Reepi

Hmm, yeah I was afraid of that.  I may ask one of my coworkers who are better with VB to help me out. 

Thank you again for taking a look at it.  I just wanted to be sure there wasn't a simple option to turn master shortcuts off or something that maybe I was missing.

wapperdude

Actually, I believe with code it out to be possible to grab the shapes and go directly to the new stencil. 

Keep us posted on your progress.  Ask questions if you get stuck.
Visio 2019 Pro

Yacine

Whilst I think that this whole workflow is not ideal - instead of building up so big stencils, better use smartshapes that adjust to the needs - there is another way, that Wapperdude has not mentioned.
Drag all the shapes you need on your drawing, then save the document as stencil. Easy and straight forward.
Yacine

Reepi

Quote from: Yacine on December 03, 2024, 06:47:53 PMWhilst I think that this whole workflow is not ideal - instead of building up so big stencils, better use smartshapes that adjust to the needs
Haha I could write you a novel about why I'm doing what I'm doing, but the short version my organization is doing stuff with Visio it wasn't really meant for so I'm doing a lot of dumb stuff over here. (like literally removing smart functionality I spend days building x^x)

Quote from: Yacine on December 03, 2024, 06:47:53 PMDrag all the shapes you need on your drawing, then save the document as stencil. Easy and straight forward.
Oh yeah, that speeds it up for me a lot.  Thank you so much for your help!

wapperdude

#11
Well that takes all the fun out of it!!!   :D  :D  :D  ;)

@Yacine:  Nice idea.  Never occurred to me that such was a viable solution.  The OP had complained about dragging shapes onto the drawing page and then to new stencil.  Guess it didn't occur to him either.  Too funny.
Visio 2019 Pro

wapperdude

#12
I was having too much fun, so decided to finish this.  Here's code that will grab selected shapes in the shapes window and drop them onto another stencil.  The assumptions are that name and path of target stencil are know and hardcoded into the macro.  Before running the macro, shape search has been performed and shapes have been selected.  The process may be repeated if desired.  Once finished, the target stencil must be manually saved and closed.

Sub SelDropMaster2CustomStencil()
   
    Dim vWin As Visio.Window
    Dim MyStn As Visio.Document
   
    Dim chsnMstrs() As Object
    Dim incMstrs As Integer
    Dim incMstrshortCuts As Integer
    Dim vMstr As Visio.Master
    Dim vMstrShortcut As Visio.MasterShortcut
    Dim iCnt As Integer
    Dim arrMstr() As Variant
   
    iCnt = 0
       
    For Each vWin In ActiveWindow.Windows
        If (vWin.Type = visDockedStencilBuiltIn) Then
            chsnMstrs = vWin.SelectedMasters
            ReDim arrMstr(UBound(chsnMstrs) + 1) 'array for holding selected master shapes
            For iCnt = LBound(chsnMstrs) To UBound(chsnMstrs)
               On Error Resume Next
               Set vMstr = Nothing
               Set vMstrShortcut = Nothing
               Set vMstr = chsnMstrs(iCnt)
               Set arrMstr(iCnt + 1) = vMstr             'masters located on docked stencils
               
               If Not vMstr Is Nothing Then
                   incMstrs = incMstrs + 1
               Else
                   Set vMstrShortcut = chsnMstrs(iCnt)
                   Set arrMstr(iCnt + 1) = vMstrShortcut    'search results are master shortcuts
                   If Not vMstrShortcut Is Nothing Then
                       incMstrshortCuts = incMstrshortCuts + 1
                   End If
               End If
            Next
           
            If (incMstrs > 0 Or incMstrshortCuts > 0) Then
                Debug.Print "The stencil " & vWin.Document.Name   'optional debug prints of results
                Debug.Print "has" & Str(incMstrs) & " masters selected and "
                Debug.Print Str(incMstrshortCuts) & " master shortcuts selected."
               
                For i = 1 To UBound(chsnMstrs) + 1     'print of selected shapes...confirmation
                    Debug.Print arrMstr(i)

'***Path and filename hard coded:
                    Set MyStn = Documents.OpenEx("filepath\filename.vssx", visOpenRW)
                    MyStn.MasterShortcuts.Drop arrMstr(i), 0#, 0#   'drop method to place shapes on target stencil
                Next
                Exit For
            End If
        End If
    Next
End Sub
Visio 2019 Pro

Yacine

#13
Quote from: Reepi on December 03, 2024, 11:41:04 PMHaha I could write you a novel about why I'm doing what I'm doing, but the short version my organization is doing stuff with Visio it wasn't really meant for so I'm doing a lot of dumb stuff over here. (like literally removing smart functionality I spend days building x^x)

Some 20 years ago, my boss tought it would be a good idea to build stencils with one master per actual part, we usually used - around 500 items. A trainee got "misused" to do the job.
We used these stencil probably half a year, before dropping them completely. They were impossible to maintain.

So I set up smart components, that based on custom properties would replace their subshapes but the right ones. Instead of 500, I handle now around 10.

If there is any possibility for you to convince your company to work smarter, do it.
And if you provide details of your project - either openly in the forum, or via PM - we can certainly give you some support.
Yacine

wapperdude

@Yacine:  that makes perfect sense and well worth the effort.  Good job convincing your management.

The code was inspired by different perspective / use case.  Rather than minimizing the number of shapes, it was aimed at creating stencils of just frequently, commonly used shapes from a variety of stencils already provided by Visio or other sources.  This makes them more efficiently available rather than having to fumble thru multiple docked stencils or repeatedly searching. 

Visio 2019 Pro

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: 415 (show)
Files included: 34 - 1306KB. (show)
Memory used: 1263KB.
Tokens: post-login.
Cache hits: 14: 0.00199s for 26,725 bytes (show)
Cache misses: 3: (show)
Queries used: 16.

[Show Queries]