Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MintJulep on being selected by the Eng-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
Joined
Jan 10, 2009
Messages
79
Location
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
 
By the way, the Rebuild line wasn't really necessary, I was just throwing it to see if it would help and it didn't.
 
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
 
Strange as SW doesn't allow for sheets with same name in same drawing file.

Deepak Gupta
SW 2009 SP4.1 & 2007 SP5.0
MathCAD 14.0
Boxer's Blog
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top