automate drawing visio 2010 diagram with c# - can't set custom properties RRS feed

  • Question

  • I've got a Visio 2010 stencil with a few shapes on it. On the ShapeSheet, the Shape Data columns are things like "Prop.Manufacturer", "Prop.IP" etc.  I want to read data from a database, start a new Visio diagram, draw shapes on the page, and take data from the database and change the properties on each shape.  I've got it all working except once I read the data from the database, I cannot change the custom properties on the shape.  Below is the code I am using.  I have also tried adding "Prop." to the beginning of each row name with no luck.  Can anyway tell me what I am doing wrong?

    public static string SetCustomPropertyFormula( Microsoft.Office.Interop.Visio.Shape customPropertyShape, string rowNameU, string universalSyntaxFormula) { if (customPropertyShape == null || rowNameU == null || universalSyntaxFormula == null)

    { return "yes"; } const string CUST_PROP_PREFIX = "Prop."; Microsoft.Office.Interop.Visio.Cell customPropertyCell; Microsoft.Office.Interop.Visio.Application visioApplication =(Microsoft.Office.Interop.Visio.Application) customPropertyShape.Application; try { if (rowNameU.Length == 0) { throw new System.ArgumentNullException("rowNameU","Zero length string input."); } if (universalSyntaxFormula.Length == 0) { throw new System.ArgumentNullException("universalSyntaxFormula", "Zero length string input."); } Console.WriteLine("universal name is " + rowNameU); // prints "universal name is Manufacturer" if (customPropertyShape.get_CellExistsU(rowNameU, (short)Microsoft.Office.Interop.Visio. VisExistsFlags.visExistsLocally)== 0) { if (visioApplication.AlertResponse == 0) { Console.WriteLine("Shape does not have a custom property with the universal name of '" + rowNameU + "'."); } // print "Shape does not have... Manufacturer" return "no"; }

    Wednesday, July 11, 2012 4:56 PM

All replies

  • Hi kathys39,

    Thanks for posting in the MSDN Forum.

    Would you please tell me whether your code comes form a add-in or a automation program such as a windows form application?

    Have a good day,


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, July 12, 2012 6:46 AM
  • Hi Kathy,

    Along with the request for information from Tom Xu could you tell us what template you used for your Visio diagram, and some idea of the stencil and the shape provided from that stencil that your code addresses. The reason for this request is that someone needs to duplicate what you're doing in order to dig down into the shape properties and possibly provide you an answer to your query.

    Thank you for your patience.

    Please remember to mark the replies as answer if they help and unmark them if they provide no help. and click "Vote as Helpful" this and other helpful posts, so other users will see your thread as useful. Best Regards, Chris Jensen

    Friday, July 20, 2012 8:48 PM