Visio Guy

Visio Discussions => Programming & Code => Topic started by: suhaspatil3007 on December 30, 2011, 05:55:10 AM

Title: delete all connection point of shape and add new and glue the shapes
Post by: suhaspatil3007 on December 30, 2011, 05:55:10 AM
hi all,

i am trying to delete all connection point of shape using following code

   For currentRow = 0 To shape.Section(Visio.VisSectionIndices.visSectionConnectionPts).Count - 1
            shape.DeleteRow Visio.VisSectionIndices.visSectionConnectionPts, visRowFirst + currentRow
    Next currentRow


and add new connection point to shape and
trying to glue the newly created connection point with connector using following code

Set beginX = connector.CellsSRC(visSectionObject, visRowXForm1D, vis1DBeginX)
Set temp = shape.CellsSRC(visSectionObject, currentRow, Visio.VisCellIndices.visCnnctX)

beginX.GlueTo temp


but it throws error saying inappropriate object

can any one put some light on this part????

thanks in advance
Title: Re: delete all connection point of shape and add new and glue the shapes
Post by: Jumpy on December 30, 2011, 07:34:03 AM
I don't know, if it relates to your error, but as a dump question: What value is in currentRow at the time you Set Temp?

As to deleting all rows: Don't know if neccessary in VBA, but I think it is a best practice, to delete backwards:
For currentRow = shape.Section(Visio.VisSectionIndices.visSectionConnectionPts).Count - 1 To 0 Step -1

Or instead of deleting all the rows you could delete the whole section, recreate it and insert a new row in it. Maybe that is faster.
Title: Re: delete all connection point of shape and add new and glue the shapes
Post by: suhaspatil3007 on December 30, 2011, 08:14:50 AM
currentrow is just counter of for loop
e.g
For currentRow = 0 To connectionPoints.count - 1
Set masterObj = ActiveDocument.Masters.ItemU("Dynamic Connector")
        Set connector = ActivePage.Drop(masterObj, 1, 1)

Set beginX = connector.CellsSRC(visSectionObject, visRowXForm1D, vis1DBeginX)
Set temp = shape.CellsSRC(visSectionObject, currentRow, Visio.VisCellIndices.visCnnctX)

beginX.GlueTo temp

next  currentRow

the point here is it wont allow to glue connector to connection point cell of shape and i dont know why.

but visio allows this
beginX.GlueTo shape.CellsSRC(visSectionObject, visRowXFormOut, visXFormPinX) -- no error for this line
Title: Re: delete all connection point of shape and add new and glue the shapes
Post by: JuneTheSecond on December 30, 2011, 11:12:34 AM
May be, the reason is Visio bug in CellsSRC.
In
     Set beginX = myConnector.CellsSRC(visSectionObject, visRowXForm1D, vis1DBeginX)
     Set temp = myShape.CellsSRC(visSectionObject, currentRow, Visio.VisCellIndices.visCnnctX)
beginX and temp are changed to something like integer.

You have found a greate bug in Visio.

Next codes run correctly.

    Set beginX = myConnector.Cells("BeginX")
    Set temp = myShape.Cells("Connections.X1")   
    beginX.GlueTo temp



Title: Re: delete all connection point of shape and add new and glue the shapes
Post by: aledlund on December 30, 2011, 12:28:50 PM
Jumpy's correct, you have to delete backwards from the end of the list.
Title: Re: delete all connection point of shape and add new and glue the shapes
Post by: Jumpy on December 30, 2011, 01:54:04 PM
Maybe you should show more code instead of just snippets.
I would guess that your indexes are wrong and you so try to connect to a connection point (row) that doesn't exist. That's the nice thing with JuneTheSeconds code, where he uses shape.Cells(""). If the named cell exists it will work.
Title: Re: delete all connection point of shape and add new and glue the shapes
Post by: JuneTheSecond on December 30, 2011, 10:56:14 PM
Now I see, please replace
Set temp = shape.CellsSRC(visSectionObject, currentRow, Visio.VisCellIndices.visCnnctX)
into
Set temp = Shape.CellsSRC(visSectionConnectionPts, currentRow, visCnnctX)
Browser ID: smf (is_webkit)
Templates: 1: Printpage (default).
Sub templates: 4: init, print_above, main, print_below.
Language files: 1: index+Modifications.english (default).
Style sheets: 0: .
Hooks called: 59 (show)
Files included: 25 - 922KB. (show)
Memory used: 767KB.
Tokens: post-login.
Cache hits: 7: 0.00095s for 22,301 bytes (show)
Cache misses: 1: (show)
Queries used: 9.

[Show Queries]