Visio Guy

Visio Guy Website & General Stuff => User-submitted Stuff => Topic started by: JuneTheSecond on August 12, 2010, 07:46:59 AM

Title: Very simple mini shape explorer driven by VBA macro only
Post by: JuneTheSecond on August 12, 2010, 07: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.
Title: Re: Very simple mini shape explorer driven by VBA macro only
Post by: Yacine on August 12, 2010, 08:06:17 AM
Great work Yoda-san, I would just miss the docking window function.
Title: Re: Very simple mini shape explorer driven by VBA macro only
Post by: Visio Guy on August 12, 2010, 12:35:57 PM
Excellent work, JTS!

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

Title: Re: Very simple mini shape explorer driven by VBA macro only
Post by: Visio Guy on August 12, 2010, 12:37:34 PM
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!
Title: Re: Very simple mini shape explorer driven by VBA macro only
Post by: JuneTheSecond on August 13, 2010, 03:09:14 AM
Thank you, Yacine and Visio Guy.
Enjoy a modified one.
Title: Re: Very simple mini shape explorer driven by VBA macro only
Post by: JuneTheSecond on August 14, 2010, 03:52:24 AM
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.
Title: Re: Very simple mini shape explorer driven by VBA macro only
Post by: JuneTheSecond on August 16, 2010, 05: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.
Title: Re: Very simple mini shape explorer driven by VBA macro only
Post by: JuneTheSecond on August 21, 2010, 09:55:50 PM
The version that you can display the masters' icons.
Title: Re: Very simple mini shape explorer driven by VBA macro only
Post by: JuneTheSecond on September 09, 2010, 06: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.
Title: Re: Very simple mini shape explorer driven by VBA macro only
Post by: JuneTheSecond on September 09, 2010, 11: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,,



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("....");
                   }
                   
                   
                   
               }

           }

           
       }

Title: Re: Very simple mini shape explorer driven by VBA macro only
Post by: JuneTheSecond on September 09, 2010, 12:35:54 PM
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.
Title: Re: Very simple mini shape explorer driven by VBA macro only
Post by: JuneTheSecond on September 10, 2010, 01:49:10 AM
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.



        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]
Title: Re: Very simple mini shape explorer driven by VBA macro only
Post by: JuneTheSecond on September 10, 2010, 07: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"



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);

       }

Title: Re: Very simple mini shape explorer driven by VBA macro only
Post by: JuneTheSecond on September 16, 2010, 04:49:04 AM
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.
Title: Re: Very simple mini shape explorer driven by VBA macro only
Post by: JuneTheSecond on September 16, 2010, 11: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.
Title: Re: Very simple mini shape explorer driven by VBA macro only
Post by: JuneTheSecond on September 17, 2010, 11:58:31 AM
Modified the program so that each tree view may have correct view
with corresponding document page when multi drawings are opened.
For this purpose activePage must be replaced by the page where treeview window is open.
ActiveWindow.ID is passed from button1_Click in Ribbon.cs via AnchorBarUsage.cs to Form1.cs.
All ActivePage in Form1.cs are replaced to visioActivePage.
visioActivePage = app.Windows.get_ItemFromID(visiowindowID).Page.
And please, save Ribbon designer once before run the project.
Title: Re: Very simple mini shape explorer driven by VBA macro only
Post by: nashwaan on May 25, 2011, 04:03:54 AM
Quote from: JuneTheSecond on September 10, 2010, 07: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"



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);

        }



Hi, Is there a way to do the same thing in VBA?
I need to convert visio's Shape.Picture (which is of type IPictureDisp but in EMF format "See Visio Automation Reference") to a IPictureDisp in bitmap format. Because the ListImages of TreeView refuses to understand 'IPictureDisp in EMF format'.
What do i need to convert Shape.Picture to bitmap and then to icon? in VBA (not VB.NET and not C#), please.

BTW, Junichi, i think you actually ment to refer to Nicolay's post rather in this link http://visguy.com/vgforum/index.php?topic=2029.msg9142#msg9142
Thanks,
Yousuf.
Title: Re: Very simple mini shape explorer driven by VBA macro only
Post by: JuneTheSecond on May 26, 2011, 06:56:13 AM
I am very sorry to late, but I've forget about the details.
It would take much more time to remember.