If possible to control drawing sheet view scale through macro
If possible to control drawing sheet view scale through macro
Hello. Try this:
It will work on the selected view. Un-comment the SelectByID2 line if you want to programmatibly select a specific view
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swView As SldWorks.View
Dim boolstatus As Boolean
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
'boolstatus = swModel.Extension.SelectByID2("Drawing View1", "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0)
Set swView = swModel.SelectionManager.GetSelectedObject6(1, -1)
swView.ScaleDecimal = 1 / 2
boolstatus = swModel.EditRebuild3
End Sub
Repeating that it doesn't work, is not useful.
The macro works fine on our end. So the problem either comes from the way you use the macro, or your files.
So describe in details what are you doing, and attach your files (sldprt and slddrw)
it shows error
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swView As SldWorks.View
Dim boolstatus As Boolean
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
'boolstatus = swModel.Extension.SelectByID2("Drawing View1", "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0)
Set swView = swModel.SelectionManager.GetSelectedObject6(1, -1)
swView.ScaleDecimal = 1 / 2
boolstatus = swModel.EditRebuild3
End Sub
highlighted line only error shows
It works fine for me when I use my code on your files, but you need to select a view and click rebuild:
1) maybe add "swView.UseSheetScale" = False after "Set swView = swModel.SelectionManager.GetSelectedObject6(1, -1)" to be sure
2) select a view (or select it automatically by removing the " ' " in front of "boolstatus = swModel.Extension.SelectByID2" but be careful that it will only work if the name of the view in "Drawing View1")
3) run the macro
4) rebuild (or add "swModel.ForceRebuild3 False" after "boolstatus = swModel.EditRebuild3")
Note:
- the macro that you have attached is empty. Did you forget to save it before closing?
- the view on your file is already scale 1/2, so you need to change the number in "swView.ScaleDecimal = 1 / 2" to see some changes
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swView As SldWorks.View
Dim boolstatus As Boolean
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
boolstatus = swModel.Extension.SelectByID2("Drawing View1", "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0)
Set swView = swModel.SelectionManager.GetSelectedObject6(1, -1)
swView.UseSheetScale = False
swView.ScaleDecimal = 1 / 4
boolstatus = swModel.EditRebuild3
swModel.ForceRebuild3 False
End Sub
Repeating that it doesn't work, is not useful.
The macro works fine on our end. So the problem either comes from the way you use the macro, or your files.
So describe in details what are you doing, and attach your files (sldprt and slddrw)