Visio Guy

Visio Discussions => ShapeSheet & Smart Shapes => Topic started by: Budgie on October 28, 2009, 01:02:04 AM

Title: Method for updating multiple shapesheets at once?
Post by: Budgie on October 28, 2009, 01:02:04 AM
Guys,
   I want to edit the "Text Transform/TxtWidth" attribute of multiple shapes in their respective shapesheets at the same time.  At present I only seem able to edit each shapes shapesheet one at a time which will take me ages (lots of shapes).  Is there a method/tool for updating multiple shapesheets with the same attributes at once?

cheers Tony
Title: Re: Method for updating multiple shapesheets at once?
Post by: wapperdude on October 28, 2009, 01:27:02 AM
Don't know of any tools that will do that.  I think it'll need some VBA code.  Something like this to get you started.  The macro searches thru all of the shapes on the active page.  If the Text Transform section is missing, the code adds it.  (Thanks Visio Guy, I stole that from you!).  It then populates the Transform section, and here is where you can make your changes.

HTH
Wapperdude


Sub TxtTranform()
    Dim shp As Shape

    For Each shp In ThisDocument.Pages(1).Shapes
    ' Add the Text Transform section, if it's not there:
If Not (shp.RowExists(Visio.VisSectionIndices.visSectionObject, Visio.VisRowIndices.visRowTextXForm, Visio.VisExistsFlags.visExistsAnywhere)) Then
Call shp.AddRow(Visio.VisSectionIndices.visSectionObject, Visio.VisRowIndices.visRowTextXForm, Visio.VisRowTags.visTagDefault)
End If
'Populate the Text Transform cells
shp.CellsSRC(visSectionObject, visRowTextXForm, visXFormWidth).FormulaU = "TextWidth(TheText)"
                shp.CellsSRC(visSectionObject, visRowTextXForm, visXFormPinX).FormulaU = "Width*0.5"
                shp.CellsSRC(visSectionObject, visRowTextXForm, visXFormPinY).FormulaU = "Height*0.5"
                shp.CellsSRC(visSectionObject, visRowTextXForm, visXFormLocPinX).FormulaU = "TxtWidth*0.5"
                shp.CellsSRC(visSectionObject, visRowTextXForm, visXFormLocPinY).FormulaU = "TxtHeight*0.5"
                shp.CellsSRC(visSectionObject, visRowTextXForm, visXFormAngle).FormulaU = "0 deg"
    Next
End Sub
Title: Re: Method for updating multiple shapesheets at once?
Post by: Budgie on October 28, 2009, 02:46:13 AM
Thanks Wapperdude,
  I've tried your code but I must be missing something (note: I'm very much a code/VBA newbie).  Maybe you can confirm I've done this right?  I created a new VBA module (even tried creating it as a macro) with the code you provided.  I then run the macro/code but when I check the shapes shapesheets they've still got the old value.

   Appreciate your help

cheers Tony
Title: Re: Method for updating multiple shapesheets at once?
Post by: wapperdude on October 28, 2009, 03:27:40 AM
OK.  I'm assuming that you received no errors as far as the code goes.  So, the steps that I would take would be:
1.  Open up a new drawing.
2.  Go to menu bar > Tools > Macro > Visual Basic Editor (or Alt F11)
3.  That pops up the Visual Basic Editor window, and on the left (I think it's call the project window)  there should be a line item ThisDocument.  Double click that.  That brings up the basic editor section.
4.  Copy and paste the code I provided into this window.
5.  Go back to the regular Visio window and place some shapes.  Either drag / drop basic flow chart shapes or just draw some rectangles, circles, etc.
6.  Check what's in the shapesheet just for reference.  The rect's and circles should not have Text Transform sections.
7.  Back to menu bar > Tools > Macro > ThisDocument.  You should see the TxtTransform macro listed.  Click on it.  It should run very quickly.
8.  Recheck the shapesheets.  They should be changed.

That should do it.

HTH
Wapperdude
Title: Re: Method for updating multiple shapesheets at once?
Post by: Budgie on October 28, 2009, 03:58:46 AM
yep, working now. Thanks heaps.