Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

API - cycling through drawing sheets and changing name

Status
Not open for further replies.

razzendahcuben

Mechanical
Jan 10, 2009
79
0
0
US
I am at a loss to explain why the following does not work. GetCurrentSheet is not getting the sheet even though that sheet is active. Any ideas? Thanks for your help.

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Dim swSheet As SldWorks.Sheet
Dim vSheets As Variant
Dim i As Integer

Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swDraw = swModel

vSheets = swDraw.GetSheetNames

For i = 1 To swDraw.GetSheetCount
swDraw.ActivateSheet vSheets(i - 1)
swModel.Rebuild swRebuildAll
Set swSheet = swDraw.GetCurrentSheet
swSheet.SetName "Sheet" & i
Next i
End Sub
 
Replies continue below

Recommended for you

Try this

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Dim swSheet As SldWorks.Sheet
Dim vSheets As Variant
Dim i As Integer

Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swDraw = swModel

vSheets = swDraw.GetSheetNames

For i = 1 To swDraw.GetSheetCount
swDraw.ActivateSheet vSheets(i - 1)
swModel.Rebuild swRebuildAll
Set swSheet = swDraw.GetCurrentSheet
swSheet.SetName ("Sheet" & i)
Next i
End Sub

Deepak Gupta
SW 2009 SP4.1 & 2007 SP5.0
MathCAD 14.0
Boxer's Blog
 
The problem ending up being that given the above macro, multiple sheets with the same name would have existed. I changed it to first change all of the sheet names to something odd and then go back through make them Sheet1, Sheet2, ... etc
 
Status
Not open for further replies.
Back
Top