×
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

Macro to open, forcerebuild, close sw docs

Macro to open, forcerebuild, close sw docs

Macro to open, forcerebuild, close sw docs

(OP)
I found this question on comp.cad.solidworks here: http://groups.google.com/group/comp.cad.solidworks/browse_thread/thread/0a0e7b1bc1d50f4e/6c1bdb4336ad1d3d?hl=en#6c1bdb4336ad1d3d

Basically does anyone have a macro tht will open a file, forcerebuild it, save it, then close it?  Is sounds pretty easy, and I'd work on this myself except I don't have a lot of time right now.  Has anyone else done this?

Matt
CAD Engineer/ECN Analyst
Silicon Valley, CA
sw.fcsuper.com
Co-moderator of Solidworks Yahoo! Group

RE: Macro to open, forcerebuild, close sw docs

Could you not do it with the update files option in SW task scheduler?

RE: Macro to open, forcerebuild, close sw docs

(OP)
There's a statement from that person suggesting this didn't work the way it was expected too.

Matt
CAD Engineer/ECN Analyst
Silicon Valley, CA
sw.fcsuper.com
Co-moderator of Solidworks Yahoo! Group

RE: Macro to open, forcerebuild, close sw docs

Enjoy.

CODE


Option Explicit
 
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim strPathAndFilename As String
Dim strResponse As String
Dim strFileType As Long
Dim longstatus As Long
Dim longwarnings As Long

Sub main()
    
    Set swApp = Application.SldWorks
    
    strPathAndFilename = "C:\Temp\Part1.SLDDRW"
    strResponse = vbYes
    
    If StrComp((UCase$(Right$(strPathAndFilename, 7))), ".SLDPRT", vbTextCompare) = 0 Then
        strFileType = swDocPART
    ElseIf StrComp((UCase$(Right$(strPathAndFilename, 7))), ".SLDASM", vbTextCompare) = 0 Then
        strFileType = swDocASSEMBLY
    ElseIf StrComp((UCase$(Right$(strPathAndFilename, 7))), ".SLDDRW", vbTextCompare) = 0 Then
        strFileType = swDocDRAWING
    End If
    
    Set swModel = swApp.OpenDoc6(strPathAndFilename, strFileType, 0, "", longstatus, longwarnings)
    Set swModel = swApp.ActivateDoc2(strPathAndFilename, False, longstatus)
        
    If (swModel Is Nothing) Then
        strResponse = MsgBox("The file could not be found." & Chr(13) & "Routine Ending.", vbCritical, "FileOpenRebuildSaveClose")
        End
    End If
    
    If (swModel.IsOpenedReadOnly = "False") Then
        
        If (swModel.GetType <> swDocDRAWING) Then
            
            'Shade Part
            swModel.ViewDisplayShaded
            
            'Set view
            'swModel.ShowNamedView2 "*Isometric", 7
            'swModel.ShowNamedView2 "*Trimetric", 8
            swModel.ShowNamedView2 "*Dimetric", 9
            
            'Set Feature Manager Splitter Position
            swModel.FeatureManagerSplitterPosition = 0.3
        
        End If
        
        'Rebuild File
        'swModel.EditRebuild3 'Stoplight or [Ctrl]+B
        swModel.ForceRebuild '[Ctrl]+Q
        
        'Zoom to extents
        swModel.ViewZoomtofit2
        
        'Save
        swModel.Save2 False
    
    Else
        strResponse = MsgBox("The file is Read-Only." & Chr(13) & "Do you want to close the file without Saving?", vbCritical + vbYesNo, "FileOpenRebuildSaveClose")
    End If
    
    Set swModel = Nothing
    
    If (strResponse = vbYes) Then
        'Close
        swApp.CloseDoc strPathAndFilename
    End If
    
    Set swApp = Nothing
    
End Sub

RE: Macro to open, forcerebuild, close sw docs

(OP)
Ken,

Thanks!  Are you the author or do you have a source for this code?  

Matt
CAD Engineer/ECN Analyst
Silicon Valley, CA
sw.fcsuper.com
Co-moderator of Solidworks Yahoo! Group

RE: Macro to open, forcerebuild, close sw docs

I have mixed and matched code I wrote and code I've found that I couldn't really tell you where everything in here came from. I guess I am the author, but I have gotten bits and pieces of the code from different places over the years (just like most everything else I've written).

Ken

RE: Macro to open, forcerebuild, close sw docs

(OP)
Ken,

Mind if I tinker with the macro and host it on my site?  I would like to had a userform for starters.

Matt
CAD Engineer/ECN Analyst
Silicon Valley, CA
sw.fcsuper.com
Co-moderator of Solidworks Yahoo! Group

RE: Macro to open, forcerebuild, close sw docs

Whatever you want to do is fine with me.
Ken

RE: Macro to open, forcerebuild, close sw docs

Hey I subscribed here now, I was the one who asked on comp.cad.sw

Thanks for helping me out, I will work with this, need it to run a whole dir drawing by drawing. Will see what I can come up with myself and then get back if I wont succeed.

RE: Macro to open, forcerebuild, close sw docs

fcsuper,

if you're interested, I've written an outside SolidWorks macro .

It rebuild an Assembly and all parts which compose the assembly.
In the rebuilding, all configurations are activated to "forceRegen" them.

Maybe this macro interests you (it's a self executable which starts SW)

SW2007 SP4
Worksatation HP wx4300 2GB
NVidia Quadro FX 3450

RE: Macro to open, forcerebuild, close sw docs

(OP)
Florent,

Location where this is available?

Matt
CAD Engineer/ECN Analyst
Silicon Valley, CA
sw.fcsuper.com
Co-moderator of Solidworks Yahoo! Group

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