none
CalloutsAssociated property when target is in group RRS feed

  • Question

  • In my vb.net code (Visual Studio 2010), I need to get the callouts associated with a target shape.  However, if the user has grouped the target shape in a larger group, the callouts associated property gives an error  (it's not a problem in selecting the target shape and assigning it to a variable, which works fine via selection.IterationMode = Visio.VisSelectMode.visSelModeSkipSuper)

    :

    System.Runtime.InteropServices.COMException was unhandled by user code
      ErrorCode=-2032465763
      Message=

    Inappropriate source object for this action.
      Source=Microsoft Visio
      StackTrace:
           at Microsoft.Office.Interop.Visio.ShapeClass.get_CalloutsAssociated()
           at Visio_RefIt_AddIn_2010.SetDataConnectionForm.StoreEditOptions() in C:\GINA DOCUMENTS\VSTO Documents\Visio_RefIt_AddIn_2010\Visio_RefIt_AddIn_2010\SetDataConnectionForm.vb:line 713
           at Visio_RefIt_AddIn_2010.SetDataConnectionForm.SetDataConnectionForm_Load(Object sender, EventArgs e) in C:\GINA DOCUMENTS\VSTO Documents\Visio_RefIt_AddIn_2010\Visio_RefIt_AddIn_2010\SetDataConnectionForm.vb:line 123
           at System.Windows.Forms.Form.OnLoad(EventArgs e)
           at System.Windows.Forms.Form.OnCreateControl()
           at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
           at System.Windows.Forms.Control.CreateControl()
           at System.Windows.Forms.Control.WmShowWindow(Message& m)
           at System.Windows.Forms.Control.WndProc(Message& m)
           at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
           at System.Windows.Forms.Form.WmShowWindow(Message& m)
           at System.Windows.Forms.Form.WndProc(Message& m)
           at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
           at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
           at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
      InnerException:


    Gina
    Tuesday, December 20, 2011 7:26 PM

Answers

  • I accomplished this by testing each shape to see if it contained shapes (a group is a shape, and so the group shape can have sub-shapes).  If it contained shapes, I iterated through those shapes to see if they contained shapes or if they were named using my keyword.  Then I tested those sub-shapes, and continued looping until none of the shapes had sub-shapes.   I collected the shapes that had my keyword in an array.

    Gina

    • Marked as answer by Gina1111 Wednesday, February 27, 2013 9:15 PM
    Wednesday, February 27, 2013 9:15 PM

All replies

  • ' Here is the code

    Dim selectShape as Visio.Shape

    ' This selectedShape is the target, which has several callouts attached

     

    Dim callNums() as Long

    'The code that it stops on is this.

    callNums = selectedShape.CalloutsAssociated

     

    'If the selShape is in a group, it gives the error.  (I've checked to ensure that selShape is the correct shape, the one with callouts, using the Locals window).   Even when I programmatically ungroup the parent shape of selShape first, it doesn't work.   If the selShape is not in a group when the program code starts, it works fine.


    Gina

    • Edited by Gina1111 Tuesday, December 20, 2011 9:00 PM
    Tuesday, December 20, 2011 8:57 PM
  • Hi Gina,

    Thank you for posting.

    It is difficult to reproduce the scenario on my side, could you show us the detail steps list about reproducing the problem? How did you define and get the value of selectedShape?

    It will be nice if you can upload the project on the skydirve:

    https://skydrive.live.com/

    and share it with us. In this way, we will analyze your problem and give you the workarounds more quickly.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Thursday, December 22, 2011 6:00 AM
  • Gina, how about the problem on your side? If you still show any concern on the problem, just feel free to let us know.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Tuesday, December 27, 2011 5:00 AM
  • Bruce,

    I have been Christmas breaking.  Sorry for the delay.  I don't want to copy all my code here, since it's for a confidential project.  Here is how to reproduce it, though:

     

    1. Create a rectangle (call it Target1) in Visio, then attach Callouts to it, either programatically or in Visio, (name them CO1, CO2, etc. )

    2.  Create other random shapes on the page that you can group these with, then group everything on the page.

    3.  Try to write code that allows the user to select the rectangle, and let the code assign all the callout shapes attached to that rectangle to an array. 

    My code works well when the rectangle is not grouped to other Visio shapes.  

    When it is grouped, though, I can still programatically assign the selected rectangle (Target1) to a Visio.Shape variable (selectedShape), but the selectedShape.CalloutsAssociated property won't return the IDs of the callouts.   It shows an error when it gets to that line.


    Gina
    Wednesday, December 28, 2011 7:39 PM
  • Hi Gina,

    Sorry for the late reply.

    I am not very familiar with Visio programming and difficult to reproduce the problem as you described.

    Which is the template do you choose? Is it a Basic Flowchart?

    >>3. Try to write code that allows the user to select the rectangle, and let the code assign all the callout shapes attached to that rectangle to an array.

    How did you get the selectedShape?

    You can build up a simple demo which can reproduce the problem for me and this can make me do the research of your problem more quickly. Thank you for your support and understanding and wish you happy new year.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us


    • Edited by Bruce Song Monday, January 2, 2012 2:25 PM
    Monday, January 2, 2012 6:33 AM
  • I accomplished this by testing each shape to see if it contained shapes (a group is a shape, and so the group shape can have sub-shapes).  If it contained shapes, I iterated through those shapes to see if they contained shapes or if they were named using my keyword.  Then I tested those sub-shapes, and continued looping until none of the shapes had sub-shapes.   I collected the shapes that had my keyword in an array.

    Gina

    • Marked as answer by Gina1111 Wednesday, February 27, 2013 9:15 PM
    Wednesday, February 27, 2013 9:15 PM