Author Topic: Guarded object within a group still grows  (Read 3340 times)

0 Members and 1 Guest are viewing this topic.

maclarkson

  • Jr. Member
  • **
  • Posts: 66
Re: Guarded object within a group still grows
« Reply #30 on: September 18, 2019, 07:22:30 AM »
I just tried to add my container on\off button altering your code like so and it, of course, failed for me  :'( what am I doing wrong?

Code
Sub Macro1()
'Macro loops thru all shapes.  Finds shapes that have a second (Icon) shape placed
'within border using Spatial Neighbor method.  Creates necessary grouping.  Locks position and size of icon, adds
'Action menu item to show/hide the icon.
'It assumes all shapes have been properly built and placed.
'The physical placement of the icon has the offset hardcoded.
'There is no error checking.

    Dim intTolerance As Integer
    Dim vsoReturnedSelection As Visio.Selection
    Dim strSpatialRelation As String
    Dim intSpatialRelation As VisSpatialRelationCodes
    Dim vMain As Visio.Shape
    Dim vIcon As Variant
   
    strSpatialRelation = ""
    intTolerance = 0.05
    intSpatialRelation = visSpatialContain
   
    For Each vMain In ActivePage.Shapes             'This construct needs to manual selecction
    'check to see if shape has containing neighbor.  If so select it.
        ActiveWindow.DeselectAll
        On Error Resume Next
        Set vsoReturnedSelection = vMain.SpatialNeighbors(intSpatialRelation, intTolerance, 0)
        If vsoReturnedSelection.Count = 1 Then
            Debug.Print "Main shape:  ", vMain.Name
            ActiveWindow.Select vMain, visSelect
'            setPgZm vMain          'Handy subroutine.  Using F8 to step code.  Takes windo to active vMain

'    Add vMain Actions here
            If Not vMain.CellExistsU("Actions.Icon", False) Then
                vMain.AddSection visSectionAction
                vMain.AddRow visSectionAction, visRowLast, visTagDefault
                vMain.CellsSRC(visSectionAction, 0, visActionMenu).RowNameU = "Icon"
                vMain.CellsSRC(visSectionAction, 0, visActionAction).FormulaU = "SETF(GETREF(Actions.Icon.Checked),NOT(Actions.Icon.Checked))"
                vMain.CellsSRC(visSectionAction, 0, visActionMenu).FormulaU = "IF(Actions.Icon.Checked,""Show Icon"",""Hide Icon"")"
           End If
               
      'Add msvStrcutureType container
                If Not vMain.CellExistsU("User.Container", False) Then
                vMain.AddSection visSectionUser
                vMain.AddRow visSectionUser, visRowLast, visTagDefault
                vMain.CellsSRC(visSectionUser, 0, visUserValue).RowNameU = "msvStructureType"
                vMain.CellsSRC(visSectionUser, 0, visUserValue).FormulaU = "SETF(GETREF(User.msvStructureType),0)"
               End If
       'Add container on action
                If Not vMain.CellExistsU("Action.ContainerOn", False) Then
                vMain.AddRow visSectionAction, visRowLast, visTagDefault
                vMain.CellsSRC(visSectionAction, 0, visActionMenu).RowNameU = "ContainerOn"
                vMain.CellsSRC(visSectionAction, 0, visActionAction).FormulaU = "SETF(GetRef(User.msvStructureType),""Container"")&SETF(GetRef(Actions.ContainerOff),""Container Off"")&SETF(GetRef(Actions.ContainerOn),"""")"
                vMain.CellsSRC(visSectionAction, 0, visActionMenu).FormulaU = "Container Off"
                End If
      'Add Container Off Action
                If Not vMain.CellExistsU("Action.ContainerOff", False) Then
                vMain.AddRow visSectionAction, visRowLast, visTagDefault
                vMain.CellsSRC(visSectionAction, 0, visActionMenu).RowNameU = "ContainerOff"
                vMain.CellsSRC(visSectionAction, 0, visActionAction).FormulaU = "SETF(GetRef(User.msvStructureType),"""")&SETF(GetRef(Actions.ContainerOn),""Container On"")&SETF(GetRef(Actions.ContainerOff),"""")"
                vMain.CellsSRC(visSectionAction, 0, visActionMenu).FormulaU = ""
               
            End If

' Convert vMain to group object
            vMain.ConvertToGroup
            vMain.CellsU("DisplayMode").Formula = "1"
            For Each vNbr In vsoReturnedSelection
                Set vIcon = vNbr
                ActiveWindow.Select vIcon, visSelect
                Debug.Print "Icon:  ", vIcon.Name
            Next
               
            ActiveWindow.Selection.AddToGroup       'Add vIcon to the group
       
' Lock vIcon size and position
            vIcon.CellsU("Width").Formula = vIcon.CellsU("Width").ResultStr(visNone)
            vIcon.CellsU("Height").Formula = vIcon.CellsU("Height").ResultStr(visNone)
            vIcon.CellsU("PinX").FormulaU = "LocPinX + 0.03125"
            vIcon.CellsU("PinY").FormulaU = vMain & "!Height*1-(Height-LocPinY)-0.03125"
           
' Iterate thru subshapes of vIcon
            For Each shp In vIcon.Shapes    'goes thru the Icon group shape and modifies the subshapes
                Debug.Print shp.Name        'name of member subshape
                shp.CellsU("Geometry1.NoShow").Formula = vMain & "!Actions.Icon.Checked"
            Next
        End If
    Next

   
End Sub
Sub setPgZm(vsoShp As Shape)

    Dim winMag As Double
    Dim shpWid As Double
    Dim shpHt As Double
    Dim pgWid As Double
    Dim pgHt As Double
    Dim widRatio As Double
    Dim htRatio As Double
   
'Use shape based upon selection:
    Application.Settings.CenterSelectionOnZoom = True
   
'    Set vsoShp = ActiveWindow.Selection(1)
   
    pgWid = ActivePage.PageSheet.CellsU("PageHeight").Result(inch)
    shpWid = vsoShp.CellsU("Width").Result(inch)
    widRatio = pgWid / shpWid
   
    pgHt = ActivePage.PageSheet.CellsU("PageWidth").Result(inch)
    shpHt = vsoShp.CellsU("Height").Result(inch)
    htRatio = pgHt / shpHt
   
    If widRatio < htRatio Then
        winMag = widRatio * 0.5
    Else
        winMag = htRatio * 0.5
    End If
   
    ActiveWindow.Zoom = winMag
    Application.Settings.CenterSelectionOnZoom = False

End Sub


wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3794
  • Ideas Visio-lized into solutions
Re: Guarded object within a group still grows
« Reply #31 on: September 18, 2019, 08:19:47 AM »
Not really.  Never done that.  Start a new thread...make the title obvious.
Visio 2019 Pro

maclarkson

  • Jr. Member
  • **
  • Posts: 66
Re: Guarded object within a group still grows
« Reply #32 on: September 18, 2019, 06:53:15 PM »
Would it be possible to create a whole new discussion topic called the database project rather than a single thread?

I would like to ultimately create a plugin that allows you to connect to a database. The idea I have a really simple one where you can create or use existing shapes from the database to create diagrams. All of the connectors are also registered in the database. its only two tables.

The question the solution is primarily answering is what is, I have created x number of diagrams what is connected to what?

Imagine its uses:
Network diagrams
CMDBs
Architectural diagrams
Process flow diagrams
Integration diagrams
TOGAF diagrams

People would be able to use the data to discover the implications of changing anything.


Nikolay

  • Hero Member
  • *****
  • Posts: 931
    • UnmanagedVisio
Re: Guarded object within a group still grows
« Reply #33 on: September 19, 2019, 12:21:29 AM »
Visio (now) has "Data Visualizer" for drawing diagrams from data.
https://support.office.com/en-us/article/create-a-data-visualizer-diagram-17211b46-d144-4ca2-9ea7-b0f48f0ae0a6

It works mostly for specific diagram types (flowcharts), but it's built-in, user-friendly, well-documented, and customizable (e.g. allows custom shapes for example).

In general, the implication of generating diagrams is basically the layout; how do you arrange shapes from your database on the diagram properly, so that it looks nice, and how do you update the diagram when you change both data in the database and on the diagram (i.e. how to merge "manual" changes with "database" ones)

There were multiple attempts in the past to create such an application that will do the work automatically based on data on the basis of Visio, none of them really worked for a wider audience, as far as I know (i.e. they worked basically for the project, for which they were created, or only for the person, who created them). But maybe you'll have more luck - you never know. Some of them were based on OrgChart wizard (since it has automatic layout feature) but it's quite a rigid solution that does not assume user customization, and in addition, it has issues with updating diagram (and sorting). Also, I remember some swiss guy tried to build a solution based on GraphViz engine. Unfortunately was not trivial to install and use. Another approach was to use MSAGL (Microsoft Automatic Graph Layout library), SaveenR was building and presenting a PowerShell module based on this idea.
The idea of automatic generation of diagrams from data is as old as Visio itself I suppose  :)
« Last Edit: September 19, 2019, 12:49:54 AM by Nikolay »

maclarkson

  • Jr. Member
  • **
  • Posts: 66
Re: Guarded object within a group still grows
« Reply #34 on: September 19, 2019, 12:52:51 AM »
Orbus iServer, and ITP commerce have both achieved this. but the price of these product is simply ridiculous $1600 a user per seat!! and all it does is exactly what I explained.

I tried data visualizer and this is pretty rubbish in that its exactly as you called it. it only works with two diagram types. Its also is not relational with its connections. It put the relationships into a single cell. If I got this to work there would be every architect and their dog after this.

Nikolay

  • Hero Member
  • *****
  • Posts: 931
    • UnmanagedVisio
Re: Guarded object within a group still grows
« Reply #35 on: September 19, 2019, 12:57:14 AM »
Oh. If you could manage to build a product that would do the same as Orbus or ITP commerce, you probably would be able to expel those greedy bastards from the market  ;D

maclarkson

  • Jr. Member
  • **
  • Posts: 66
Re: Guarded object within a group still grows
« Reply #36 on: September 19, 2019, 01:02:06 AM »
Ye man, But that's not what I am try to do. If I was to look at it from a roadmap perspective. give the product free and then charge for specialised templates support and out of the box reports. That's were we'd make some money. I have achieved the above to some effect using your back sync product, but it would awesome if I could create something a little more robust.

By the way do you know where I am going wrong in my code above?

Nikolay

  • Hero Member
  • *****
  • Posts: 931
    • UnmanagedVisio
Re: Guarded object within a group still grows
« Reply #37 on: September 19, 2019, 01:08:37 AM »
Sorry, it's a bit specific... maybe you have a diagram this could run against - that could help I suppose
The code has a comment at the top saying that it is supposed to be run on a prepared diagram ("the shapes should be properly built and placed"?)

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3794
  • Ideas Visio-lized into solutions
Re: Guarded object within a group still grows
« Reply #38 on: September 19, 2019, 01:25:58 AM »
@Nikolay:  LOL.  Yes.  It's specific.  See reply #26 for file that it was based on.  Other than the lines about the container, the code was my solution.  So, it assumes that the "Main" shape is just an ordinary 2D shape.  Then, the "Icon" shape is a grouped shape, and placed at the ~ desired location within the Main shape.  It's strictly based upon the physical layout.  Uses spacial neighbors to locate the Icon associated with the Main shape.  It then converts the Main shape to a group and adds the Icon to the new group.  There were some advantages to this method versus the typical select shapes and group.  Along the way it locks the Icon position and size.  Adds Action item to group to show/hide Icon visibility by write formula to each Icon subshape's Geometry1.NoShow cell.

Haven't looked at the container code lines yet.
Visio 2019 Pro

Paul Herber

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2891
    • Paul Herber's website
Re: Guarded object within a group still grows
« Reply #39 on: September 19, 2019, 02:59:26 AM »
Would it be possible to create a whole new discussion topic called the database project rather than a single thread?


There's a Database Diagramming section ripe and ready for any new topic you wich to create!
Electronic and Electrical engineering, business and software stencils and applications for Visio -

https://www.paulherber.co.uk/

maclarkson

  • Jr. Member
  • **
  • Posts: 66
Re: Guarded object within a group still grows
« Reply #40 on: September 19, 2019, 11:16:26 PM »
Hi guys,

I have created another topic under database diagraming

http://visguy.com/vgforum/index.php?topic=8924.0

And have added Yasine's database as a first release. I will probably have a go over the weekend to create a second release. and make sure the database is a web based one. See you all there.