Pages

Showing posts with label visio. Show all posts
Showing posts with label visio. Show all posts

Friday, December 27, 2013

Visio 2013 fill color problem

Recently there was a huge change in my professional life. I`ve moved to another city and found a new job. If for my previous employment I was working on WinForms application (and mostly on Visio integration into it) then now I am a back-end (mostly) web developer. So the focus of my posts will be moved to web questions and solutions.

But for now I want to post my last (probably) note about Visio. One of the problems I faced with Visio 2013 was introduction of the FillGradientEnabled param. Here is a link on MSDN. There is nothing special about it but it interfere  with a common way of filling with FillColor. If you will try to fill a shape with setting FillColor to some value it wont show if the FillGradientEnabled is there and is not False. It took a little for me to figure it out. The special case was with Organisational Chart shapes, as all of them from Visio 2013 have that property inherited from the theme...

So for me the solution was to check if that property is there, and in that case set it to false. After it FillColor worked as before!

Thursday, June 13, 2013

Detecting that shape is being copied in the visio control

Let`s say you are developing c# application that is using visio control for drawings.
Easy, scalable with the only major drawback that users will have to install MS Visio on their PCs.

Today I had to determine if the new shape is being copied rather then created from stencil. For example, you may want to copy some properties to shape from the original and if this shape is new it needs to be initialized somehow (those properties can`t be setted in the stencil). You can do it in the ShapeAdded event of the page object. But how to check if the shape is a copy? The answer is simple - check the Application.IsInScope[] property. Here is a little snippet:

private void page_ShapeAdded(Shape Shape)
{
    //it might be simple copy by Copy-Paste
    //or a drag-copied shape
    bool shapeIsACopy = VisioApplication.IsInScope[(int)VisUICmds.visCmdUFEditPaste] || 
              VisioApplication.IsInScope[(int)VisUICmds.visCmdEditPasteSpecial] || 
              VisioApplication.IsInScope[(int)VisUICmds.visCmdDragDuplicate]; 

    if (Shape.Master.NameU == MyShapes.TargetedShapeMaster && !shapeIsACopy)
        SetDefaultProperties(Shape);
}

Wednesday, January 16, 2013

How to disable glue in Visio

Recently I was implementing text labels for shapes inside visio control. This task was not very hard - I had to add new shape for labels into our stencil, add action for specific shapes and drop labels with that action.
Here is the method to add action for shape:

class VisioUtility
{
    public static string GetCellValue(Shape shape, VisSectionIndices section, VisRowIndices row, VisCellIndices column)
    {
        Cell cell = GetCell(shape, section, row, column);
        return cell.Formula;
    }

    public static Cell GetCell(Shape shape,VisSectionIndices section,VisRowIndices row, VisCellIndices column)
 {
  return shape.get_CellsSRC((short)section,(short)row,(short)column);
  }

    public static void AddSectionRow(Shape shape, short sectionIndex, VisRowIndices rowIndex, VisRowTags rowTag)
    {
        shape.AddRow(sectionIndex, (short)rowIndex, (short)rowTag);
    }

    public static void SetCellValue(Shape shape, VisSectionIndices section, VisRowIndices row, VisCellIndices column, string value)
    {
        Cell cell = GetCell(shape, section, row, column);
        if (cell.Formula != value)
        {   //in case of UNDO...
            try
            {
                cell.FormulaU = value;
            }
            catch (System.Runtime.InteropServices.COMException ex) //7580 - workaround
            {
                //handle the exception
            }
        }
    }
}

class VisioForm
{
    public static void AddAction(Shape element, string actionMarker, string title, bool isSubMenu, bool beginGroup)
    {
        //Check if this menu item is already exists
        short newItemNumber = 0;
        while (element.get_CellsSRCExists((short)VisSectionIndices.visSectionAction, (short)(VisRowIndices.visRowAction + newItemNumber), (short)VisCellIndices.visActionAction, 0) != 0)
        {
            string currentTitle = VisioUtility.GetCellValue(element, VisSectionIndices.visSectionAction, VisRowIndices.visRowAction + newItemNumber, VisCellIndices.visActionMenu);

            if (VisioUtility.StripQuotes(currentTitle) == title)
                return;

            newItemNumber++;
        }

        //add new item as last one
        newItemNumber = element.get_RowCount((short)VisSectionIndices.visSectionAction);

        VisioUtility.AddSectionRow(element, (short)VisSectionIndices.visSectionAction, VisRowIndices.visRowAction + newItemNumber, (short)VisRowTags.visTagDefault);
        Cell cell = element.get_CellsSRC((short)VisSectionIndices.visSectionAction, (short)(VisRowIndices.visRowAction + newItemNumber), (short)VisCellIndices.visActionAction);
        //set action marker, so we can handle it after
        cell.FormulaU = string.Format("RUNADDONWARGS(\"QueueMarkerEvent\",\"{0}\")", actionMarker);

        //set title
        VisioUtility.SetCellValue(element, VisSectionIndices.visSectionAction, VisRowIndices.visRowAction + newItemNumber, VisCellIndices.visActionMenu, title);

        if (isSubMenu)
            VisioUtility.SetCellValue(element, VisSectionIndices.visSectionAction, VisRowIndices.visRowAction + newItemNumber, VisCellIndices.visActionFlyoutChild, "1");

        if (beginGroup)
            VisioUtility.SetCellValue(element, VisSectionIndices.visSectionAction, VisRowIndices.visRowAction + newItemNumber, VisCellIndices.visActionBeginGroup, "1");
    }
}

And I had to handle MarkerEvent for visio application
visioApp.MarkerEvent += new EApplication_MarkerEventEventHandler(visioApp_MarkerEvent);

The main problem I faced with this task is how to disable glue for those labels, as for visio document GlueSettings we have visGlueToGeometry. I asked for this question on visguy forum and got few interesting advices, however they were not what I was looking for. The most usefull advice was to create a group and set IsSnapTarget to False. I gave up on this path, since creating the group was too complex.


The solution turned to be very easy. There is cell that disables connect for geometry NoSnap, so simply put True there!