Author Topic: Very simple mini shape explorer driven by VBA macro only  (Read 23533 times)

0 Members and 1 Guest are viewing this topic.

JuneTheSecond

  • Hero Member
  • *****
  • Posts: 1027
    • Visio Shapes, Stencils and Sample Drawings
Very simple mini shape explorer driven by VBA macro only
« on: August 12, 2010, 02:46:59 AM »
Here is a simple shape explorer.
It is driven by VBA macro and userform with textbox.
Tree view of the shapes on a page is written as text in textbox, but not uses TreeView control.
I fear that tree view is not visible in your Visio other than Japanese version, because I've used sepcial characters in the unicode characters to draw tree view.
When you click the shape name on the textbox, the specified shape is selected on the page, and is scrolled to the center of window.
It is all that this macro does, but for me making such a macro is good to study VBA programming.  ;) ;) ;)
Enable VBA macro and enjoy.
« Last Edit: August 13, 2010, 06:46:59 AM by JuneTheSecond »
Best Regards,

Junichi Yoda
http://june.minibird.jp/

Yacine

  • Hero Member
  • *****
  • Posts: 2991
Re: Very simple mini shape explorer driven by VBA macro only
« Reply #1 on: August 12, 2010, 03:06:17 AM »
Great work Yoda-san, I would just miss the docking window function.
Yacine

Visio Guy

  • Administrator
  • Hero Member
  • *****
  • Posts: 1735
  • Smart Graphics for Visual People...n' Stuff
    • Visio Guy
Re: Very simple mini shape explorer driven by VBA macro only
« Reply #2 on: August 12, 2010, 07:35:57 AM »
Excellent work, JTS!

Here's what it looks like on my system (Win 7 Pro 64 US English, Visio 2010 64 US English)

For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

Visio Guy

  • Administrator
  • Hero Member
  • *****
  • Posts: 1735
  • Smart Graphics for Visual People...n' Stuff
    • Visio Guy
Re: Very simple mini shape explorer driven by VBA macro only
« Reply #3 on: August 12, 2010, 07:37:34 AM »
By the way, this is a great download for new Visio developers that want to learn how to walk through objects in Visio, from Documents to Pages to Shapes to Subshapes.

Just look at the VBA inside of the Visio document to see how JuneTheSecond makes it happen!
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

JuneTheSecond

  • Hero Member
  • *****
  • Posts: 1027
    • Visio Shapes, Stencils and Sample Drawings
Re: Very simple mini shape explorer driven by VBA macro only
« Reply #4 on: August 12, 2010, 10:09:14 PM »
Thank you, Yacine and Visio Guy.
Enjoy a modified one.
« Last Edit: August 13, 2010, 01:11:54 AM by JuneTheSecond »
Best Regards,

Junichi Yoda
http://june.minibird.jp/

JuneTheSecond

  • Hero Member
  • *****
  • Posts: 1027
    • Visio Shapes, Stencils and Sample Drawings
Re: Very simple mini shape explorer driven by VBA macro only
« Reply #5 on: August 13, 2010, 10:52:24 PM »
1. Added an option to limit expansion level of grouped shapes.
2. The list will change togather with various changes on the window, such as turning page, adding or deleting shape.
    This is done by Application.ExitScope events.
3. Added a copy bottun to copy all text in the tree view.
4. Modified tree view so that text box shows always top of the tree at first time.
« Last Edit: August 14, 2010, 07:15:58 AM by JuneTheSecond »
Best Regards,

Junichi Yoda
http://june.minibird.jp/

JuneTheSecond

  • Hero Member
  • *****
  • Posts: 1027
    • Visio Shapes, Stencils and Sample Drawings
Re: Very simple mini shape explorer driven by VBA macro only
« Reply #6 on: August 16, 2010, 12:10:50 AM »
This is another version that uses TreeVew control.
You migh feel how simple the VBA macro is.
However, I am not sure if TreeView control is available in your Visio.
Best Regards,

Junichi Yoda
http://june.minibird.jp/

JuneTheSecond

  • Hero Member
  • *****
  • Posts: 1027
    • Visio Shapes, Stencils and Sample Drawings
Re: Very simple mini shape explorer driven by VBA macro only
« Reply #7 on: August 21, 2010, 04:55:50 PM »
The version that you can display the masters' icons.
Best Regards,

Junichi Yoda
http://june.minibird.jp/

JuneTheSecond

  • Hero Member
  • *****
  • Posts: 1027
    • Visio Shapes, Stencils and Sample Drawings
Re: Very simple mini shape explorer driven by VBA macro only
« Reply #8 on: September 09, 2010, 01:23:09 AM »
Made a Visio addin version of shape explorer.
This program has radio button to select option for icons on the treeview.
Matser  icon, Master preview picture, Shape preview picture and simple tree view.
Attatched is a project file for Visual Studio 2010 C# Visio 2010 addin.

Thank you for your great help, Visio Guy.
« Last Edit: September 09, 2010, 01:31:06 AM by JuneTheSecond »
Best Regards,

Junichi Yoda
http://june.minibird.jp/

JuneTheSecond

  • Hero Member
  • *****
  • Posts: 1027
    • Visio Shapes, Stencils and Sample Drawings
Re: Very simple mini shape explorer driven by VBA macro only
« Reply #9 on: September 09, 2010, 06:50:23 AM »
Modified a part of program code.

The shape preview of the sub sgape has differnt preview picture than the parent shape.
Now, you can analyse the group shape without opening the shape window.   :D :D :D

New "private void treeView1_BeforeExpand" in the Form1.cs is,,

Code

private void treeView1_BeforeExpand(object sender, TreeViewCancelEventArgs e)
        {
          
            TreeNode tn = e.Node;

            if (tn.Name != string.Empty)          
            {
                tn.Nodes.Clear();
                String st = tn.Name;
                String nb = st.Substring(6, st.Length - 6);
                int idSp = int.Parse(nb);
                Visio.Shape Shape = app.ActivePage.Shapes.get_ItemFromID(idSp);
                
                foreach (Visio.Shape shp in Shape.Shapes)
                {
                    TreeNode tnChild;


                    if (radioButton3.Checked)
                    {

                        addPicture(shp.Picture, shp.NameU);

                        int im = this.imageList1.Images.IndexOfKey(shp.NameU);

                        tnChild = tn.Nodes.Add(shp.NameID, shp.Name, im, im);
                    }
                    else
                    {
                        if (shp.Master != null)
                        {
                            int im = this.imageList1.Images.IndexOfKey(shp.Master.NameU);

                            tnChild = tn.Nodes.Add(shp.NameID, shp.Name, im, im);
                        }
                        else
                        {
                            tnChild = tn.Nodes.Add(shp.NameID, shp.Name, 0, 0);
                        }
                      
                    }

                    if (shp.Shapes.Count > 0)
                    {
                        tnChild.Nodes.Add("....");
                    }
                    
                    
                    
                }

            }

            
        }

« Last Edit: September 09, 2010, 06:52:30 AM by JuneTheSecond »
Best Regards,

Junichi Yoda
http://june.minibird.jp/

JuneTheSecond

  • Hero Member
  • *****
  • Posts: 1027
    • Visio Shapes, Stencils and Sample Drawings
Re: Very simple mini shape explorer driven by VBA macro only
« Reply #10 on: September 09, 2010, 07:35:54 AM »
Another analysis of the group shape is "Group" in the stencil "Active Drectory".
You can see how the picture of 2 persons are constructed.
If you click sheet.5 in the group in tree view, you see this triangle is an eye of the person in the right.
Best Regards,

Junichi Yoda
http://june.minibird.jp/

JuneTheSecond

  • Hero Member
  • *****
  • Posts: 1027
    • Visio Shapes, Stencils and Sample Drawings
Re: Very simple mini shape explorer driven by VBA macro only
« Reply #11 on: September 09, 2010, 08:49:10 PM »
You can easily change colors, clicking node in tree view, and selecting Visio menu "Fill Colors".  :D :D
To start this program from existing drawing , some part of the program must be modified.
I changed "private void ThisAddIn_Startup"  as follows,
and now I can start program by double clicking the icon of existing Visio drawing.

Code

        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            if (Application.Documents.Count == 0)
            {
                Application.Documents.Add("");
            }
                AnchorBarsUsage test = new AnchorBarsUsage();
         
            if (test.DemoAnchorBar(Application,true) == false)
            {
                MessageBox.Show("Demo Failed!");
            }
        }

[code]
[/code]
Best Regards,

Junichi Yoda
http://june.minibird.jp/

JuneTheSecond

  • Hero Member
  • *****
  • Posts: 1027
    • Visio Shapes, Stencils and Sample Drawings
Re: Very simple mini shape explorer driven by VBA macro only
« Reply #12 on: September 10, 2010, 02:04:32 AM »
"private void addPicture" in "Form1.cs" is surprisingly simplified.
It has been done by refering to Nikolay's  useful post at
http://visguy.com/vgforum/index.php?topic=2065.msg9299;topicseen#msg9299"

Code

private void addPicture(IPictureDisp pic, String key)
        {

            Image img = new Metafile((IntPtr)pic.Handle, true);
            Bitmap bmp = new Bitmap(img);
            this.imageList1.Images.Add(key, bmp);

        }

« Last Edit: September 10, 2010, 02:08:27 AM by JuneTheSecond »
Best Regards,

Junichi Yoda
http://june.minibird.jp/

JuneTheSecond

  • Hero Member
  • *****
  • Posts: 1027
    • Visio Shapes, Stencils and Sample Drawings
Re: Very simple mini shape explorer driven by VBA macro only
« Reply #13 on: September 15, 2010, 11:49:04 PM »
Added event handler so that tree view changes dynamically.
And added button to show the anchor window at Add-in tab of Ribbon.

When you expand a group shape in the tree view, event handler is locked,
and checkbox on the form is checked.
"Refresh" button on the form unlock the event handler.

The portability of attatched project file is not good after I added Ribbon program.
Then, it may happen that sometimes this project does not run correctly.
I have not yet found the reason why it is.
« Last Edit: September 16, 2010, 06:24:43 AM by JuneTheSecond »
Best Regards,

Junichi Yoda
http://june.minibird.jp/

JuneTheSecond

  • Hero Member
  • *****
  • Posts: 1027
    • Visio Shapes, Stencils and Sample Drawings
Re: Very simple mini shape explorer driven by VBA macro only
« Reply #14 on: September 16, 2010, 06:28:58 AM »
Now, I foud a way to run this project correctly.
If this project does not make the custom ribbon,
please, once save the Ribbon designer.

Then the custom ribbon will be correctly loaded at add-in tab.
Best Regards,

Junichi Yoda
http://june.minibird.jp/