Visio Guy

Visio Discussions => ShapeSheet & Smart Shapes => Topic started by: haggis999 on May 24, 2013, 06:49:55 PM

Title: Is there a quick way to make the same change to multiple ShapeSheets?
Post by: haggis999 on May 24, 2013, 06:49:55 PM
I am just starting to learn how to use the trial version of Visio 2013 and this is my very first post to this forum.

I have imported a complex back panel diagram for an AV amplifier as an SVG from Adobe Illustrator and I want this diagram to be fully resizable. A search online for a method of making text resizable in Visio found a solution from Visio Guy, which was to change a fixed character size in a text box ShapeSheet to the following formula:

=12 pt*ThePage!PageScale/ThePage!DrawingScale*Height/0.23

The use of 12 pt in that formula is obviously just an example. The figure of 0.23 is a figure found by trial and error that generated the same size text as before in one sample text box (before any resizing of that box).

My problem is that my diagram has a very large number of similar text boxes and changing the ShapeSheets one at a time would be extremely tedious. Is there a better way?

David

EDIT:  I suspect the answer to my own question is to write some VBA code that creates a list of all the text boxes on a page and then runs a loop to modify the Character value for each text box in turn. It still seems a little odd to me that Visio doesn't simply let you select multiple text boxes and then apply the same change to all of them simultaneously, which is the way that a lot of other software behaves.

Assuming that VBA code would solve my problem, I guess this question should really be in the Programming & Code forum.
Title: Re: Is there a quick way to make the same change to multiple ShapeSheets?
Post by: JuneTheSecond on May 25, 2013, 08:50:55 AM
I am very bad in English.
So. I read only the title of your question.
The content is too long for me to read.
Therefore my answer may be wrong.

You can save your Visio document in the form of XML.
Then you can open saved XML file with text editor or XML editor.
And then you can edit multiple shapesheet with change or replace command in the text editor.
Title: Re: Is there a quick way to make the same change to multiple ShapeSheets?
Post by: haggis999 on May 27, 2013, 08:16:13 PM
How do I save in XML format?

I am using Visio 2013. I cannot see any XML option.

David

NOTE: Google Translate can be useful if you find English difficult to understand.
http://translate.google.com/ (http://translate.google.com/)
Title: Re: Is there a quick way to make the same change to multiple ShapeSheets?
Post by: JuneTheSecond on May 27, 2013, 08:55:13 PM
I hope this document may be a help.
http://msdn.microsoft.com/en-us/library/office/jj228622.aspx
Title: Re: Is there a quick way to make the same change to multiple ShapeSheets?
Post by: haggis999 on May 27, 2013, 11:11:35 PM
After some searching, I found out that if I changed the .vsdx filename extension to .zip I could then view the XML contents using software called EditPad Pro 7 (I don't know where that came from) or in Visual Studio 2012.

While inspecting the XML code, it seemed that making selective font size changes would be very difficult. I could not see how I could find only the font size settings for a specific set of textboxes on a complex Visio page. I therefore went back to Visio and moved the relevant items to a separate page. I also made sure that all my existing textboxes had exactly the same font size.

I then did a search and replace on the XML file as follows (the new text was based on the result of one of my previous manual changes):

ORIGINAL TEXT:    <Cell N='Size' V='0.05555555555555555' U='PT'/>

REPLACED TEXT:   <Cell N='Size' V='0.04134486114774413' U='PT' F='5PT*ThePage!PageScale/ThePage!DrawingScale*Height/0.177'/>

I then saved this XML file, renamed my .zip back to .vsdx and reopened it in Visio. Unfortunately, none of my textboxes on the affected page had been updated to use my formula! I will try again tomorrow...

David
Title: Re: Is there a quick way to make the same change to multiple ShapeSheets?
Post by: Visio Guy on May 28, 2013, 08:20:59 AM
I think that I can understand why they never tried to make a multi-applicable ShapeSheet. The context can be too different, and each selected shape can have so many different or unique cells, that it would be tricky or slow to make a common-cells ShapeSheet view. Not to mention how confusing it could be for users.

If you're doing this a lot, just have a blank "Tools" stencil or drawing that you can open, and run 'scratch' VBA code like this:


'// Set the ShapeSheet formula for each selected cell. Note, all
'// selected shapes must actually have the cells!

Dim shp as Visio.Shape
For Each shp in Visio.ActiveWindow.Selection

     '// Add cell and formula/results here:
     shp.Cells("Prop.Size").ResultIU = 2 '//...IU = inches
     shp.Cells("Prop.CommieSize").Result("mm") = 2 * 25.4
     shp.Cells("Prop.Name").FormulaU = Chr(34) & "Bob" & Chr(34)
     shp.CellsU("Width").FormulaForceU = "GUARD(Width * 2)" '//...'Force' to override preexisting GUARDs

Next shp
Set shp = Nothing
Title: Re: Is there a quick way to make the same change to multiple ShapeSheets?
Post by: haggis999 on May 28, 2013, 08:54:36 AM
Quote from: Visio Guy on May 28, 2013, 08:20:59 AM

If you're doing this a lot, just have a blank "Tools" stencil or drawing that you can open, and run 'scratch' VBA code ...


Hi VG,
Thanks for that; I had a feeling that VBA would provide the answer. However, I'm too much of a Visio newbie to fully understand what you mean by the above quote from your post. How would code stored somewhere in a 'Tools' drawing be invoked by my primary drawing?

I have some experience of using VBA in the event-driven environment of an Access database but don't yet understand what is normally used to trigger code in Visio (though I have found a familiar button control). Some clarification would be appreciated.

David
Title: Re: Is there a quick way to make the same change to multiple ShapeSheets?
Post by: Yacine on May 28, 2013, 07:03:09 PM
Quote from: Visio Guy on May 28, 2013, 08:20:59 AM
I think that I can understand why they never tried to make a multi-applicable ShapeSheet. The context can be too different, and each selected shape can have so many different or unique cells, that it would be tricky or slow to make a common-cells ShapeSheet view. Not to mention how confusing it could be for users.
I don't want to agree with your statement. I prefer to still dream of a docking window that displays 1 to 1 the shapesheet. May be a little bit simplier ... not really. But available directly. Basically a better graphical Excel. May be a project for the next 2-3 weeks of vacation without kids? (I'm horrible, I know.)
Title: Re: Is there a quick way to make the same change to multiple ShapeSheets?
Post by: kennyj on May 29, 2013, 06:34:48 AM
Quote from: Yacine on May 28, 2013, 07:03:09 PM
I don't want to agree with your statement. I prefer to still dream of a docking window that displays 1 to 1 the shapesheet. May be a little bit simplier ... not really. But available directly. Basically a better graphical Excel. May be a project for the next 2-3 weeks of vacation without kids? (I'm horrible, I know.)

@Yacine - I'm a little wet behind the ears to know if you're comment is strictly "tongue in cheek" or not, but I'd be curious to hear more about what you're idea is all about. The thought reminds me a bit of some of my recent musings re: an excel template that mirrors the shapesheet and an accompanying macro to thus import shapes or changes to shapes, etc; along with my current prototyping project where I'm using excel to calculate various aspects of drawing requirements and then visio to draw them. Anyway, I'd be interested to hear about your ideas, if you care to share further on that topic.

Title: Re: Is there a quick way to make the same change to multiple ShapeSheets?
Post by: kennyj on May 29, 2013, 06:39:49 AM
Quote from: haggis999 on May 28, 2013, 08:54:36 AM
Quote from: Visio Guy on May 28, 2013, 08:20:59 AM

If you're doing this a lot, just have a blank "Tools" stencil or drawing that you can open, and run 'scratch' VBA code ...


Hi VG,
Thanks for that; I had a feeling that VBA would provide the answer. However, I'm too much of a Visio newbie to fully understand what you mean by the above quote from your post. How would code stored somewhere in a 'Tools' drawing be invoked by my primary drawing?

I have some experience of using VBA in the event-driven environment of an Access database but don't yet understand what is normally used to trigger code in Visio (though I have found a familiar button control). Some clarification would be appreciated.

David

@David, I could be off base here, as I'm newer to VBA than you, but I've used visio off and on since pre-microsoft, so hopefully this coment will be relevant (and hopefully visguy or someone will correct me if I'm out to lunch!)

I think what VG was implying is that VBA code in visio generally lives either in a document or a stencil. So if you have some code that you want to reuse, you would need to have open the stencil or drawing it's attached to.

Therefore, creating a stencil for yourself in which to save your bits of frequently needed code, and then perhaps saving your workspace/template with that stencil open would allow easy access to the code whenever you should need it.

As to accessing the code from there, I would guess you can use a button control tied to the macro, or you could create a simple shape to store in your stencil, and set the double click action or such to run the associated macro, then just drag the shape off the stencil and double click on it when you want it. Here's a good little video (https://www.youtube.com/watch?v=vD6PX4H90FM&list=UUKB65-V5s-7BnHPK691jB2g&index=1) from VG, which incidentally demonstrates  that very technique. Note also how he makes the 'button' shape non-printing so you can leave it out and not worry about forgetfully goofing up a printout with it showing.

Of course, you could alternately access the code manually via the macro menu, which I'm sure you're well aware of.

HTH,

-k
Title: Re: Is there a quick way to make the same change to multiple ShapeSheets?
Post by: Yacine on May 29, 2013, 07:47:31 PM
@Kenny,
Quote@Yacine - I'm a little wet behind the ears to know if you're comment is strictly "tongue in cheek" or not, but I'd be curious to hear more about what you're idea is all about. The thought reminds me a bit of some of my recent musings re: an excel template that mirrors the shapesheet and an accompanying macro to thus import shapes or changes to shapes, etc; along with my current prototyping project where I'm using excel to calculate various aspects of drawing requirements and then visio to draw them. Anyway, I'd be interested to hear about your ideas, if you care to share further on that topic.
Well, I'm quite serious about it.
Whilst most (developers) would prefer to hide the shapesheet from the normal users, every developer would wish to have:
- a direct access to the shapesheet without having to switch between the windows
- an editing feature for multiple shapes
- a possibilty to edit the shapesheet from outer editors (eg Excel)  ,....

As I  sayed, it is a project for which one needs some days of a calm period and we shall get remembered about it. May be the rating feature that Chris will implement ( ;D http://visguy.com/vgforum/index.php?topic=4845.msg19051;topicseen#msg19051), will help us in this matter.

I'd love to follow your project, but not right now, as I've already too much projects to handle. hopefully somewhen in summer this year.
This would definitely be the ULTIMATE contribution to Visio from it's community.
Title: Re: Is there a quick way to make the same change to multiple ShapeSheets?
Post by: kennyj on June 01, 2013, 03:41:00 PM
Very interesting, @Yacine. It will be fun to see what develops :)
Thanks,

-k
Title: Re: Is there a quick way to make the same change to multiple ShapeSheets?
Post by: kennyj on June 01, 2013, 03:42:49 PM
Here's another very good intro article to the v2013 file format and how to access/manipulate it.
http://blogs.office.com/b/visio/archive/2013/01/29/10-tips-for-developers-working-with-the-visio-vsdx-file-format.aspx
Title: Re: Is there a quick way to make the same change to multiple ShapeSheets?
Post by: Yacine on June 01, 2013, 07:59:19 PM
Yes, looks very interesting
Title: Re: Is there a quick way to make the same change to multiple ShapeSheets?
Post by: haggis999 on June 01, 2013, 09:58:27 PM
Kennyj,
I've not had much time to play with Visio over the past week but I will follow up your suggestions asap. Thanks for the help.

Yacine,
If you can come up with ways to edit multiple ShapeSheets simultaneously then that would certainly fill a gap in the standard product. I'm sure your kids will understand the need to lock them up while you get on with such important work  :). 

David
Title: Re: Is there a quick way to make the same change to multiple ShapeSheets?
Post by: haggis999 on June 02, 2013, 08:55:03 AM
Quote from: haggis999 on May 27, 2013, 11:11:35 PM
After some searching, I found out that if I changed the .vsdx filename extension to .zip I could then view the XML contents using software called EditPad Pro 7 (I don't know where that came from) or in Visual Studio 2012.

While inspecting the XML code, it seemed that making selective font size changes would be very difficult. I could not see how I could find only the font size settings for a specific set of textboxes on a complex Visio page. I therefore went back to Visio and moved the relevant items to a separate page. I also made sure that all my existing textboxes had exactly the same font size.

I then did a search and replace on the XML file as follows (the new text was based on the result of one of my previous manual changes):

ORIGINAL TEXT:    <Cell N='Size' V='0.05555555555555555' U='PT'/>

REPLACED TEXT:   <Cell N='Size' V='0.04134486114774413' U='PT' F='5PT*ThePage!PageScale/ThePage!DrawingScale*Height/0.177'/>

I then saved this XML file, renamed my .zip back to .vsdx and reopened it in Visio. Unfortunately, none of my textboxes on the affected page had been updated to use my formula! I will try again tomorrow...

David

Before attempting to pursue a potentially more complex VBA-based solution, I made another attempt to use the above referenced procedure. This time it worked!

I had been editing the relevant page XML file while it was still stored inside a zip file. When I saved this modified page a WinZip dialogue box popped up asking me to confirm that I wished to update the zip file with my changes. I hadn't seen this popup during my first attempt to edit the XML code outside Visio, probably because there was a small delay before it appeared and it was obscured by a lot of other open windows.

David
Title: Re: Is there a quick way to make the same change to multiple ShapeSheets?
Post by: JohnGoldsmith on June 02, 2013, 09:29:38 AM
Bear in mind also that not all changes to the file will be reflected in the drawing after a change.  Have a look at this post (tip 5) which deals with forcing recalculation:

http://blogs.office.com/b/visio/archive/2013/01/29/10-tips-for-developers-working-with-the-visio-vsdx-file-format.aspx (http://blogs.office.com/b/visio/archive/2013/01/29/10-tips-for-developers-working-with-the-visio-vsdx-file-format.aspx)

Best regards

John

[Update - sorry, just noticed that @kennyj posted that link already]
Title: Re: Is there a quick way to make the same change to multiple ShapeSheets?
Post by: haggis999 on June 02, 2013, 10:09:09 AM
Yes, I had already read that warning, which seemed to suggest a potential need to delve deep into various complicated coding scenarios.

However, in one of the associated references I read the comment "you can often change a shape's text without needing to recalculate the document". This seems to be the situation in my case, as my external edits to replace a fixed text size with a formula for text size all appear to have been implemented immediately in my Visio drawing.

David   
Title: Re: Is there a quick way to make the same change to multiple ShapeSheets?
Post by: haggis999 on June 02, 2013, 11:28:36 AM
I am rather confused by the differences between the Character section of a ShapeSheet as viewed within Visio and what I am assuming is the matching Character definition in the associated XML page file.

For example, a simple textbox containing a single character I have set to 12pt Arial Narrow in Visio contains the following data in the Character section of its ShapeSheet as viewed via Visio:



















Character0
Font4
Size12 pt
Scale100%
Spacing0 pt
Color0
TransparencyNo Formula
Style0
Case0
Pos.0
StrikethruFALSE
DoubleULineFALSE
OverlineFALSE
DoubleStrikethroughFALSE
AsianFont0
ComplexScriptFont0
ComplexScriptSize-100%
LangID2057

In contrast, the XML code for this same Character section is as follows:
<Section N='Character'><Row IX='0'><Cell N='Font' V='Arial Narrow'/><Cell N='Size' V='0.08517847225260369' U='PT'/></Row></Section>

Can anyone explain why these descriptions are so different? In particular, I am interested in how a 12 pt setting is converted into a size value of 0.08517847225260369.

David
Title: Re: Is there a quick way to make the same change to multiple ShapeSheets?
Post by: Yacine on June 02, 2013, 11:13:42 PM
QuoteI'm sure your kids will understand the need to lock them up while you get on with such important work  :). 
:o ;D ::) ;D
Title: Re: Is there a quick way to make the same change to multiple ShapeSheets?
Post by: JohnGoldsmith on June 03, 2013, 09:05:10 AM
Hello David,

The difference that you're seeing between the number of properties (cells) in the ShapeSheet and the small number of corresponding elements in the xml reflects how Visio makes use of inheritance. 

If you look at the ShapeSheet image below you'll see the Font and Size cells are blue and the rest are black.  Blue represents a local formula and black an inherited one.  So remember that the xml file is just a way of persisting the data and so only the local formulae are present in the page shape xml. 

You'll find the values for the rest of the cells in other locations in the package depending on where the shape is inheriting that cell from.  This might be from a master or a style.  If it's the former then it will be in the respective master_n.xml file under Package(zip)/visio/masters and if it's a style then it will be in document.xml under Package(zip)/visio (see the stylesheets element). 

Bear in mind that a shape can inherit from a master which may also inherit some of its values from a style and, since styles can inherit from other styles, potentially other styles further up the tree.

In code, you can test whether a particular shape's cell is local or not by accessing the Cell.IsInherited property and there's an equivalent ShapeSheet function called LOCALFORMULAEXISTS.

In terms of why the 12pt value get's persisted as a decimal number, this is because Visio uses inches internally  as its default unit and 12pt = 0.08517847225260369, or there abouts.  You can see that the U attribute keeps a note of the actual units displayed in the ShapeSheet.

Returning to your original question though, I would have thought that code would be a better approach.  How many unique shape types are you dealing with?  Do you have one AV amplifier type and then multiple copies?  Are you likely to reuse the shapes?

Do you have a sample document possibly including the Illustrator file you could share?  Either as an attached file or email if you'd prefer not to broadcast it.

Hope that helps.

Best regards

John
 
Title: Re: Is there a quick way to make the same change to multiple ShapeSheets?
Post by: haggis999 on June 03, 2013, 12:45:44 PM
Quote from: JohnGoldsmith on June 03, 2013, 09:05:10 AM
...Visio uses inches internally as its default unit and 12pt = 0.08517847225260369, or thereabouts... 


Hi John,
Only 17 places of decimals? With such a casual approach to accuracy, I doubt if you could ever hang a picture straight  :).

That aside, many thanks for providing that very useful clarification. I'm off on holiday very soon and may not have much time to play with Visio before I leave (my wife doesn't have computing issues high on her list of priorities over the next few days). However, I will delve a little deeper on my return.

David
Title: Re: Is there a quick way to make the same change to multiple ShapeSheets?
Post by: JohnGoldsmith on June 03, 2013, 02:48:19 PM
My pleasure.

I'll have you know that not one of the pictures in my house is straight, at least that what my micrometer says.  :)

If you're off on holiday then now is the perfect time to convince your wife of the positive impact that Visio can have on your life and of course there's lots of great books she can read while relaxing.

Enjoy your holiday.

Best regards

John
Title: Re: Is there a quick way to make the same change to multiple ShapeSheets?
Post by: JuneTheSecond on June 05, 2013, 10:13:33 AM
I hope this document may be a help.
"How to: Manipulate the Visio 2013 file format programmatically"
http://msdn.microsoft.com/en-us/library/office/jj649391%28v=office.15%29.aspx