Glue 2 shapes

Started by Miguel, February 08, 2017, 02:37:37 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Miguel

Hello!

Please, i need your help!

That is the problem; I want to glue two 2'D Sahpes.

Public Sub Document_ShapeAdded(ByVal vsoShapeAdded As IVShape)

Dim vsoDocument As Visio.Document
Dim vsoPage As Visio.Page
Dim vsoShapeOnPage As Visio.Shapes

Dim vsoCellToGlue As Visio.Cell
Dim vsoCellGlueToObject As Visio.Cell

Set vsoPage = Visio.ActivePage
Set vsoDocument = Visio.ActiveDocument
Set vsoShapeOnPage = ActivePage.Shapes
       
    If vsoShapeOnPage.Name Like "Rectangle*" And vsoShapeAdded.Name Like "Triangle*" Then
   
       Set vsoCellToGlue = vsoShapeAdded.Cells("Controls.Row_1")
       Set vsoCellGlueToObject = vsoShapeOnPage.Cells("Connections.Row")

       vsoCellGlueToObject.GlueTo vsoCellToGlue
   
    End If
End Sub


As you can see, my program don't work and i don't know why. I use the GlueTo method to glue my shapes. And if i understand, this method can glue a cell of controls point with a cell of connections point.  If I post this topic here it's because I have to handle the ShapeSheet. I need your help. It's very significant for me. So I hope that you could help me.

Thank you :)

wapperdude

#1
Bit odd gluing to a control.  Doesn't do much of anything.  Using the macro recorder plus some editting, the following code results:
Shape sheet.1 is the rectangle shape
Shape sheet.2 is a triangle shape, with a control point.

I'm assuming that you already have vsoShapeOnPage and vsoShapeAdded defined previously in code.  They are not defined in the code you provided.

I added two lines to make the assignment to mimic your code, and the conditional IF statement. 

Then show the gluing steps from the macro recorder.  The control point of the triangle is glued to the rectangle connection point... assuming that's what you want.


Sub Macro1()

    Dim vsoCell1 As Visio.Cell
    Dim vsoCell2 As Visio.Cell
    Dim vsoShpOnPg As Shape
    Dim vsoShpOnDrp As Shape
   
    Set vsoShpOnPg = ActiveWindow.Page.Shapes.ItemFromID(1)
    Set vsoShpOnDrp = ActiveWindow.Page.Shapes.ItemFromID(2)
   
    If vsoShpOnPg.Name Like "Rectangle" And vsoShpOnDrp.Name Like "Triangle" Then
        Set vsoCell1 = vsoShpOnDrp.CellsSRC(visSectionControls, 0, visCtlX)
        Set vsoCell2 = vsoShpOnPg.CellsSRC(7, 1, 0)
        vsoCell1.GlueTo vsoCell2
    End If

End Sub


Wapperdude
Visio 2019 Pro

Miguel

Thank you for your help.

I've succeeded to glue two 2D Shapes without macro. Now I would to know if you know a method which can Flip a shape automatically when it is next to the sides of an other shape. For example, I would like that my triangle can to flip (or no, depends of his position) when there is next to the sides of my rectangle. 

Thank you for your help.  8) ;D