Visio Organization Chart Pictures

  • Thread starter Steve Fibelkorn
  • Start date
S

Steve Fibelkorn

I maintain an Organization chart in Visio 2003. Recently the organization
size has grown to over 500 members, and inserting a picture for each member
one at a time has become quite bothersome.

Does anyone have a way or know of code (macro or vba) that will read a
picture path from the custome properties for each shape and inset a picture
for each shape on the the org chart?

Or secondly, Does anyone know of a way to have the picture from the Access
database pulled into a visoio org chart form the data base?
 
M

Mark Mayle

I also need to programmatically insert pictures into my Visio (2007) org chart shapes (created with the wizard). Any idea how to do this? I cannot seem to find any information on how and where these are kept or how they can be accessed via the Visio object model. The reply above did not help me achieve this. Maybe I am missing something?

EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com
 
D

David Parker

Not pretty, but a loop with something like the following would work:

Dim shp As Visio.Shape
Dim adn As Visio.Addon

Set adn = Visio.Addons("OrgC11")
'Loop thru your shapes
Set shp = Visio.ActivePage.Shapes("Assistant")
Visio.ActiveWindow.DeselectAll
Visio.ActiveWindow.Select shp, Visio.VisSelectArgs.visSelect
SendKeys "C:\Users\davidp\Pictures\anypicture.jpg{ENTER}", True
adn.Run "/cmd=InsertPicture"
'end loop

in message news:[email protected]...
 
M

Mark Mayle

David, Thanks for the tip. I was able to implement the piece that inserts
the picture just fine, but am having trouble passing the keystrokes to the
file dialog box that is part of the insert picture add-on. When I run this
(my application is VB.NET that is using the visio automation server) from my
application or from VBA inside Visio all that happen is that the characters
are entered into the shape and the add-on waits for input on the dialog box).
Again, thanks for your help!

Mark
 
M

Mark Mayle

Did some further work on this. The second parameter on sendkeys needs to be
False not True. This parameter tells the function whether to wait until
processing is complete before moving on to the next statement. It is the
"wait" parameter. We do NOT want to wait, as immediately after we send the
keys we call the insert function which pops up the file dialog box and gets
populated with the keys we sent. If wait is True, it takes the keys and
shoves them into the shape object, then moves on and inserts the picture.
This works perfectly in VBA in a Visio macro.

Now for the problem. My program is a VB.net application with no user
interface (it will be kicked off via a separate application). It uses Visio
as an automation server; when I try to call the send method from my app I
get an error message stating: SendKeys cannot run inside this application
because the application is not handling Windows messages. Either change the
application to handle messages, or use the SendKeys.SendWait method.

I may go back to my previous method of just reproducing the insert picture
function manually. This works but I need to get all of the shape rows and
cells that describe the placement of the picture correct.
 
D

David Parker

Oh well, I did say it wasn't pretty...
I don't like using sendkeys, but it is a quick way to use some existing
addons.
I do wish that MS would make there addons accept optional parameters for
those of us that wish to automate rather than use the UI...:)
Hint ;-)
 
J

John Goldsmith

Hello Mark,

Just an observation on David's SendKeys suggestion is that I would have
thought the following code should be in the reverse order

ie:

'Invoke the insert picture dialog
adn.Run "/cmd=InsertPicture"
'add a DoEvents to ensure the dialog is active
DoEvents
'now add the file name
SendKeys "C:\Users\davidp\Pictures\anypicture.jpg{ENTER}", True

That may not solve your .Net porblem of course. In terms of adding your
owner image, it should be just a case of changing some User cells in the Org
chart shape plus some formulae in the image shape you're dropping:

User.ShowPicture = 1
User.HasPicture = 1
User.PictureAspectRatio = [need to calculate]
User.PictureID = [your image shape's Sheet.ID]
User.ExpandedForPicture = 1

Note, I haven't fully tested this but I these are the main ones. You'll
also need to look at the image shape itself and then add the appropriate
formulae once you've dropped the shape.

Best regards

John


John Goldsmith
www.visualSignals.typepad.co.uk
www.visualSignals.co.uk
 
M

Mark Mayle

John,

It turns out that the order that David suggested works. If you call the
insert picture addon first, your program execution stops until the addon
completes; the dialog box asking for a file name comes up and waits for
input. Once you give it input then your sendkeys statement would run but
it's too late at that point. The problem is that the addon runs
synchronously. By using the no wait option on the sendkeys you get it to run
asynchronously, meaning that you send the keys in and then start the addon
without waiting for the keys to be processed. What makes this a little
questionable is there might be some system dependent timing issues between
how fast your keys are processed and when the dialog box comes up. If your
program thread maintains control and does not let the system process the
keys until it blocks (like when it waiting for user input in the dialog box),
this will work.

Thanks for the suggestions on the cell settings! I will give these a try.
What makes it somewhat more challenging is that some of the settings are
formulas that reference other shape settings. But I will trudge through
it.....

Mark

John Goldsmith said:
Hello Mark,

Just an observation on David's SendKeys suggestion is that I would have
thought the following code should be in the reverse order

ie:

'Invoke the insert picture dialog
adn.Run "/cmd=InsertPicture"
'add a DoEvents to ensure the dialog is active
DoEvents
'now add the file name
SendKeys "C:\Users\davidp\Pictures\anypicture.jpg{ENTER}", True

That may not solve your .Net porblem of course. In terms of adding your
owner image, it should be just a case of changing some User cells in the Org
chart shape plus some formulae in the image shape you're dropping:

User.ShowPicture = 1
User.HasPicture = 1
User.PictureAspectRatio = [need to calculate]
User.PictureID = [your image shape's Sheet.ID]
User.ExpandedForPicture = 1

Note, I haven't fully tested this but I these are the main ones. You'll
also need to look at the image shape itself and then add the appropriate
formulae once you've dropped the shape.

Best regards

John


John Goldsmith
www.visualSignals.typepad.co.uk
www.visualSignals.co.uk

Mark Mayle said:
Did some further work on this. The second parameter on sendkeys needs to
be
False not True. This parameter tells the function whether to wait until
processing is complete before moving on to the next statement. It is the
"wait" parameter. We do NOT want to wait, as immediately after we send
the
keys we call the insert function which pops up the file dialog box and
gets
populated with the keys we sent. If wait is True, it takes the keys and
shoves them into the shape object, then moves on and inserts the picture.
This works perfectly in VBA in a Visio macro.

Now for the problem. My program is a VB.net application with no user
interface (it will be kicked off via a separate application). It uses
Visio
as an automation server; when I try to call the send method from my app I
get an error message stating: SendKeys cannot run inside this application
because the application is not handling Windows messages. Either change
the
application to handle messages, or use the SendKeys.SendWait method.

I may go back to my previous method of just reproducing the insert picture
function manually. This works but I need to get all of the shape rows and
cells that describe the placement of the picture correct.
 
J

John Goldsmith

Hello Mark,

Yes, I've had a test now and see you're quite right. That's what I get for
questioning David's code. He must have used Visio before :)

Re the cells I would just copy and the formulae from an existing image shape
and amend their respective shape IDs. As you point out you'll need to
ensure that the shapes and cells exist in the drawing before referencing
them (ie drop the image shape onto the page to get its ID before trying to
write to the parent cells .

Best regards

John


John Goldsmith
www.visualSignals.typepad.co.uk
www.visualSignals.co.uk

Mark Mayle said:
John,

It turns out that the order that David suggested works. If you call the
insert picture addon first, your program execution stops until the addon
completes; the dialog box asking for a file name comes up and waits for
input. Once you give it input then your sendkeys statement would run but
it's too late at that point. The problem is that the addon runs
synchronously. By using the no wait option on the sendkeys you get it to
run
asynchronously, meaning that you send the keys in and then start the addon
without waiting for the keys to be processed. What makes this a little
questionable is there might be some system dependent timing issues between
how fast your keys are processed and when the dialog box comes up. If
your
program thread maintains control and does not let the system process the
keys until it blocks (like when it waiting for user input in the dialog
box),
this will work.

Thanks for the suggestions on the cell settings! I will give these a try.
What makes it somewhat more challenging is that some of the settings are
formulas that reference other shape settings. But I will trudge through
it.....

Mark

John Goldsmith said:
Hello Mark,

Just an observation on David's SendKeys suggestion is that I would have
thought the following code should be in the reverse order
SendKeys "C:\Users\davidp\Pictures\anypicture.jpg{ENTER}", True
adn.Run "/cmd=InsertPicture"

ie:

'Invoke the insert picture dialog
adn.Run "/cmd=InsertPicture"
'add a DoEvents to ensure the dialog is active
DoEvents
'now add the file name
SendKeys "C:\Users\davidp\Pictures\anypicture.jpg{ENTER}", True

That may not solve your .Net porblem of course. In terms of adding your
owner image, it should be just a case of changing some User cells in the
Org
chart shape plus some formulae in the image shape you're dropping:

User.ShowPicture = 1
User.HasPicture = 1
User.PictureAspectRatio = [need to calculate]
User.PictureID = [your image shape's Sheet.ID]
User.ExpandedForPicture = 1

Note, I haven't fully tested this but I these are the main ones. You'll
also need to look at the image shape itself and then add the appropriate
formulae once you've dropped the shape.

Best regards

John


John Goldsmith
www.visualSignals.typepad.co.uk
www.visualSignals.co.uk

Mark Mayle said:
Did some further work on this. The second parameter on sendkeys needs
to
be
False not True. This parameter tells the function whether to wait
until
processing is complete before moving on to the next statement. It is
the
"wait" parameter. We do NOT want to wait, as immediately after we send
the
keys we call the insert function which pops up the file dialog box and
gets
populated with the keys we sent. If wait is True, it takes the keys
and
shoves them into the shape object, then moves on and inserts the
picture.
This works perfectly in VBA in a Visio macro.

Now for the problem. My program is a VB.net application with no user
interface (it will be kicked off via a separate application). It uses
Visio
as an automation server; when I try to call the send method from my
app I
get an error message stating: SendKeys cannot run inside this
application
because the application is not handling Windows messages. Either change
the
application to handle messages, or use the SendKeys.SendWait method.

I may go back to my previous method of just reproducing the insert
picture
function manually. This works but I need to get all of the shape rows
and
cells that describe the placement of the picture correct.

:

Not pretty, but a loop with something like the following would work:

Dim shp As Visio.Shape
Dim adn As Visio.Addon

Set adn = Visio.Addons("OrgC11")
'Loop thru your shapes
Set shp = Visio.ActivePage.Shapes("Assistant")
Visio.ActiveWindow.DeselectAll
Visio.ActiveWindow.Select shp, Visio.VisSelectArgs.visSelect
SendKeys "C:\Users\davidp\Pictures\anypicture.jpg{ENTER}", True
adn.Run "/cmd=InsertPicture"
'end loop

in message I also need to programmatically insert pictures into my Visio (2007)
org
chart shapes (created with the wizard). Any idea how to do this? I
cannot
seem to find any information on how and where these are kept or how
they
can be accessed via the Visio object model. The reply above did not
help
me achieve this. Maybe I am missing something?

EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top