Solved

Generating mind map from xml fields

Posted on 2007-11-16
6
701 Views
Last Modified: 2008-02-01
I would like to do this for directories within a directory:

(1) Open an xml file X
(2) Read a name field from X to a string
(3) Put a circle with that name on a visio sheet

Thanks

Andy
0
Comment
Question by:mranders
  • 3
  • 2
6 Comments
 
LVL 24

Expert Comment

by:fridom
ID: 20297390
if visio has a COM Interface this is not that hard.
1) check that you have some XML library like msxml or libxml2 installed
 1.1) do whatever is needed to open the xml file
2) use an XPath search string to look for the pattern you're interested in
3) Open the COM interface of visio
4) find the proper function to call in the COM interface.

Not difficult if you know XML, and COM programming otherwise....

Regards
Friedrich
0
 

Author Comment

by:mranders
ID: 20298085
Thanks Fridom. I was hoping that someone had done something simiilar and could provide some sort of code snippet  as a starting point.
0
 
LVL 30

Expert Comment

by:Scott Helmers
ID: 20303163
Andy,

The Visio macro recorder is a great way to generate sample code. For example, I turned on the macro recorder, drew a circle (by using the Drawing toolbar), then double-clicked on it and added text.  After I stopped the recorder, I only made one edit -- I set the x/y parameters for the DrawOval method to integer values for convenience. (BTW, the first two numbers are the x and y coordinates of the lower left corner of the width-height box surrounding the circle; the second pair of numbers is the upper right corner.)

If you paste the attached code into the VBA editor and run it, you'll have a circle on the page containing text.

Obviously I've skipped over your requirement to read data from an XML file but let me know if this much is useful to start.

Sub DrawCircle()
 
    Application.ActiveWindow.Page.DrawOval 3, 4, 4, 5
 
    Dim vsoCharacters1 As Visio.Characters
    Set vsoCharacters1 = Application.ActiveWindow.Page.Shapes.ItemFromID(1).Characters
    vsoCharacters1.Begin = 0
    vsoCharacters1.End = 0
    vsoCharacters1.Text = "text in circle"
 
End Sub

Open in new window

0
ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 

Author Comment

by:mranders
ID: 20303461
Scott,
Thanks, you suggestion could be the way to go - to work with the macro recorder and do as much as you can with it, then try to figure out how to go through the subdierectories in a folder open an xml file within each, search within that file for the right tag etc. I suspect this latter part is not trivial however.
0
 
LVL 30

Accepted Solution

by:
Scott Helmers earned 500 total points
ID: 20304478
Andy,

After I posted last night I had a nagging feeling that I'd seen sample VBA code for looping through multiple files in a directory. I found it this morning on a long-time Visio help site. The specific page of VBA samples is here: http://visio.mvps.org/VBA.htm but be sure to browse the rest of the site as well. It looks like most of the information here is circa Visio 2003 or earlier but the basics of Visio VBA haven't changed -- you just won't find code snippets that use newer Visio functions.

The sample below specifically looks for Visio files but shouldn't be hard to adapt to find XML files instead. As far as locating specific data inside an XML file, that's just basic text parsing because an XML file is straight text. I'm sure the VB zone or VB support sites should be able to help with the text processing piece as that really doesn't have anything to do with Visio.

LoopThroughFiles: This subroutine loops through the files in a specific directory.
 
Sub LoopThroughFiles()
' This program will loop through specific files within a directory.
 
Dim docsObj As Visio.Documents, docObj As Visio.Document, pagsObj as Visio.Pages
Dim PathFileName As String, PathName As String, CurrFileName As String
 
' Set the default pathname
PathName = "C:\VisioTemp\"
PathFileName = PathName & "*.vsd"
 
' Find the first file from the directory (not necessarily the first alphabetically)
CurrFileName = Dir(PathFileName)
 
Do While CurrFileName <> ""
 
' Open the file
PathFileName = PathName & CurrFileName
Set docObj = Documents.Open(PathFileName)
Set pagsObj = docObj.Pages
 
 
 
' Do what you want to the pages in this file!
 
 
docObj.Save
docObj.Close
 
CurrFileName = Dir
Loop
 
End Sub

Open in new window

0
 

Author Comment

by:mranders
ID: 20333560
Thanks Scott I have some good ideas now to get started.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A short article about problems I had with the new location API and permissions in Marshmallow
This is about my first experience with programming Arduino.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question