Can I apply Custom Property Sets from VBA in Visio 2003?

I'm documenting a system using Visio 2003, and I've created dozens of diagrams with shapes using custom properties that evolved over time.  About midway through my project I discovered Custom Property sets and developed some standard sets I'd like to apply to my earlier drawings.  Unfortunately, the Custom Property Set tool wipes out any data that exists in earlier custom properties, and there are so many shapes it's impractical to replace them manually.  Is it possible to apply custom property sets to shapes from within VBA?  I've populated ordinary custom properties that way, but I haven't seen anything written about using custom property sets.  I'm hoping that since the sets are saved somewhere in the document, they can be accessed and applied programmatically.

Thanks,

Gabrielle Gagnon

February 28th, 2012 12:08pm

You can select all the shapes on the page or do a Select by type and apply the CP set to all the shapes at once. If the shapes contain other custom properties, they are not removed.

In Visio 2010, custom properties are called Shape Data and Shape Data sets is NOT part of the UI and you will have to go into Options and add it to the ribbon or QAT.

Free Windows Admin Tool Kit Click here and download it now
July 12th, 2012 1:10pm

Thanks very much for responding.

The problem is not so simple as that.  While I could programmatically select the shapes I need, I don't see any automated way of applying a CP set to them, and the CP set to be applied has to be in the document already.  As I mentioned, I didn't discover CP sets until about halfway through the project, and they evolved, so many documents either don't have CP sets at all or they have the wrong versions.  Ideally, I'd like to import or define CP sets in VBA for each document and apply them from within VBA, since there are literally hundreds of diagrams I need to modify.

It looks like the only way to import a CP set is to copy objects from one file to another, but if there is already a CP set in the file with the same name, the copied objects take on the characteristics of the resident CP set, not the imported one.  The resident set can be deleted manually, but again, I don't see any way to do this from within VBA.

Although CP sets are a nice feature, they appear to be an afterthought, and they're a bit cludgy to work with.  It would have been nice if they had been integrated into the Visio object model. 

Does anyone know if this functionality will be enhanced in future releases of Visio?  I haven't seen any mention of them in 2010. Does this mean CPs set are being abandoned?

July 13th, 2012 3:12pm

Custom Property Sets are an add-on solution that was included later. Most solutions that are in this type of category are not documented in how they are implemented and are not included in the API. It is in v2010, I believe they mention it in one of the mvp sessions

http://visio.microsoft.com/en-us/Get_Started/How_To/Learn_Visio_2010_from_Visio_MVPs/Pages/default.aspx

either session seven or eight. I haven't seen MS pre-announce materials like this (in my old job I think the courts had declared that unfair and an inhibition of trade). The data is stored in the document as SolutionXML, and XML can be edited (saving the drawing as a VDX file).

Al

Free Windows Admin Tool Kit Click here and download it now
July 13th, 2012 3:59pm

I guess then the answer to my question is NO, Custom Property Sets can't be applied from VBA.  Too bad.

Thanks, though, for steering me to the MVP sessions.  It looks like there's a lot of good information there.  The company is upgrading to Visio 2010.  Maybe I can find a workaround with SolutionXML.

Gabrielle

July 14th, 2012 1:32pm

I don't think it's as bad as that.

You can access a shape's sheet, which contains the Properties section, which in turn contains rows that represent the properties.

So, you can use the AddNamedRow method of a Shape object to add a property to that shape.

This method accepts a "Section" parameter. The value for this parameter should be visSectionProp.

Before you need to create the section with oShape.Addsection.

Here you have a snippet which works for me (spanish installation). All you have to do is change "BASIC_M.VSS" and "Rectngulo" to the correct names for your particular environment

     Dim intRowNum As Integer
    Dim oShape As Shape
    Dim oRow As Row
    
    Set oShape = ActivePage.Drop(Application.Documents("BASIC_M.VSS").Masters("Rectngulo"), 1#, 1#)
    
    ' Create the Custom Properties section
    oShape.AddSection visSectionProp
    
    ' Create a Custom Property (a row in the previous section)
    intRowNum = oShape.AddNamedRow(visSectionProp, "Prueba", visTagDefault)
    
    Set oRow = oShape.Section(visSectionProp).Row(intRowNum)
    
    'Set the value for the property
    oRow.Cell(5).FormulaForce = 0
    oRow.Cell(0).FormulaForce = """Hola"""

Note that the column index for this section is, insofar as I've learned,
Value = 0
Prompt = 1
Label = 2
Format = 3
SortKey = 4
Type = 5
LangID = 14
Calendar = 15

Free Windows Admin Tool Kit Click here and download it now
July 4th, 2013 6:01am

Even if you can't apply custom property sets programmatically you can still iterate through all the shapes in your documents and apply some properties by code.

You can access a shape's sheet, which contains the Properties section, which in turn contains rows that represent the properties.

So, you can use the AddNamedRow method of a Shape object to add a property to that shape.

This method accepts a "Section" parameter. The value for this parameter should be visSectionProp.

Before you need to create the section with oShape.Addsection.

Here you have a snippet which works for me (spanish installation). All you have to do is change "BASIC_M.VSS" and "Rectngulo" to the correct names for your particular environment

     Dim intRowNum As Integer
    Dim oShape As Shape
    Dim oRow As Row
    
    Set oShape = ActivePage.Drop(Application.Documents("BASIC_M.VSS").Masters("Rectngulo"), 1#, 1#)
    
    ' Create the Custom Properties section
    oShape.AddSection visSectionProp
    
    ' Create a Custom Property (a row in the previous section)
    intRowNum = oShape.AddNamedRow(visSectionProp, "Prueba", visTagDefault)
    
    Set oRow = oShape.Section(visSectionProp).Row(intRowNum)
    
    'Set the value for the property
    oRow.Cell(5).FormulaForce = 0
    oRow.Cell(0).FormulaForce = """Hola"""
Note that the column index for this section is, insofar as I've learned,
Value = 0
Prompt = 1
Label = 2
Format = 3
SortKey = 4
Type = 5
LangID = 14
Calendar = 15



July 4th, 2013 12:56pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics