Author Topic: Programmatically expand Shapes  (Read 5657 times)

0 Members and 1 Guest are viewing this topic.

ctrollen

  • Newbie
  • *
  • Posts: 6
Programmatically expand Shapes
« on: September 22, 2010, 10:45:43 AM »
We have a Visio-based add-on (written in C++) that uses a template .VST file as its start point.  Each of the many template files we use contains several Shape groups that are displayed within the Shapes pane.

I would like to be able to programmatically expand (or close) a particular group of shapes - by default they are not expanded and the user has to click the bar of the requisite group to expand it. 

I can access the relevant CSVDocument but there appears to be no call to expand the window; calling Open() on it simply opens a whole new child window, which is not what I want.

How would I go about this?

Thanks in advance.

Jumpy

  • Hero Member
  • *****
  • Posts: 1061
Re: Programmatically expand Shapes
« Reply #1 on: September 22, 2010, 01:33:37 PM »
Here is how it's done in VBA. Maybe you can learn enough from it for C++.
I translated it partly to english as the names of variables and functions were in german.
So "Schablone", which can still be found as variablename is the german word for stencil.

Code
Sub GetStencil()
  Sten "HereYourStencilNameWithout'.vss'"
End Sub

Public Sub Sten(Schablone As String)
'*******************************************
'* Gets Stencil to foreground              *
'*******************************************
Dim strSchablone As String
Dim stnObj As Document

strSchablone = Schablone
If IsStenOpen(strSchablone) = False Then
  strSchablone = strSchablone & ".VSS"
  Documents.OpenEx strSchablone, visOpenDocked
End If
Set stnObj = Documents(strSchablone)

End Sub

Public Function IsStenOpen(ByVal Schablonenname As String)
'Checks, if stencil is open

Dim stnObj As Document
Dim blnOffen As Boolean

blnOffen = False

For Each stnObj In Application.Documents
 If Schablonenname = stnObj.Name Then
  blnOffen = True
  Exit For
 End If
Next

IsStenOpen = blnOffen

End Function


Edit: Used this Code with Visio 2007. Just saw, that you need it for 2010. Don't know, if it will work there, too.
« Last Edit: September 22, 2010, 02:47:17 PM by Jumpy »

Paul Herber

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3301
    • Paul Herber's website
Re: Programmatically expand Shapes
« Reply #2 on: September 22, 2010, 07:42:28 PM »
Can you post a few screen shots of what this "expansion" involves?
Electronic and Electrical engineering, business and software stencils and applications for Visio -

https://www.paulherber.co.uk/

Nikolay

  • Hero Member
  • *****
  • Posts: 1125
    • UnmanagedVisio
Re: Programmatically expand Shapes
« Reply #3 on: September 22, 2010, 11:33:43 PM »
Supposing that "expanding a shape group" === "maximizing a docked stencil",
the idea expressed by Jumpy can well be formulated as "you could try OpenEx(...,visOpenDocked + visOpenRO) instead of Open(...)"

Alternatively, you could use:
yourDrawingWindow.Windows.ItemEx("Your Stencil").Activate
« Last Edit: September 22, 2010, 11:36:02 PM by Nikolay »

ctrollen

  • Newbie
  • *
  • Posts: 6
Re: Programmatically expand Shapes
« Reply #4 on: September 23, 2010, 04:33:31 AM »
Using Documents().OpenEX(vstrStencilName, visOpenDocked) worked great - thanks all!