News:

BB code in posts seems to be working again!
I haven't turned on every single tag, so please let me know if there are any that are used/needed but not activated.

Main Menu

Very simple mini shape explorer driven by VBA macro only

Started by JuneTheSecond, August 12, 2010, 07:46:59 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

JuneTheSecond

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.
Best Regards,

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

Yacine

Great work Yoda-san, I would just miss the docking window function.
Yacine

Visio Guy

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

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

#4
Thank you, Yacine and Visio Guy.
Enjoy a modified one.
Best Regards,

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

JuneTheSecond

#5
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.
Best Regards,

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

JuneTheSecond

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

The version that you can display the masters' icons.
Best Regards,

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

JuneTheSecond

#8
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.
Best Regards,

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

JuneTheSecond

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

           }

           
       }

Best Regards,

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

JuneTheSecond

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

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]
Best Regards,

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

JuneTheSecond

#12
"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);

       }

Best Regards,

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

JuneTheSecond

#13
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.
Best Regards,

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

JuneTheSecond

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/

Browser ID: smf (possibly_robot)
Templates: 4: index (default), Display (default), GenericControls (default), GenericControls (default).
Sub templates: 6: init, html_above, body_above, main, body_below, html_below.
Language files: 4: index+Modifications.english (default), Post.english (default), Editor.english (default), Drafts.english (default).
Style sheets: 4: index.css, attachments.css, jquery.sceditor.css, responsive.css.
Hooks called: 396 (show)
Files included: 34 - 1306KB. (show)
Memory used: 1277KB.
Tokens: post-login.
Cache hits: 14: 0.00144s for 26,764 bytes (show)
Cache misses: 3: (show)
Queries used: 16.

[Show Queries]