Visio Guy

Visio Discussions => Programming & Code => Topic started by: kiler40 on February 09, 2015, 09:58:22 AM

Title: Draw a shape around selection
Post by: kiler40 on February 09, 2015, 09:58:22 AM
Hello All,
I have a question if is possible to draw a shape around selection. Something like outline.
I use the free-form tool to create this shape. But i was wondering if anyone have an idea for faster drawing.

For Sure it is impossible for me to do it  :-[



Title: Re: Draw a shape around selection
Post by: Visio Guy on February 09, 2015, 10:01:04 AM
Hi Kiler,

I think you want to do this with code...

This is a start: with your line selected, try:

Visio.ActiveWindow.Selection.Offset(0.125)

where 0.125 is inches, (1in = 25.4 mm)

A place to start, anyway!
Title: Re: Draw a shape around selection
Post by: kiler40 on February 09, 2015, 10:37:59 AM
Ok. This is a interesting start :)
but how to close these lines as a shape.
Another issue. if it is a closed shape (circle, square, etc.) it creates 2 more shapes on outside, one inside.

Little more help pls :)
Title: Re: Draw a shape around selection
Post by: Visio Guy on February 09, 2015, 11:09:16 AM
Yes, you will get two shapes. You can find these using Visio.ActivePage.Shapes( Visio.ActivePage.Shapes.Count ), and Count - 1.

I don't have the complete solution, I am just giving hints that make sense. I've got other things to do!
Title: Re: Draw a shape around selection
Post by: Visio Guy on February 09, 2015, 11:27:16 AM
If shapes aren't closed, you should be able to get the endpoints and draw lines between them, then Fragment the whole thing to create a shape (or draw a polyline yourself)
Title: Re: Draw a shape around selection
Post by: kiler40 on February 09, 2015, 11:35:21 AM
I`m not so good yet in coding. i`m really a basic user.
So this is too much for me.  :-[
Title: Re: Draw a shape around selection
Post by: Visio Guy on February 09, 2015, 11:41:44 AM
Maybe some of the other guys have time to help! :)
Title: Re: Draw a shape around selection
Post by: wapperdude on February 09, 2015, 07:54:28 PM
Do you need an outline, or could highlighting suffice, .i.e.,  change linecolor, lineweight?

Wapperdude
Title: Re: Draw a shape around selection
Post by: kiler40 on February 09, 2015, 08:21:29 PM
Outline for sure ... :/ line color or weight i can manage to do by my self.
Title: Re: Draw a shape around selection
Post by: Yacine on February 09, 2015, 08:26:41 PM
Hi Andrei,
,,the Master" gave you some serious words, about asking too much.
And whilst agreeing with him, I do confess, that your specific problems are always (often) so challenging and interesting, that I find myself working them out for you.
Guy! You need to get involved and learn to code!
This is the very last time I do this for you! Seriously! Get some VBA courses!

This said, here's what I worked out.
For requests like yours, one would try out the steps to get the result by different shape operations on the drawing itself.
Once this done, one would record a macro and repeat these operations.
The so recorded macro will then need to be cleaned from absolute references. There's some research work involved to get the right routines, working with the right parameters.
And the most important thing in this case, would be to have control over the shapes involved.
A good place would be a separate window, where only the specific shapes are involved.
I did chose a master in the document stencil for this task. I do create a new one, populate it with a copy of the shapes in the selection, then do all the join, segment and fragment operations on it.
After finishing these operations I delete the master and paste the result in the drawing.
My work does not consider the position to paste the outline in. You need to center the view on the selection first. That's however a feature you can (should) add.
Title: Re: Draw a shape around selection
Post by: Visio Guy on February 09, 2015, 11:14:38 PM
Laughing my head off!
Title: Re: Draw a shape around selection
Post by: Nikolay on February 10, 2015, 12:55:38 AM
You could also try "glow" effect.. (Visio 2013) has similar look:
Title: Re: Draw a shape around selection
Post by: Yacine on February 10, 2015, 03:24:02 AM
@Nikolay,
I like your LICEcap very much, thanks for the info.


@Master,  8)
Title: Re: Draw a shape around selection
Post by: wapperdude on February 10, 2015, 04:13:50 AM
I want to play too!  Can I???

Meanwhile, back to the freeform tool.  Not sure what the fuss is about.  Seems like the obvious, straight-forward solution.  The outline can be made very quickly with a little initial effort. 

Not sure where it is in the newer, "sophisticated" versions of Visio, but in V2007 go to menu bar>tools>options.  Click on Advanced tab.  Under Freeform drawing, set Precision to max Looseness, i.e., Value =10.  Then set smoothing to something like a value of 7.  Click OK.

Now draw your outline.  Should be a nice, smooth contour.  Take you all of 30 seconds or less.   If this meets your needs, thank Jojo, ooops, that's from a Beatle's song, thank Vojo.   As I recall, he pointed this out sometime ago, in a post, far, far away.

Wapperdude.

@Yacine:  "Master Yoda" said I could play.   :o   LOL
Title: Re: Draw a shape around selection
Post by: Yacine on February 10, 2015, 04:43:36 AM
 ;D Nice. Both the Yoda and the freeform looseness.


To understand Kiler's problem, you need to remember that he makes those big car electrification diagrams with dozens (hundreds?) of shapes (see the upload picture in his first post)
Having a tool, that follows smoothly the outline of a shapes selection to highlight groups is certainly easier to handle than the freeform tool ... and looks better on professional documents.
Title: Re: Draw a shape around selection
Post by: kiler40 on February 10, 2015, 07:26:42 AM
Thanks for the replays to all,
@ Nikolay - this looks awesome and simple, but i`m limited with visio 2010.
@  wapperdude - i have found this option through this forum i think. and i use it. i have also found that if you make one small line, then continue from the same place where stop, it is much much easier to close the line when finished "drawing".

Yacine,
I really appreciate ALL your help. The help of all people in this forum actually.
It is the bes place for visio Q&A for both prof. and beginners.

Because of this forum i have made lot of little helpers for me (and my colleagues - whoever wants to use them) for use at work.
Everything i ask here i try to remember and use in different cases. I also try to improvemyself. I have made some things without other help (and i`m pretty proud with myself  ::) ) I must say that one year ago i didn`t know how to open the visual basic editor...
Now i`m connecting excel, changing excel from visio, importing data, linking to shape and so one all with code. All with the help of you.
Learning coding for a person that have no idea what is this is a little bit tricky.  :)
I`ll take your constructive critics and see if i can finish the hint you gave me in the stencil.

The thing is that the more i go deep the more questions pops out :)

Yes i do complex "diagrams". But actually this is a work instruction for operators that produce a product. The more simple and yet detailed, the more better to understand.
But more complex and time consuming to prepare... So i`m looking for creating a helpers in my everyday job. :)

I`ll do my best to minimize the stupidity of the questions and the things i ask, but please don`t give up one me yet ! :)

Andrei.
Title: Re: Draw a shape around selection
Post by: wapperdude on February 10, 2015, 07:48:57 AM
Hi Andrei...

After Yacine's memory refresher, I see where automating the "outliner" would be very beneficial.  Must admit, that I'm surprised that you need to use that technique rather than just highlighting a desired or selected path.  It would seem that path highlighting would be preferable.  Mostly because it's less cluttered.  Pretty simple to make the selected path "pop out" and be readily visible without having to lasso it.

I guess what would be really cool would be to have the equivalent of a highlighter, just trace along the path with the cursor and highlight it as the cursor moves.  Not sure Visio can do that.

Don't know if this helps or not, but, say somehow you select the objects you want focus on.  A pseudo-glow approach that Nikolay showed, would be to:
  1.)  Duplicate the shapes
  2.)  Then operations>combine
  3.)  Change line width to something like 20 - 40 pt, and change color to yellow or whatever is desired.
  4.)  Send to back and reposition under the original shapes.

That gives you a "fake" highlighting.  Probably could automate with code.

Wapperdude
Title: Re: Draw a shape around selection
Post by: kiler40 on February 10, 2015, 08:10:13 AM
Hi Wapperdude,

I can do this yes. and i can do it automated with code also. The issue is that there is a standard that uses this kind of visual representation. Outlining.
If it was not that i would not bother any of you and create this topic :)

Andrei
Title: Re: Draw a shape around selection
Post by: Visio Guy on February 10, 2015, 12:52:09 PM
Really impressive thread and solutions, people! Thanks for making this an interesting place to be!
Title: Re: Draw a shape around selection
Post by: wapperdude on February 10, 2015, 03:43:09 PM
Ah!!! The missing element....a standard! 
Title: Re: Draw a shape around selection
Post by: kiler40 on February 10, 2015, 03:45:10 PM
Is this bad ? Thick red line represents one. Thick blue - another. Yellow outline - third :)
Title: Re: Draw a shape around selection
Post by: wapperdude on February 10, 2015, 03:53:00 PM
Was there supposed to be an attachment?
Title: Re: Draw a shape around selection
Post by: kiler40 on February 10, 2015, 03:54:49 PM
Only a picture...
Title: Re: Draw a shape around selection
Post by: Yacine on February 10, 2015, 04:44:00 PM
Quote from: Visio Guy on February 09, 2015, 11:09:16 AM
Yes, you will get two shapes. You can find these using Visio.ActivePage.Shapes( Visio.ActivePage.Shapes.Count ), and Count - 1.

@Chris, Now that's an important hint. In the solution I worked out, you see that I create a new master, copy the selection in this master, make the offset, ... and so on, only to make sure, to know the result (the shapes) of the offset operation.
I was thinking that the order of the shapes was related some how to their IDs. But I checked it and indeed, the order in a for each loop corresponds to the order in which the shapes were created. Thank you.
I asked this very same question here (http://visguy.com/vgforum/index.php?topic=5984.0), but the solutions were not as easy as your's.
Title: Re: Draw a shape around selection
Post by: wapperdude on February 10, 2015, 05:11:07 PM
A new picture? ... there was no picture attached.
Title: Re: Draw a shape around selection
Post by: Yacine on February 10, 2015, 05:48:45 PM
All this said and tweaked and tried out, ...  but still thoughts about the problem.
When you wrote "But actually this is a work instruction for operators that produce a product. The more simple and yet detailed, the more better to understand.
But more complex and time consuming to prepare... So i`m looking for creating a helpers in my everyday job
",
I didn't realize it immediately, but this actually applies to my job too.
I do P&IDs – a lot of them – and after having drawn all the stuff that describes the system, I need to add a description about the intention of adding the one or the other feature. I need to do this for the people in the shop assembling the machines, for the programmers (FDS Functional Design Specifications), the commissioners, and so on.
What I came up with, was a tool to highlight a portion of the whole circuit, combined with a snapshot tool to get an image of the so highlighted region. This tool links the drawing to an Access DB, where the textual instructions, as well as the images are stored. I made already a post about the snapshot tool, to be found here: http://visguy.com/vgforum/index.php?topic=4773.0 (http://visguy.com/vgforum/index.php?topic=4773.0)
Having all the highlighting and snapshot instructions in digital form, later editing is not only easy, but "possible". (Think about all the highlightings when done manually on a BIG drawing).
Now, please don't ask me to upload the tool. It is not ready. (I need someone to kick me in the ass to finish it, as most of my colleagues don't understand the benefits of such a tool – and I'm a "praise" worker.
This is just to give you some ideas, may be you can achieve to kick me in the ass!
Cheers,
Yacine
Title: Re: Draw a shape around selection
Post by: kiler40 on February 12, 2015, 07:09:33 AM

BTW the idea is the same. But i`m using Excel not  Access DB. There is a big file with all operations per operator no matter what part number he is producing. And since the information become too much, we have (I have) created an excel file that transforms everything and puts it into correct form to be imported into Visio..

Put some guiding table with information, draw the part of the product where the operator is working, create color schemes for what exactly he is doing in the colored area and last one (the one this topic is :) ) is finishing details somewhere in the product.
So far everything is more or less automated. :) Almost everything is thanks to this forum ;)

" as most of my colleagues don't understand the benefits of such a tool"
Same here... But from some time (one month and something) someone found out that this can be very helpful and now i`m under pressure to finish it (and of course not a single "good job" or "continue the good work" was said  ;D )

So now i`m in a fight with "CenterViewOnShape" to finish Yacine proposal :)

Andrei
Title: Re: Draw a shape around selection
Post by: Yacine on February 12, 2015, 03:00:18 PM
Have a look at this topic http://visguy.com/vgforum/index.php?topic=6144.msg25319#msg25319 (http://visguy.com/vgforum/index.php?topic=6144.msg25319#msg25319)
Title: Re: Draw a shape around selection
Post by: kiler40 on February 12, 2015, 03:07:09 PM
i have started from there. (no way to know about this function :) )
But maybe i`m wrong maybe i do something wrong but this CenterViewOnShape is working for only one shape ?



Andrei
Title: Re: Draw a shape around selection
Post by: Yacine on February 12, 2015, 03:21:25 PM
I haven't tried it, but since you center the view on the outline, there shouldn't be any difficulty.
Title: Re: Draw a shape around selection
Post by: wapperdude on February 12, 2015, 03:45:29 PM
CenterYiewOnShape:  This method introduced with V2010.
Title: Re: Draw a shape around selection
Post by: Yacine on February 12, 2015, 04:11:50 PM
Thanks, Wayne.
In this case my own submission in this post can be used. I works with V2007.
Title: Re: Draw a shape around selection
Post by: JuneTheSecond on February 13, 2015, 04:26:33 AM
Is it too late for " Draw a shape around selection"?

Selection.DrawRegion may be a help.



Option Explicit

Sub test()
    Dim shp As Visio.Shape
   
    Set shp = ActiveWindow.Selection.DrawRegion(0.01, visDrawRegionIncludeHidden)
    shp.Cells("LineColor").Formula = "RGB(145,205,220)"
    shp.Cells("LineWeight").Formula = "30 pt"
    shp.SendToBack
End Sub

Title: Re: Draw a shape around selection
Post by: kiler40 on February 13, 2015, 08:01:24 AM
JuneTheSecond,
This is quite amazing :)

But i didn`t give up on CenterViewOnShape :)
Since i didn`t understood how to use it on a multiple selection i went to a stupid (maybe) but effective idea

If ActiveWindow.Selection.Count > 1 Then
        ActiveWindow.Selection.Group
        ActiveWindow.CenterViewOnShape ActiveWindow.Selection(1), visCenterViewDefault
        ActiveWindow.Selection.Ungroup
    Else
        ActiveWindow.CenterViewOnShape ActiveWindow.Selection(1), visCenterViewDefault
    End If

8)
and after that i continue with the proposal given from Yacine. The benefit there is that creates a shape that can have both fill color and line color. And  DrawRegion is giving only line ? (maybe i`m speaking stupid now...)

Andrei