Best Ways to Hide Shapes on a page?

Started by bwharrington, July 15, 2019, 07:52:35 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

bwharrington

There a couple known ways that I am aware however I am inquiring if there are better ways. For me I just need to hide the relationships at will.

Option A - The first way I am aware of is to assign shapes to a layer then hide the layer.

Option B - The second way I know of it to usea formula. I have it in a method like this,

public static void SetLineVisible(this Visio.Shape shape, bool visible)
{
            shape.Cells["Geometry1.NoLine"].FormulaU = (!visible).ToString();
}

The issue with Option B is that shapes are still selectable on the page. They are hidden but can be found an altered.

Anyone aware of other ways this could be done? I'm simply looking for the best solution.

Paul Herber

Setting the line to be invisible would also need to be done for all geometry sections and for all sub-shapes within a grouped shape. But then fill colours are still visible! And text!

You could set the shape select protection, but you also set the document shapes protection.

These hidden shapes can still be seen within the drawing explorer window, though they will be greyed-out. Anyone in the know can then unprotect the document.

Electronic and Electrical engineering, business and software stencils for Visio -

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

vojo

Pedantic, but I have on occasion set the height and width = 0mm.   to hide shape or group.
Now you have to be careful since you need a way to get it back  (lasso the region or some trigger at parent or page level).

Width could be    Width = guard(if <flag>, 30mm, 0mm))

wapperdude

That's about it...3 techniques:
1) hide via setting disabilities to zero
2) assign to layer and hide
3) set size to zero.

Old topic, see this, some additional details provided:  http://visguy.com/vgforum/index.php?topic=5740.msg22885#msg22885
Visio 2019 Pro

Hey Ken

Folks:

   Pardon me if I sound contrary, but there is a fourth way.  Depending on what you want to be available to the user, you could always just make everything transparent.  Of course I had to go forth and play around with it, and in a few minutes came up with the following:



Sub MakeAllVanish()

Dim I As Integer
Dim J As Integer

For I = 1 To ActivePage.Shapes.Count
    With ActivePage.Shapes.Item(I)
        MakeOneVanish ActivePage.Shapes.Item(I)
        For J = 1 To .Shapes.Count
            MakeOneVanish .Shapes(J)
            Next J
        End With
    Next I

End Sub


Sub MakeOneVanish(TheShape As Shape)

Dim J As Integer

With TheShape
    .Cells("LineColorTrans").Formula = "=100%"
    .Cells("FillForegndTrans").Formula = "=100%"
    .Cells("FillBkgndTrans").Formula = "=100%"
    .Cells("Char.ColorTrans").Formula = "=100%"
    .Cells("TextBkgndTrans").Formula = "=100%"
    .Cells("Transparency").Formula = "=100%"
    For J = 1 To .Shapes.Count
        MakeOneVanish .Shapes(J)
        Next J
    End With
   
End Sub



   I tried it against several complex drawings I had lying about, and it worked just fine, even for grouped-grouped shapes, except for one thing: It does not handle multiple Char rows.  Oops.  I'll leave that as an exercise for the student.

   Thanks for the fun diversion,

   - Ken




Ken V. Krawchuk
Author
No Dogs on Mars - A Starship Story
http://astarshipstory.com

wapperdude

#5
Gotta have some fun here  :o ;)...this only counts as 3.5, well, with  the effort to do this, 3.75!  Why???  Well, it's just automating the 1st point, i.e., hiding.  Setting transparencies = 100%, I considered as hiding.  Doing this with code = +1/2 pt.  Making this recursive so it goes thru all shapes = +1/4 point.

So, using your code as starting point, = -1 full point for me for being lazy, it is possible to simplify somewhat and takes care of the multiple character rows.  However, as shown, it only works for single geometry sections.  If the shape has multiple geometry sections, then, some additional coding is needed.  Finally, added select / delete protection.

As Paul indicates, the shapes are still listed and selectable in the DEW window. 

BTW, nice to see you back Ken.


Sub MakeAllVanish()
    Dim I As Integer
    Dim J As Integer
   
    For I = 1 To ActivePage.Shapes.Count
        With ActivePage.Shapes.Item(I)
            MakeOneVanish ActivePage.Shapes.Item(I)
            For J = 1 To .Shapes.Count
                MakeOneVanish .Shapes(J)
            Next J
        End With
    Next I
End Sub
Sub MakeOneVanish(TheShape As Shape)
    Dim J As Integer
   
    With TheShape
        .Cells("HideText").Formula = "1"
        .Cells("Geometry1.NoShow").Formula = "1" 'need more code for multiple geo sections
        .Cells("LockDelete").Formula = "1"
        .Cells("LockSelect").Formula = "1"
        For J = 1 To .Shapes.Count
            MakeOneVanish .Shapes(J)
        Next J
    End With
End Sub
Visio 2019 Pro

Hey Ken

Mr. Wd.

   Thanks for the welcome back, but I never went away.  Granted, it's been months since I last posted; but I'm here most every weekday.  Checking this forum is part of my standard morning routine.  I've learned so many random items here that daily visits have long since proved their worth.  And the people here are pretty friendly, unlike other (cough, cough, St***Ov******, cough) forums.

   I thought we established long ago that laziness was a virtue.  So change your -1 to a +1, please.  However, I'd take several points off for adding the complexity of diddling the geometry.  Why loop through multiple sections when a single access to the line and fill transparency cells has the same effect?  It's the same idea as your idea of using HideText rather than looping through Char rows (a good suggestion).  I'd skip the loops everywhere in favor of the single cell approach.  A lazy man's approach, if there ever was one.

   There's also one other item neither of us mentioned, and that's the handles.  Run our macro and yes, the shapes disappear, but then do a Ctrl-A and you can see all sorts of handles and such.  Setting NoObjHandles, NoCtlHandles, and NoAlignBox to 1 clears up the last traces of any shape's existence.

   Taking a giant step back and looking at the original question, I'd say the optimally lazy solution would be to combine our non-loopy ways to hide things, plus your protection against selecting or deleting, plus hiding the handles, and that should do it.  Except that once you do it, you also need a way to UNdo it.  See some suggested code below (which uses a trick I learned here).

   As a whimsical aside, the solution we've been discussing has recursion to take care of grouped-grouped shapes.  When my kids were small and they asked for a bedtime story, I told them what I called "The Recursive Story".  It goes like this...

   Once upon a time there was a little girl who said, "Daddy, tell me a story."  And he said, "OK.  Here you go: Once upon a time there was a little girl who said, "Daddy, tell me a story."  And he said, "OK.  Here you go: Once upon a time there was a little girl who said, "Daddy, tell me a story."  And he said, "OK.  Here you go..."  And so on.

   Needless to say they caught on pretty quickly, and cries of "No Recursive Story!" could be heard echoing through the house.  And I'd reply, "And the Dad promised never to tell the recursive story ever again, and the little girl lived happily ever after.  And the Dad promised never to tell the recursive story ever again, and the little girl lived happily ever after.  And the Dad promised never to tell the recursive story ever again, and the little girl lived happily ever after..." until I closed off all the recursion. 

   Bottom line: How many three-year-olds do you know who understand recursion?  And can provide a reasonable example???

   As always, thanks for the diversion.  Gave me something fun to do during an otherwise-dull conference call.

   - Ken





Sub MakeAllVanish()

Dim I As Integer
Dim J As Integer

For I = 1 To ActivePage.Shapes.Count
    With ActivePage.Shapes.Item(I)
        MakeOneVanish ActivePage.Shapes.Item(I)
        For J = 1 To .Shapes.Count
            MakeOneVanish .Shapes(J)
            Next J
        End With
    Next I

End Sub


Sub MakeOneVanish(TheShape As Shape)

Dim J As Integer

With TheShape
    .Cells("LineColorTrans").Formula = "=100%"
    .Cells("FillForegndTrans").Formula = "=100%"
    .Cells("FillBkgndTrans").Formula = "=100%"
    .Cells("TextBkgndTrans").Formula = "=100%"
    .Cells("Transparency").Formula = "=100%"
    .Cells("HideText").Formula = "1"
    .Cells("LockDelete").FormulaForce = "1"
    .Cells("LockSelect").Formula = "1"
    .Cells("NoObjHandles").Formula = "1"
    .Cells("NoCtlHandles").Formula = "1"
    .Cells("NoAlignBox").Formula = "1"
    For J = 1 To .Shapes.Count
        MakeOneVanish .Shapes(J)
        Next J
    End With
   
End Sub


Sub MakeAllReappear()

Dim I As Integer
Dim J As Integer

For I = 1 To ActivePage.Shapes.Count
    With ActivePage.Shapes.Item(I)
        MakeOneReappear ActivePage.Shapes.Item(I)
        For J = 1 To .Shapes.Count
            MakeOneReappear .Shapes(J)
            Next J
        End With
    Next I

End Sub


Sub MakeOneReappear(TheShape As Shape)

Dim J As Integer

With TheShape
    .Cells("LineColorTrans").Formula = "="
    .Cells("FillForegndTrans").Formula = "="
    .Cells("FillBkgndTrans").Formula = "="
    .Cells("TextBkgndTrans").Formula = "="
    .Cells("Transparency").Formula = "="
    .Cells("HideText").Formula = "="
    .Cells("LockDelete").FormulaForce = "="
    .Cells("LockSelect").Formula = "="
    .Cells("NoObjHandles").Formula = "="
    .Cells("NoCtlHandles").Formula = "="
    .Cells("NoAlignBox").Formula = "="
    For J = 1 To .Shapes.Count
        MakeOneReappear .Shapes(J)
        Next J
    End With
   
End Sub


Ken V. Krawchuk
Author
No Dogs on Mars - A Starship Story
http://astarshipstory.com

vojo

all shapes hidden = rich drawing in a snow storm??   I guess its a matter of perspective  ;-) ;-)

wapperdude

@Hey Ken:  I've not heard that story before...before...before. 
  >> Yeah, I swapped multiple chars for multiple geos.
  >> Handles?  Handles???  We don't need no stinking handles.  I guess that was your point.  Good catch.
        ... and yes, if mine goes to that extreme, there needs to be a recovery route.

@Vojo:  😁😁😁. Hiding all.  What's the point?  That's easy enough modification, instead of looping thru all shapes on a page, just loop thru all shapes that are selected...so I left that part of code alone.

@bwharrington:  I think the point here is that you can get quite detailed in hiding shapes.  There is one other aspect, and maybe this is part of the driving factor...The shapes, though hidden, are still there.  So, some could place other shapes over the hidden ones.  That may or may not be OK.  But it could have implications with selection and shape movement/sizing...either accidentally or intentionally.
Visio 2019 Pro

vojo

apologies...trying to be sarcastic as in why would you want to hide ALL the shapes.
Now, I could see a "hide all but selected" option being useful...but not sure why "hide all shapes"

bwharrington

I'm currently on modeling software that allows users to import data objects from our CRM Cloud. We model these objects into two categories, Shapes and Connectors. Shapes represents just about anything you can think of and have properties. Connectors describe relationships between shapes.

Its not necessary that I need to hide ALL shapes but certain ones. Mainly connectors. In my case I want customers to be able to selected a shape and hide/show all incoming out outgoing connectors. Alternatively they can hide ALL connectors or Show them.

I've attached a simple drawing that may provide reference.


bwharrington

Quote from: wapperdude on July 17, 2019, 03:43:54 PM
@bwharrington:  I think the point here is that you can get quite detailed in hiding shapes.  There is one other aspect, and maybe this is part of the driving factor...The shapes, though hidden, are still there.  So, some could place other shapes over the hidden ones.  That may or may not be OK.  But it could have implications with selection and shape movement/sizing...either accidentally or intentionally.

You hit the nail on the head here. I've been doing some experiments trying to find the best way to hide or show shapes. Our original implementations just set the visibility properly on the shape itself. That's just OK. In small models that may work but some of our customers and my project manager thing its clunky and I would attend to agree because as you mentioned, they shapes are still there.

I knew about the layer method but before I set on this magic refactoring journey I wanted to get all opinions. Thank you so much for providing yours. I really appreciate it. 

wapperdude

#12
Interesting.  Here's a few more links that might be of interest...at least, provide some ideas. 
http://visguy.com/vgforum/index.php?topic=6373.msg26266#msg26266  This allows the user to select a shape, then see outgoing or incoming or both connections.  It can also provide the shortest path between two shapes.

http://visguy.com/vgforum/index.php?topic=5936.msg23931#msg23931  This focuses more on just shortest path.

miscellaneous connectivity ideas:
http://visguy.com/vgforum/index.php?topic=8701.msg38015#msg38015
http://visguy.com/vgforum/index.php?topic=8702.msg38020#msg38020

Visio 2019 Pro