Search docked Stencil, drop Shape

Started by wapperdude, January 26, 2019, 06:49:40 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

wapperdude

The following code works, but is there a better method or a more direct method?
The code searches for a known stencil, and once found, grabs a desired Master from the stencil and drops onto a drawing page.

Comments please!?!

Sub FindStencilDropShp()
'This routine looks at all windows in the document'
'First, ignores windows that are not Docked, and furnished stencils
'Then, it compares the candidate windows to the desired window.  Assumes that desired
'window is docked.
'Once window found, it will select desired Master from stencil and drop at specified location
'in the ActiveWindow.
'Wapperdude, 1/26/2019
'
    Dim vsoDoc As Document
    Dim i As Integer
    Dim vsoShp As Visio.Shape
   
    For i = 1 To ActiveWindow.Windows.Count
    If ActiveWindow.Windows(i).Type = visDockedStencilBuiltIn Then
        If ActiveWindow.Windows(i).Document.Name = "DBCROW_U.vssx" Then
            Set vsoDoc = ActiveWindow.Windows(i).Document
            Debug.Print vsoDoc.Name
            Set vsoShp = ActivePage.Drop(vsoDoc.Masters.ItemU("Entity"), 4, 4) ', Application.ActiveWindow.Selection
        End If
    End If
Next
End Sub


Wapperdude
Visio 2019 Pro

wapperdude

Well, I found code that's more direct, in a link that I referenced in a different post of mine.  Here is the adapted code:


Sub FindStencilDropShp2()
' A more direct approach to getting a known stencil and fetching master shape for dropping
' Adaptation of https://code.msdn.microsoft.com/windowsdesktop/Visio-2010-Add-Containers-e8f8daf2
' Wapperdude, 1/26/2019
'
    Dim vsoSten As Visio.Document
    Dim stnName As String
    Dim vsoShp As Visio.Shape
   
    stnName = "DBCROW_U.vssx"
    Set vsoSten = Visio.Documents.OpenEx(stnName, visOpenDocked)
    Set vsoShp = ActivePage.DropContainer(vsoSten.Masters.ItemU("Entity"), Nothing)
    vsoShp.Text = "My Dropped Container"
End Sub
Visio 2019 Pro

vojo

Is the idea something like
- I kind of know what shape I want (a name or a handle)
- script searches all stencils all shapes to find the shape and drop it

Otherwise, would the user have to know exactly what he is looking for???

I am just confused about the intent here.
Naively, smells like the same reason the world came up with filesystems, directories, etc.
(unfair to have user memorize the name of a billion objects).

Maybe some sort of look up front end
- menu with 3-5 parameters
- then search across all directories
- 1 match, drop it....3 matches, maybe a list of possibles
- Trick would be shapes would need some user cells to define key words
  (like today where some shapes have "user.version = visio 15"

or

Maybe define attributes to the drawing at creation time (probably easier to tailor the drawing than all shapes)
- at creation time, specify attributes (wiring diagram or org chart or datacenter topology)
- place in page user cells
- you script uses those to tailor the search or selection 

Don't get me wrong, it would be interesting to have some sort of "global flat DB of shapes" appearance to user.   Just need to crack the "how user identifies what he wants" problem

I have always thought google would be more useful if user to could specify some context
(SAS give storage protocol stuff as well as statistical analysis info for the SAS company as well as .....)

wapperdude

The goal was not so noble.  It was an exercise in dropping a specific container onto the drawing.  It wasn't about searching for a container.  And it's how to automate just  the steps of placing a given container on a drawing.  A code snippet, building block.

Applications:  Useful if you're dropping many of the same container.  Or, perhaps, you have an Excel file with a list of items, specific items, and you want populate a drawing...plus, said items may have many specified unique, pre-defined data entries that must be filled in.  A time consuming chore in Visio, but readily automated with info stored in a database (Excel or whatever).

It's not a search algorithm.  (Visio has a rudimentary shape searching facility.) 

Yeah, should've indicated that with original posting.   ???
Visio 2019 Pro