Problems with Placing of Containers

Started by cliverenwood, November 15, 2019, 10:09:00 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

cliverenwood

Hey!

I am working on a project, where i draw a network schematic and place devices in containers and connect them to devices in other containers. Everything is working almost perfect, but a little thing drives me nuts:

I am not able to increase the sheet size on the x-axis appropriate to the paper size a3 and put on container on each printer page. For some reason, while i iterate trough the containers and move them, they tend more and more to the right and end up right on the page breaks. When i check the shapsheets, the calculated values look fine to me. Here is the code of the sub:

Public Sub containerOrder()
   
    Dim vsoContainer As Shape
    Dim xPos        As Double
    Dim yPos        As Double
    'Dim newHeight  As Double
   
    'Const maxPerPage = 2 '2 Liegenschaften a' 4 Items pro Zeile
    Const minWidth = 200
    Dim rowCount    As Integer
    'Dim currentHeight As Double
   
    xPos = 0        'Start / Erstes Shabe bei x=0mm
    yPos = 0        'Start
   
    'rowCount = 0
    pageCounter = 1
    ActiveDocument.DiagramServicesEnabled = visServiceVersion140 + visServiceVersion150
   
    For Each containerID In ThisDocument.Pages(2).GetContainers(visContainerIncludeNested)
       
        Set vsoContainer = ThisDocument.Pages(2).Shapes.ItemFromID(containerID)
        vsoContainer.ContainerProperties.FitToContents        'Nach getConnectionData stehen die Geräte teilweise außerhalb der Container. Hier wieder reinpacken
        vsoContainer.ContainerProperties.ResizeAsNeeded = False        'Verhindere späteres Ändern
       
        If vsoContainer.Cells("Width").Result("mm") < 200 Then        'min width für die Überschrift
        vsoContainer.Cells("Width").Result("mm") = 200
       
    End If
   
    vsoContainer.Cells("Height").Result("mm") = vsoContainer.Cells("Height").Result("mm") + 50        'Texte der letzten Shape-Reihe werden abgeschnitten
    If vsoContainer.Cells("Width").Result("mm") + 50 < 380 Then
        vsoContainer.Cells("Width").Result("mm") = vsoContainer.Cells("Width").Result("mm") + 50        'Texte der letzten Shape-Spalte werden abgeschnitten
    Else
        vsoContainer.Cells("Width").Result("mm") = 380
    End If
    vsoContainer.Cells("LocPinX").Result("mm") = 0
    vsoContainer.Cells("LocPinY").Result("mm") = 0
    ThisDocument.Pages(2).PageSheet.Cells("PageWidth").ResultForce("mm") = pageCounter * 420

       
    Application.ActiveDocument.PaperSize = visPaperSizeA3
    If pageCounter > 1 Then
    xPos = 410 * (pageCounter - 1)  ' (pageCounter * 410.5) + (vsoContainer.Cells("Width").Result("mm") / 2) + 5     
   
    Else
    xPos = 0
    End If
    yPos = 70 'vsoContainer.Cells("Height").Result("mm") / 2 + 50        'Da Pin in der Mitte *0.5 vom alten Container und vom neuen
   
    pageCounter = pageCounter + 1
    vsoContainer.Cells("PinX").Result("mm") = xPos
    vsoContainer.Cells("PinY").Result("mm") = yPos

    'Try to prevent movement
     vsoContainer.CellsSRC(visSectionObject, visRowLock, visLockWidth).FormulaU = "1"
    vsoContainer.CellsSRC(visSectionObject, visRowLock, visLockHeight).FormulaU = "1"
    vsoContainer.CellsSRC(visSectionObject, visRowLock, visLockMoveX).FormulaU = "1"
    vsoContainer.CellsSRC(visSectionObject, visRowLock, visLockMoveY).FormulaU = "1"
    vsoContainer.CellsSRC(visSectionObject, visRowLock, visLockAspect).FormulaU = "1"
    vsoContainer.CellsSRC(visSectionObject, visRowLock, visLockDelete).FormulaU = "1"
    vsoContainer.CellsSRC(visSectionObject, visRowLock, visLockBegin).FormulaU = "1"
    vsoContainer.CellsSRC(visSectionObject, visRowLock, visLockEnd).FormulaU = "1"
    vsoContainer.CellsSRC(visSectionObject, visRowLock, visLockRotate).FormulaU = "1"
    vsoContainer.CellsSRC(visSectionObject, visRowLock, visLockTextEdit).FormulaU = "0"
    vsoContainer.CellsSRC(visSectionObject, visRowLock, visLockFormat).FormulaU = "0"
    vsoContainer.CellsSRC(visSectionObject, visRowLock, visLockSelect).FormulaU = "0"
    vsoContainer.CellsSRC(visSectionObject, visRowLock, visLockFromGroupFormat).FormulaU = "1"
    vsoContainer.CellsSRC(visSectionObject, visRowLock, visLockThemeColors).FormulaU = "0"
    vsoContainer.CellsSRC(visSectionObject, visRowLock, visLockThemeEffects).FormulaU = "0"
    vsoContainer.CellsSRC(visSectionObject, visRowLock, visLockThemeConnectors).FormulaU = "0"
    vsoContainer.CellsSRC(visSectionObject, visRowLock, visLockThemeFonts).FormulaU = "0"
    vsoContainer.CellsSRC(visSectionObject, visRowLock, visLockThemeIndex).FormulaU = "0"
    vsoContainer.CellsSRC(visSectionObject, visRowLock, visLockReplace).FormulaU = "1"

Next containerID

'ThisDocument.Pages(2).ResizeToFitContents

End Sub


Any help would be appreciated!

wapperdude

Did a quick test with 3 containers on Page-2.  Ran the code.  Each container resizes per code.  Each container moves to spot specified by code...which is right at page breaks.

First container has LocPinx =0 => left edge.  PinX = 0.  Which is the very left edge of 1st page.
Second container has LocPinX =0, and PinX = 410*(pagecounter-1) = 410.  And that is where it is located.  Which happens to be page break.
Similarly for 3rd container.

Need some code changes.  First container, PinX should not be 0.
2nd and following containers, the formula for xPos needs something other than 410. 

Visio 2019 Pro