Hi,
I'm definitively losing my time since several weeks in manually arranging views in my drawing. I tried to write a macro but the view.position function doesn't seem to work. I found the SPR 682112 issue that sounds like my problem, but didn't succeed to find an alternate solution. Here is my code, does anyone can try it on any sheet with multiple views and check the result ? I'm running on SW2016 but can upgrade if necessary.
Before macro :
after running the macro :
The vpos array is really weird.
And if anyone has a solution ...
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swDraw As SldWorks.DrawingDoc
Dim swView As SldWorks.View
Dim nextView As SldWorks.View
Dim bool As Boolean
Dim i As Long
Dim vPos As Variant
Dim vOutline As Variant
Dim vNewPos As Variant
Dim vNewOutline As Variant
Dim larg_col As Double
Dim marge As Double
Dim first_body As Boolean
Sub arrange_views() '(swModel As SldWorks.ModelDoc2)
Set swApp = Application.SldWorks
Dim swModel As SldWorks.ModelDoc2
Set swModel = swApp.ActiveDoc
Set swDraw = swModel
first_body = True
marge = 0.02
Set swView = swDraw.GetFirstView
Set swView = swView.GetNextView
Do While Not swView Is Nothing
vNewPos = swView.Position
vNewOutline = swView.GetOutline
Debug.Print swView.Name & vbCrLf & " position INITIALE " & " : min : (" & Round(vNewOutline(0) * 1000, 2) & " ; " & Round(vNewOutline(1) * 1000, 2) & ") | MAX : (" & Round(vNewOutline(2) * 1000, 2) & " ; " & Round(vNewOutline(3) * 1000, 2) & ")"
If vNewOutline(2) - vNewOutline(0) < vNewOutline(3) - vNewOutline(1) Then 'if height > width then rotate
bool = swModel.Extension.SelectByID2(swView.Name, "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0)
bool = swModel.DrawingViewRotate(90 / 57.3) 'rotation de 90° (conversion degres/radians)
swModel.GraphicsRedraw2
vNewOutline = swView.GetOutline
Debug.Print "APRES ROTATION : min : (" & vNewOutline(0) & " ; " & vNewOutline(1) & ") | MAX : (" & vNewOutline(2) & " ; " & vNewOutline(3) & ")"
End If
If first_body = True Then 'initialisation pour la première vue
vOutline = swView.GetOutline
vOutline(1) = 0.277
larg_col = vOutline(2)
End If
vNewPos(0) = marge + Abs(vNewOutline(2) - vNewOutline(0)) / 2 ' X centre de la vue à plat
vNewPos(1) = vOutline(1) - Abs(vNewOutline(3) - vNewOutline(1)) / 2 'Y centre de la vue à plat
swView.Position = vNewPos
swDraw.SuppressView
swDraw.UnsuppressView
vNewOutline = swView.GetOutline
If vNewOutline(1) < 0.05 Then ' si la vue déborde en dessous de 50mm, déplacement dans la colonne suivante
marge = larg_col
vNewPos(0) = marge + (vNewOutline(2) - vNewOutline(0)) / 2 ' X centre de la vue à plat
vNewPos(1) = 0.277 - (vNewOutline(3) - vNewOutline(1)) / 2 'Y centre de la vue à plat
swView.Position = vNewPos
vNewOutline = swView.GetOutline
End If
If larg_col < vNewOutline(2) Then larg_col = vNewOutline(2)
vPos = swView.Position
vOutline = swView.GetOutline
first_body = False
Debug.Print " position FINALE : min : (" & Round(vNewOutline(0) * 1000, 2) & " ; " & Round(vNewOutline(1) * 1000, 2) & ") | MAX : (" & Round(vNewOutline(2) * 1000, 2) & " ; " & Round(vNewOutline(3) * 1000, 2) & ")"
Set swView = swView.GetNextView
Loop
End Sub
Thx
SolidworksApi macros