Hi!
I am trying to do the simplest thing - connect two 2d shapes in code with GlueTo.
I have dropped two shapes, added to them connection points with "In" and "Out". Now when I am trying to connect them with a mouse - it`s all ok.
Then I have written a macro:
Sub Macro5()
'Enable diagram services
Dim DiagramServices As Integer
DiagramServices = ActiveDocument.DiagramServicesEnabled
ActiveDocument.DiagramServicesEnabled = visServiceVersion140
Dim UndoScopeID1 As Long
UndoScopeID1 = Application.BeginUndoScope("1")
ActiveWindow.DeselectAll
ActiveWindow.Select Application.ActiveWindow.Page.Shapes.ItemFromID(1), visSelect
Application.ActiveWindow.Selection.Move -1.161417, 0.669291
Dim vsoCell1 As Visio.Cell
Dim vsoCell2 As Visio.Cell
Set vsoCell1 = Application.ActiveWindow.Page.Shapes.ItemFromID(1).CellsU("PinX")
Set vsoCell2 = Application.ActiveWindow.Page.Shapes.ItemFromID(15).CellsSRC(7, 0, 0)
vsoCell1.GlueTo vsoCell2
Dim vsoCell3 As Cell
Dim vsoCell4 As Cell
Set vsoCell3 = Application.ActiveWindow.Page.Shapes.ItemFromID(1).CellsSRC(visSectionConnectionPts, 0, 0)
Set vsoCell4 = Application.ActiveWindow.Page.Shapes.ItemFromID(15).CellsSRC(visSectionConnectionPts, 0, 0)
vsoCell3.GlueTo vsoCell4
Application.EndUndoScope UndoScopeID1, True
'Restore diagram services
ActiveDocument.DiagramServicesEnabled = DiagramServices
End Sub
And it is not working... When I manually unglued shapes it throws "Inappropriate source object for this action" - but it`s macro!
Can you help me to write correct code?
Can someone help me?
Maybe any additional details needed?
It will work if add control handle and glue it, not PinX
can you clarify the 'control handle' and pinx comment? i am having this same exact issue
got it. see below for others with same question.
Public Sub GlueTwoD_Example()
Dim sBoxLower As Visio.Shape ' lower box
Dim sBoxCaption As Visio.Shape ' upper caption box
Dim vsoCellGlueFromObject As Visio.Cell
Dim vsoCellGlueToObject As Visio.Cell
Dim vsoCharacters1 As Visio.Characters ' this is for adding text to the box
'Draw the lower rectangle.
Set sBoxLower = ActivePage.DrawRectangle(1, 1, 4, 2)
sBoxLower.AddSection visSectionConnectionPts
sBoxLower.AddRow visSectionConnectionPts, visRowLast, visTagDefault
sBoxLower.CellsSRC(visSectionConnectionPts, 0, visCnnctX).FormulaForceU = "Width*1"
sBoxLower.CellsSRC(visSectionConnectionPts, 0, visCnnctY).FormulaForceU = "Height*1"
sBoxLower.CellsSRC(visSectionConnectionPts, 0, visCnnctDirX).FormulaForceU = "0 in"
sBoxLower.CellsSRC(visSectionConnectionPts, 0, visCnnctDirY).FormulaForceU = "0 in"
sBoxLower.CellsSRC(visSectionConnectionPts, 0, visCnnctType).FormulaForceU = "2"
sBoxLower.CellsSRC(visSectionConnectionPts, 0, visCnnctAutoGen).FormulaForceU = "0 in"
sBoxLower.CellsSRC(visSectionConnectionPts, 0, 6).FormulaForceU = ""
'Draw the caption rectangle.
Set sBoxCaption = ActivePage.DrawRectangle(5, 5, 5.3, 5.4)
sBoxCaption.AddSection visSectionConnectionPts
sBoxCaption.AddRow visSectionConnectionPts, visRowLast, visTagDefault
sBoxCaption.CellsSRC(visSectionConnectionPts, 0, visCnnctX).FormulaForceU = "Width*0"
sBoxCaption.CellsSRC(visSectionConnectionPts, 0, visCnnctY).FormulaForceU = "Height*0"
sBoxCaption.CellsSRC(visSectionConnectionPts, 0, visCnnctDirX).FormulaForceU = "0 in"
sBoxCaption.CellsSRC(visSectionConnectionPts, 0, visCnnctDirY).FormulaForceU = "0 in"
sBoxCaption.CellsSRC(visSectionConnectionPts, 0, visCnnctType).FormulaForceU = "2" ' not 2 is required
sBoxCaption.CellsSRC(visSectionConnectionPts, 0, visCnnctAutoGen).FormulaForceU = "0 in"
sBoxCaption.CellsSRC(visSectionConnectionPts, 0, 6).FormulaForceU = ""
'add text to captions box (upper box)
Set vsoCharacters1 = sBoxCaption.Characters
vsoCharacters1.Begin = 0
vsoCharacters1.End = 0
vsoCharacters1.text = "20%" & Chr(10) & "Text here"
'Get the Cell objects needed to make the connections. - the FROM object / line
Set vsoCellGlueFromObject = sBoxCaption.CellsSRC(visSectionConnectionPts, 0, 0)
'Get the Cell objects needed to make the connections. - the TO object / Box
Set vsoCellGlueToObject = sBoxLower.CellsSRC(visSectionConnectionPts, 0, 0) ' UR corner of lower rectangle
'Use the GlueTo method to glue the begin point of the line to the top right vertex (Geometry1.X3) of the lower 2-D shape.
vsoCellGlueFromObject.GlueTo vsoCellGlueToObject 'debug this
End Sub
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: 57 (
showintegrate_autoload, cache_get_data, integrate_pre_load, integrate_load_session, integrate_verify_user, cache_get_data, integrate_user_info, integrate_load_board, cache_get_data, integrate_board_info, cache_get_data, integrate_allowed_to_general, integrate_allowed_to_general, integrate_boards_allowed_to, integrate_mod_cache, integrate_allowed_to_general, integrate_pre_load_theme, cache_get_data, integrate_allowed_to_general, integrate_simple_actions, integrate_allowed_to_general, integrate_load_theme, integrate_pre_log_stats, cache_get_data, integrate_actions, integrate_pre_parsebbc, integrate_bbc_codes, integrate_bbc_print, integrate_post_parsebbc, integrate_pre_parsebbc, integrate_bbc_print, integrate_post_parsebbc, integrate_pre_parsebbc, integrate_bbc_print, integrate_post_parsebbc, integrate_pre_parsebbc, integrate_bbc_print, integrate_post_parsebbc, integrate_pre_parsebbc, integrate_bbc_print, integrate_post_parsebbc, integrate_allowed_to_general, integrate_allowed_to_general, integrate_allowed_to_general, integrate_allowed_to_general, integrate_allowed_to_general, integrate_allowed_to_general, integrate_allowed_to_general, integrate_allowed_to_general, integrate_allowed_to_general, integrate_allowed_to_general, integrate_menu_buttons, integrate_current_action, integrate_theme_context, integrate_allowed_to_general, integrate_allowed_to_general, integrate_allowed_to_general)
Files included: 25 - 925KB. (
show/home/iw0lkfe3x6cq/public_html/vgforum/index.php, /home/iw0lkfe3x6cq/public_html/vgforum/Settings.php, /home/iw0lkfe3x6cq/public_html/vgforum/cache/db_last_error.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/QueryString.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Subs.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Subs-Auth.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Errors.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Load.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Security.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Subs-Compat.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Subs-Db-mysql.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Cache/CacheApi.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Cache/CacheApiInterface.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Cache/APIs/FileBased.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Subs-Charset.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Unicode/Metadata.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Unicode/QuickCheck.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Session.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Logging.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Class-BrowserDetect.php, (Current Theme)/languages/index.english.php, (Current Theme)/languages/Modifications.english.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Printpage.php, (Current Theme)/Printpage.template.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Unicode/CaseUpper.php)
Memory used: 749KB.
Tokens:
post-login.
Cache hits: 8: 0.00118s for 22,301 bytes (
showget modSettings: 0.00041s - 19982 bytes, get known_languages: 0.00014s - 1277 bytes, get board_parents-0: 0.00009s - 2 bytes, get permissions:-1: 0.00007s - 50 bytes, get theme_settings-1: 0.00010s - 980 bytes, get hostlookup-216.73.216.105: 0.00004s - 0 bytes, get log_online-update: 0.00030s - 10 bytes, get menu_buttons--1-english: 0.00002s - 0 bytes)
Cache misses: 2: (
showget hostlookup-216.73.216.105, get menu_buttons--1-english)
Queries used: 11.
[Show Queries]