×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

API - cycling through drawing sheets and changing name

API - cycling through drawing sheets and changing name

API - cycling through drawing sheets and changing name

(OP)
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

RE: API - cycling through drawing sheets and changing name

(OP)
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.

RE: API - cycling through drawing sheets and changing name

Try this

Quote:

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

RE: API - cycling through drawing sheets and changing name

(OP)
No luck unfortunately.

RE: API - cycling through drawing sheets and changing name

It is working for me

Deepak Gupta
SW 2009 SP4.1 & 2007 SP5.0
MathCAD 14.0
Boxer's Blog

RE: API - cycling through drawing sheets and changing name

(OP)
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

RE: API - cycling through drawing sheets and changing name

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources