I can't figure out why these macro change the position of the dimensions, and just for the base view. I though it was the <ScaleAnnoPosition> of the <SetScale> method but even using <True> doesn't change the result.
I have another macro to change the sheet format that use the <SetupSheet5> method but same results. If I change the scale with the SolidWorks interfaces the dimensions stay where they are...
I have attached a brief video and a sample file.
Here is the code
Code: Select all
Dim swApp As SldWorks.SldWorks
Dim swDraw As SldWorks.IDrawingDoc
Dim swSheet As SldWorks.Sheet
Dim sheetProperties As Variant
Dim scalaNum As Double
Dim scalaDen As Double
Dim ScaleAnnoPosition As Boolean
Dim ScaleAnnoTextHeight As Boolean
Dim value As Boolean
Sub main()
Set swApp = Application.SldWorks
Dim swDraw As SldWorks.IDrawingDoc
Dim swSheet As SldWorks.Sheet
Dim swModel As SldWorks.ModelDoc2
Set swModel = swApp.ActiveDoc
If swModel Is Nothing Then
MsgBox ("Open a drawing")
GoTo finally_
End If
If swModel.GetPathName() = "" Then
MsgBox ("Save the file")
GoTo finally_
End If
If Not swModel.GetType() = swDocDRAWING Then
MsgBox ("OPen a drawing")
GoTo finally_
End If
Set swDraw = swApp.ActiveDoc
Set swSheet = swDraw.GetCurrentSheet
sheetProperties = swSheet.GetProperties2
scalaNum = sheetProperties(2)
scalaDen = sheetProperties(3)
If scalaNum = 1 Then
Select Case scalaDen
Case Is = 1
scalaDen = 1
scalaNum = 2
Case Is = 2
scalaDen = 1
Case Is = 2.5
scalaDen = 2
Case Is = 4
scalaDen = 2.5
Case Is = 5
scalaDen = 4
Case Is = 7.5
scalaDen = 5
Case Is = 10
scalaDen = 7.5
Case Is = 15
scalaDen = 10
Case Is = 20
scalaDen = 15
Case Is = 25
scalaDen = 20
Case Is = 30
scalaDen = 25
Case Is = 50
scalaDen = 30
Case Is = 75
scalaDen = 50
Case Is = 100
scalaDen = 75
Case Is = 150
scalaDen = 100
Case Is = 200
scalaDen = 150
Case Is = 250
scalaDen = 200
Case Else
MsgBox "Scale not found", vbExclamation
GoTo finally_
End Select
ElseIf scalaDen = 1 Then
Select Case scalaNum
Case Is = 2
scalaNum = 2.5
Case Is = 2.5
scalaNum = 4
Case Is = 4
scalaNum = 5
Case Else
MsgBox "Scale not found", vbExclamation
GoTo finally_
End Select
End If
ScaleAnnoPosition = False
ScaleAnnoTextHeight = False
value = swSheet.SetScale(scalaNum, scalaDen, ScaleAnnoPosition, ScaleAnnoTextHeight)
finally_:
End Sub
Code: Select all
Dim swApp As SldWorks.SldWorks
Dim swDraw As SldWorks.IDrawingDoc
Dim swSheet As SldWorks.Sheet
Dim sheetProperties As Variant
Dim scalaNum As Double
Dim scalaDen As Double
Dim ScaleAnnoPosition As Boolean
Dim ScaleAnnoTextHeight As Boolean
Dim value As Boolean
Sub main()
Set swApp = Application.SldWorks
Dim swDraw As SldWorks.IDrawingDoc
Dim swSheet As SldWorks.Sheet
Dim swModel As SldWorks.ModelDoc2
Set swModel = swApp.ActiveDoc
If swModel Is Nothing Then
MsgBox ("Open a drawing")
GoTo finally_
End If
If swModel.GetPathName() = "" Then
MsgBox ("Save the file")
GoTo finally_
End If
If Not swModel.GetType() = swDocDRAWING Then
MsgBox ("Open a drawing")
GoTo finally_
End If
Set swDraw = swApp.ActiveDoc
Set swSheet = swDraw.GetCurrentSheet
sheetProperties = swSheet.GetProperties2
scalaNum = sheetProperties(2)
scalaDen = sheetProperties(3)
If scalaNum = 1 Then
Select Case ScalaDen
Case Is = 1
ScalaDen = 2
Case Is = 2
ScalaDen = 2.5
Case Is = 2.5
ScalaDen = 4
Case Is = 4
ScalaDen = 5
Case Is = 5
ScalaDen = 7.5
Case Is = 7.5
ScalaDen = 10
Case Is = 10
ScalaDen = 15
Case Is = 15
ScalaDen = 20
Case Is = 20
ScalaDen = 25
Case Is = 25
ScalaDen = 30
Case Is = 30
ScalaDen = 50
Case Is = 50
ScalaDen = 75
Case Is = 75
ScalaDen = 100
Case Is = 100
ScalaDen = 150
Case Is = 150
ScalaDen = 200
Case Is = 200
ScalaDen = 250
Case Else
MsgBox "Scale not found" , vbExclamation
Goto finally_
End Select
ElseIf ScalaDen = 1 Then
Select Case ScalaNum
Case Is = 1
ScalaNum = 1
ScalaDen = 2
Case Is = 2
ScalaNum = 1
Case Is = 2.5
ScalaNum = 2
Case Is = 4
ScalaNum = 2.5
Case Is = 5
ScalaNum = 4
Case Else
MsgBox "Scale not found" , vbExclamation
Goto finally_
End Select
End If
ScaleAnnoPosition = False
ScaleAnnoTextHeight = False
value = swSheet.SetScale(ScalaNum, ScalaDen, ScaleAnnoPosition, ScaleAnnoTextHeight)
finally_:
End Sub