News:

BB code in posts seems to be working again!
I haven't turned on every single tag, so please let me know if there are any that are used/needed but not activated.

Main Menu

No longer able to add rows in the geometry section of dynamic connectors

Started by IRDC, March 19, 2013, 02:52:26 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

IRDC

I just noticed that I'm no longer able to manually add a new row in the geometry section of a dynamic connector using the shape sheet's context menu or VBA or C#. The option is there but no new line is added. I can still create new lines by manually dragging the line (holding SHIFT or CTRL) but when I use the macro recorder of Visio 2013 such an action that created new rows in the shape sheet will only consist of set formula lines. (see recorded macro below) I could not find any new cell or property that might disable such a behavior. Even setting the diagram services to none does not help.
Does anybody know anything about this?


Sub Macro4()

    'Enable diagram services
    Dim DiagramServices As Integer
    DiagramServices = ActiveDocument.DiagramServicesEnabled
    ActiveDocument.DiagramServicesEnabled = visServiceVersion140 + visServiceVersion150

    Dim UndoScopeID1 As Long
    UndoScopeID1 = Application.BeginUndoScope("Manual Edit")
    Application.ActiveWindow.Page.Shapes.ItemFromID(5).CellsSRC(visSectionObject, visRowXFormOut, visXFormWidth).FormulaForceU = "GUARD(EndX-BeginX)"
    Application.ActiveWindow.Page.Shapes.ItemFromID(5).CellsSRC(visSectionObject, visRowXFormOut, visXFormHeight).FormulaForceU = "GUARD(EndY-BeginY)"
    Application.ActiveWindow.Page.Shapes.ItemFromID(5).CellsSRC(visSectionObject, visRowXForm1D, vis1DBeginX).FormulaU = "95 mm"
    Application.ActiveWindow.Page.Shapes.ItemFromID(5).CellsSRC(visSectionObject, visRowXForm1D, vis1DBeginY).FormulaU = "179 mm"
    Application.ActiveWindow.Page.Shapes.ItemFromID(5).CellsSRC(visSectionObject, visRowXForm1D, vis1DEndX).FormulaU = "117.5 mm"
    Application.ActiveWindow.Page.Shapes.ItemFromID(5).CellsSRC(visSectionObject, visRowXForm1D, vis1DEndY).FormulaU = "109 mm"
    Application.ActiveWindow.Page.Shapes.ItemFromID(5).CellsSRC(visSectionObject, visRowTextXForm, visXFormPinX).FormulaU = "0.10810368899296"
    Application.ActiveWindow.Page.Shapes.ItemFromID(5).CellsSRC(visSectionObject, visRowTextXForm, visXFormPinY).FormulaU = "-1.8181060097971"
    Application.ActiveWindow.Page.Shapes.ItemFromID(5).CellsSRC(visSectionObject, visRowShapeLayout, visSLOConFixedCode).FormulaForceU = "3"
    Application.ActiveWindow.Page.Shapes.ItemFromID(5).CellsSRC(visSectionFirstComponent, 1, 0).FormulaForceU = "0"
    Application.ActiveWindow.Page.Shapes.ItemFromID(5).CellsSRC(visSectionFirstComponent, 1, 1).FormulaForceU = "0"
    Application.ActiveWindow.Page.Shapes.ItemFromID(5).CellsSRC(visSectionFirstComponent, 2, 0).FormulaForceU = "0.15748031496063"
    Application.ActiveWindow.Page.Shapes.ItemFromID(5).CellsSRC(visSectionFirstComponent, 2, 1).FormulaForceU = "-1.3897637795276"
    Application.ActiveWindow.Page.Shapes.ItemFromID(5).CellsSRC(visSectionFirstComponent, 3, 0).FormulaForceU = "-4.4408920985006e-16"
    Application.ActiveWindow.Page.Shapes.ItemFromID(5).CellsSRC(visSectionFirstComponent, 3, 1).FormulaForceU = "-2.755905511811"
    Application.ActiveWindow.Page.Shapes.ItemFromID(5).CellsSRC(visSectionFirstComponent, 4, 0).FormulaForceU = "0.88582677165354"
    Application.ActiveWindow.Page.Shapes.ItemFromID(5).CellsSRC(visSectionFirstComponent, 4, 1).FormulaForceU = "-2.755905511811"
    Application.EndUndoScope UndoScopeID1, True

    'Restore diagram services
    ActiveDocument.DiagramServicesEnabled = DiagramServices

End Sub

Paul Herber

Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

IRDC

Must have not noticed it back then. Good that it's back so I have a chance to see it now  ;)
Do you know a workaround?

IRDC

I just noticed, that it doesn't work in 2010 out of the box but if you set application.autolayout to false you can insert new lines manually. This just won't work in 2013 where the new line appears for half a second and is automatically removed again.

Visio Guy

Um, the code sample doesn't add any Geometry rows, so I'm not sure which test failed, exactly.

That macro code is hard to use, you really need to replace some of that stuff with a variable to make it easier (for others) to test. The sample only works with a specific shape with an ID of 5, which is a pain to recreate.

I suggest:


    Dim shp As Visio.Shape
    Set shp = Visio.ActiveWindow.Selection(1)

    'Now replace any occurrence of
    ' Application.ActiveWindow.Page.Shapes.ItemFromID(5).
    ' with shp.



I cleaned up the macro code and made a sub that randomly adds points to the end of Geometry 1 of the selected shape:


Sub AddGeometryLineToSelectedConnector()

  '// Geometry1:
  Const SEC% = Visio.VisSectionIndices.visSectionFirstComponent

'  Dim DiagramServices As Integer
'  DiagramServices = ActiveDocument.DiagramServicesEnabled
'  ActiveDocument.DiagramServicesEnabled = visServiceVersion140 + visServiceVersion150

  '// Select a Dynamic Connector in the active window,
  '// Press F5 over and over to run this sub.

  Dim shp As Visio.Shape
  Set shp = Visio.ActiveWindow.Selection(1)
   
  Dim iRowCt As Integer
  iRowCt = shp.RowCount(SEC%)
 
  Dim iNewRow As Integer
  '// Add a row to at N-1 in Geometry1:
  iNewRow = shp.AddRow(SEC%, _
                       Visio.VisRowIndices.visRowLast, _
                       Visio.VisRowTags.visTagLineTo)
                       
  Dim x As Double, y As Double
  x = VBA.Rnd(1)
  y = VBA.Rnd(1)
                       
  '// Set the X and Y formulas for the new row:
  shp.CellsSRC(SEC%, _
               iNewRow, _
               Visio.VisCellIndices.visX).FormulaForceU = "Width*" & x

  shp.CellsSRC(SEC%, _
               iNewRow, _
               Visio.VisCellIndices.visY).FormulaForceU = "Height*" & y
               
  'Restore diagram services
  'ActiveDocument.DiagramServicesEnabled = DiagramServices
   
End Sub


(In Visio 2010) If you draw a 1D line, you can see that it works. If you use it on a Dynamic Connector, then nothing. Regardless of the diagram services stuff. If you step through it line by line (F8), once in awhile you will see an extra Geometry row, that sometunes disappears as you step. Sometimes, I was able to get rows to appear and stay. Visio seems to be recalculating the connector whenever something changes.

I couldn't manually add a row via the ShapeSheet either. It is very weird!

Here's another idea that might work:

1. Create a new geometry section (ie: Geometry2)
2. Configure the rows the way you want
3. Delete Geometry1. Geometry2 becomes Geometry1 and will be governed by connector behavior, but Visio doesn't seem to whack it right away!

I haven't had time to fully test this idea.
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

Jumpy

Maybe the "engine" controling the dynamic connector has changed? But even in earlier Versions of Visio adding rows to geometry sections of a dynamic connector was not recommended. Or formulas/VBA that looked at those geometry rows. That's due to the fact that Visio recalculates the geometry section "at will".

So maybe you could explain what the ultimate goal is? The reason why to change the geometry sections?
Eventually you could change the objecttype to make the connector "un-dynamic" and than change the geometry section?
Or u use another type of connector, maybe the universal connector from the connectors stencil?

IRDC

Quote from: Visio Guy on March 20, 2013, 03:23:04 PM
Um, the code sample doesn't add any Geometry rows, so I'm not sure which test failed, exactly.

That macro code is hard to use, you really need to replace some of that stuff with a variable to make it easier (for others) to test. The sample only works with a specific shape with an ID of 5, which is a pain to recreate.

I just pasted that code to illustrate that the macro recorder does not record the add of a new line (it wasn't intended for use or test).


Quote from: Visio Guy on March 20, 2013, 03:23:04 PM

Here's another idea that might work:

1. Create a new geometry section (ie: Geometry2)
2. Configure the rows the way you want
3. Delete Geometry1. Geometry2 becomes Geometry1 and will be governed by connector behavior, but Visio doesn't seem to whack it right away!

I haven't had time to fully test this idea.
I just tested it and when I right-click Geometry1 and select "delete section" in Visio 2013 Geometry2 gets deleted.

IRDC

Quote from: Jumpy on March 21, 2013, 07:22:38 AM
So maybe you could explain what the ultimate goal is? The reason why to change the geometry sections?

My goal is to recreate the functionality I had for Visio 2007 and 2010: The ability to connect to shapes with a connector that bends at specific coordinates to exactly recreate a drawing from somewhere else.

Quote from: Jumpy on March 21, 2013, 07:22:38 AM
Eventually you could change the objecttype to make the connector "un-dynamic" and than change the geometry section?
Or u use another type of connector, maybe the universal connector from the connectors stencil?

I'll test that next.

IRDC

Well, other connectors don't have the same benefits for the user working with the finished diagram, so I need to find a solution to make it work with the dynamic connector somehow.

IRDC

"Solved" the problem by adding a "pre bend" dynamic connector to a stencil and if I detect Visio 2013 I use that one instead, change the bends/geometry section row values and remove the additional bends/rows from the geometry section.

IRDC

While testing different files I ran into a new problem: Some rows were not removed resulting in a loop that tried to delete the same row over and over again.

IRDC

Quote from: Jumpy on March 21, 2013, 07:22:38 AM
Eventually you could change the objecttype to make the connector "un-dynamic" and than change the geometry section?
I believe I never tried that. I ran into the same problem today in another project and ended up here in my old topic again. In need of a different solution this time I gave it a try and it seems to be working. So, thank you, belatedly.

Browser ID: smf (possibly_robot)
Templates: 4: index (default), Display (default), GenericControls (default), GenericControls (default).
Sub templates: 6: init, html_above, body_above, main, body_below, html_below.
Language files: 4: index+Modifications.english (default), Post.english (default), Editor.english (default), Drafts.english (default).
Style sheets: 4: index.css, attachments.css, jquery.sceditor.css, responsive.css.
Hooks called: 356 (show)
Files included: 34 - 1306KB. (show)
Memory used: 1216KB.
Tokens: post-login.
Cache hits: 15: 0.00259s for 26,731 bytes (show)
Cache misses: 4: (show)
Queries used: 16.

[Show Queries]